mirror of
https://github.com/urbit/shrub.git
synced 2024-11-28 13:54:20 +03:00
landscape: add eth/ threads
This commit is contained in:
parent
143bb80035
commit
bff16ada72
44
pkg/landscape/ted/eth/get-timestamps.hoon
Normal file
44
pkg/landscape/ted/eth/get-timestamps.hoon
Normal file
@ -0,0 +1,44 @@
|
||||
:: eth/get-timestamps: query ethereum block timestamps
|
||||
::
|
||||
:: produces list of @da result
|
||||
::
|
||||
/+ ethereum, ethio, strandio
|
||||
=, ethereum-types
|
||||
=, jael
|
||||
::
|
||||
|= args=vase
|
||||
=+ !<([url=@t blocks=(list @ud)] args)
|
||||
=/ m (strand:strandio ,vase)
|
||||
=| out=(list [block=@ud timestamp=@da])
|
||||
|^ ^- form:m
|
||||
=* loop $
|
||||
?: =(~ blocks) (pure:m !>(out)) ::TODO TMI
|
||||
;< res=(list [@t json]) bind:m
|
||||
(request-blocks (scag 100 blocks))
|
||||
%_ loop
|
||||
out (weld out (parse-results res))
|
||||
blocks (slag 100 blocks)
|
||||
==
|
||||
::
|
||||
++ request-blocks
|
||||
|= blocks=(list @ud)
|
||||
%+ request-batch-rpc-strict:ethio url
|
||||
%+ turn blocks
|
||||
|= block=@ud
|
||||
^- [(unit @t) request:rpc:ethereum]
|
||||
:- `(scot %ud block)
|
||||
[%eth-get-block-by-number block |]
|
||||
::
|
||||
++ parse-results
|
||||
|= res=(list [@t json])
|
||||
^+ out
|
||||
%+ turn res
|
||||
|= [id=@t =json]
|
||||
^- [@ud @da]
|
||||
:- (slav %ud id)
|
||||
%- from-unix:chrono:userlib
|
||||
%- parse-hex-result:rpc:ethereum
|
||||
~| json
|
||||
?> ?=(%o -.json)
|
||||
(~(got by p.json) 'timestamp')
|
||||
--
|
15
pkg/landscape/ted/eth/read-contract.hoon
Normal file
15
pkg/landscape/ted/eth/read-contract.hoon
Normal file
@ -0,0 +1,15 @@
|
||||
:: eth/read-contract: query ethereum for contract data
|
||||
::
|
||||
:: produces hex string result, for use with +decode-results:rpc:ethereum
|
||||
::
|
||||
/+ ethereum, ethio, strandio
|
||||
=, ethereum-types
|
||||
=, jael
|
||||
::
|
||||
|= args=vase
|
||||
=/ m (strand:strandio ,vase)
|
||||
^- form:m
|
||||
;< res=@t bind:m
|
||||
%- read-contract:ethio
|
||||
!<([@t proto-read-request:rpc:ethereum] args)
|
||||
(pure:m !>(res))
|
111
pkg/landscape/ted/eth/send-txs.hoon
Normal file
111
pkg/landscape/ted/eth/send-txs.hoon
Normal file
@ -0,0 +1,111 @@
|
||||
:: eth/send-txs: query ethereum for contract data
|
||||
::
|
||||
:: produces hex string result, for use with +decode-results:rpc:ethereum
|
||||
::
|
||||
/- rpc=json-rpc
|
||||
/+ ethio, strandio
|
||||
::
|
||||
=>
|
||||
|%
|
||||
++ tape-to-ux
|
||||
|= t=tape
|
||||
(scan t ;~(pfix (jest '0x') hex))
|
||||
--
|
||||
::
|
||||
|= args=vase
|
||||
=+ !<([url=@t step-size=@ud txs=(list @ux)] args)
|
||||
=/ m (strand:strandio ,vase)
|
||||
^- form:m
|
||||
|-
|
||||
=* submit-loop $
|
||||
~& ['remaining txs:' (lent txs)]
|
||||
?: =(~ txs) (pure:m !>(~))
|
||||
:: send a step-size batch of transactions
|
||||
::
|
||||
;< responses=(list response:rpc) bind:m
|
||||
%+ request-batch-rpc-loose:ethio url
|
||||
%+ turn (scag step-size txs)
|
||||
|= tx=@ux
|
||||
:- `(scot %ux (end [3 10] tx))
|
||||
[%eth-send-raw-transaction tx]
|
||||
:: parse tx hashes out of responses, bailing on submission failure
|
||||
::
|
||||
=/ pending=(each (set @ux) [term tang])
|
||||
=| pending=(list @ux)
|
||||
|-
|
||||
?~ responses &+(sy pending)
|
||||
=/ res=response:rpc i.responses ::NOTE =* breaks typechecks
|
||||
?+ -.res |+[%unexpected-non-result >res< ~]
|
||||
%result
|
||||
%_ $
|
||||
responses t.responses
|
||||
pending [(tape-to-ux (sa:dejs:format res.res)) pending]
|
||||
==
|
||||
::
|
||||
%error
|
||||
?: ?| =('known transaction' (end [3 17] message.res))
|
||||
=('Known transaction' (end [3 17] message.res))
|
||||
=('Transaction with the same ' (end [3 26] message.res))
|
||||
==
|
||||
~& [%sent-a-known-transaction--skipping id.res]
|
||||
$(responses t.responses)
|
||||
?: ?| =('nonce too low' message.res)
|
||||
=('Nonce too low' message.res)
|
||||
==
|
||||
::NOTE this assumes it's an "oops re-sent txs" case
|
||||
~& [%nonce-too-low--skipping id.res]
|
||||
$(responses t.responses)
|
||||
|+[%transaction-send-failed >+.res< ~]
|
||||
==
|
||||
?: ?=(%| -.pending)
|
||||
(strand-fail:strandio p.pending)
|
||||
:: wait for the transactions to get confirmed
|
||||
::
|
||||
|-
|
||||
=* confirm-loop $
|
||||
?: =(~ p.pending)
|
||||
:: all confirmed, continue to next step-size transactions
|
||||
::
|
||||
submit-loop(txs (slag step-size txs))
|
||||
~& [~(wyt in p.pending) 'txs awaiting confirmation']
|
||||
:: get receipts
|
||||
::
|
||||
;< responses=(list response:rpc) bind:m
|
||||
%+ request-batch-rpc-loose:ethio url
|
||||
%+ turn ~(tap in p.pending)
|
||||
|= txh=@ux
|
||||
:- `(crip '0' 'x' ((x-co:co 64) txh))
|
||||
[%eth-get-transaction-receipt txh]
|
||||
:: find transactions that haven't been confirmed yet, bailing on failure
|
||||
::
|
||||
=/ unconfirmed=(each (set @ux) [term tang])
|
||||
=| done=(list @ux)
|
||||
|-
|
||||
?~ responses &+(~(dif in p.pending) (sy done))
|
||||
=/ res=response:rpc i.responses ::NOTE =* breaks typechecks
|
||||
?. ?=(?(%error %result) -.res)
|
||||
|+[%unexpected-non-result >res< ~]
|
||||
=/ txh=@ux (tape-to-ux (trip id.res))
|
||||
?- -.res
|
||||
%error
|
||||
~& :- 'receipt fetch error'
|
||||
[code.res message.res]
|
||||
$(responses t.responses)
|
||||
::
|
||||
%result
|
||||
?. ?=([%o *] res.res)
|
||||
$(responses t.responses)
|
||||
=/ status=@
|
||||
%- tape-to-ux
|
||||
%- sa:dejs:format
|
||||
(~(got by p.res.res) 'status')
|
||||
?. =(1 status)
|
||||
|+[%transaction-failed >txh< ~]
|
||||
$(responses t.responses, done [txh done])
|
||||
==
|
||||
?: ?=(%| -.unconfirmed)
|
||||
(strand-fail:strandio p.unconfirmed)
|
||||
:: some transactions still pending, wait for a bit, then check again
|
||||
::
|
||||
;< ~ bind:m (sleep:strandio ~s30)
|
||||
confirm-loop(pending unconfirmed)
|
Loading…
Reference in New Issue
Block a user