mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-11 08:55:23 +03:00
Send transactions in batches of 50, wait for success
This commit is contained in:
parent
1141b79e10
commit
42734b747b
@ -1,9 +1,12 @@
|
||||
::
|
||||
/- json-rpc
|
||||
/+ ceremony
|
||||
::
|
||||
|%
|
||||
++ state
|
||||
$: txs=(list @ux)
|
||||
see=(set @ux)
|
||||
wen=@da
|
||||
==
|
||||
::
|
||||
++ move (pair bone card)
|
||||
@ -15,11 +18,17 @@
|
||||
::
|
||||
|_ [bol=bowl:gall state]
|
||||
::
|
||||
++ this .
|
||||
::
|
||||
++ prep
|
||||
|= old=(unit *)
|
||||
[~ ..prep]
|
||||
::
|
||||
++ poke-noun
|
||||
|= a=@t
|
||||
^- [(list move) _+>]
|
||||
?. =('start' a) [~ +>]
|
||||
~& 'loading txs'
|
||||
^- [(list move) _this]
|
||||
?. =('start' a) [~ this]
|
||||
~& 'loading txs...'
|
||||
=/ tox=(list cord)
|
||||
.^ (list cord) %cx
|
||||
/(scot %p our.bol)/home/(scot %da now.bol)/txs/txt
|
||||
@ -27,19 +36,106 @@
|
||||
=. txs
|
||||
%+ turn tox
|
||||
(cork trip tape-to-ux:ceremony)
|
||||
~& 'sending moves'
|
||||
:_ +>.$
|
||||
:_ ~
|
||||
~& [(lent txs) 'loaded txs']
|
||||
send-next-batch
|
||||
::
|
||||
++ batch-requests
|
||||
|= [wir=wire req=(list [(unit @t) request:ethe])]
|
||||
^- move
|
||||
:- ost.bol
|
||||
:^ %hiss /aaa [~ ~]
|
||||
:^ %hiss wir [~ ~]
|
||||
:+ %json-rpc-response %hiss
|
||||
%+ json-request:ethereum
|
||||
=+ (need (de-purl:html 'http://localhost:8545'))
|
||||
-(p.p |)
|
||||
:- %a
|
||||
%+ turn txs
|
||||
%+ turn req
|
||||
request-to-json:ethereum
|
||||
::
|
||||
++ send-next-batch
|
||||
^- [(list move) _this]
|
||||
?: =(0 (lent txs))
|
||||
~& 'all sent!'
|
||||
[~ this]
|
||||
:_ .(txs (slag 50 txs))
|
||||
~& ['waiting txs: ' (lent txs)]
|
||||
~& 'sending 50 txs...'
|
||||
:_ ~
|
||||
%+ batch-requests /send
|
||||
%+ turn (scag 50 txs)
|
||||
|= tx=@ux
|
||||
%+ request-to-json:ethereum ~
|
||||
:- `'id'
|
||||
[%eth-send-raw-transaction tx]
|
||||
::
|
||||
++ sigh-json-rpc-response-send
|
||||
|= [wir=wire res=response:json-rpc]
|
||||
^- [(list move) _this]
|
||||
?> ?=(%batch -.res)
|
||||
=. see
|
||||
%- ~(gas in see)
|
||||
%+ turn bas.res
|
||||
|= r=response:json-rpc
|
||||
^- @ux
|
||||
?: ?=(%error -.r)
|
||||
~| :- 'transaction send failed, game over'
|
||||
[code.r message.r]
|
||||
!!
|
||||
?> ?=(%result -.r)
|
||||
%- tape-to-ux:ceremony
|
||||
(sa:dejs:format res.r)
|
||||
(wake-see ~ ~)
|
||||
::
|
||||
++ kick-timer
|
||||
^- [(list move) _this]
|
||||
~& :_ ~(wyt in see)
|
||||
'waiting for transaction confirms... '
|
||||
?: (gth wen now.bol) [~ this]
|
||||
=. wen (add now.bol ~s5) ::TODO more sane/polite value
|
||||
[[ost.bol %wait /see wen]~ this]
|
||||
::
|
||||
++ wake-see
|
||||
|= [wir=wire ~]
|
||||
^- [(list move) _this]
|
||||
:_ this(see ~)
|
||||
:_ ~
|
||||
^- move
|
||||
%+ batch-requests /see
|
||||
%+ turn ~(tap in see)
|
||||
|= txh=@ux
|
||||
:- `(crip '0' 'x' ((x-co:co 64) txh))
|
||||
[%eth-get-transaction-receipt txh]
|
||||
::
|
||||
++ sigh-json-rpc-response-see
|
||||
|= [wir=wire res=response:json-rpc]
|
||||
^- [(list move) _this]
|
||||
?> ?=(%batch -.res)
|
||||
=. see
|
||||
%- ~(gas in see)
|
||||
%+ murn bas.res
|
||||
|= r=response:json-rpc
|
||||
^- (unit @ux)
|
||||
?< ?=(%batch -.r)
|
||||
=+ txh=(tape-to-ux:ceremony (trip id.r))
|
||||
?: ?=(%error -.r)
|
||||
~& :- 'receipt fetch error'
|
||||
[code.r message.r]
|
||||
`txh
|
||||
?~ res.r `txh
|
||||
?> ?=(%o -.res.r)
|
||||
=+ stat=(~(got by p.res.r) 'status')
|
||||
?: .= 1
|
||||
%- tape-to-ux:ceremony
|
||||
(sa:dejs:format stat)
|
||||
~
|
||||
`txh
|
||||
?~ see
|
||||
~& 'batch confirmed, next!'
|
||||
send-next-batch
|
||||
kick-timer
|
||||
::
|
||||
++ sigh-tang
|
||||
|= [wir=wire err=tang]
|
||||
~& %sigh-tang
|
||||
~& (slog err)
|
||||
[~ this]
|
||||
--
|
||||
|
@ -171,6 +171,7 @@
|
||||
==
|
||||
[%eth-get-filter-logs fid=@ud]
|
||||
[%eth-get-filter-changes fid=@ud]
|
||||
[%eth-get-transaction-receipt txh=@ux]
|
||||
[%eth-send-raw-transaction dat=@ux]
|
||||
==
|
||||
::
|
||||
@ -7349,6 +7350,9 @@
|
||||
::
|
||||
%eth-get-filter-changes
|
||||
['eth_getFilterChanges' (tape (num-to-hex fid.req)) ~]
|
||||
::
|
||||
%eth-get-transaction-receipt
|
||||
['eth_getTransactionReceipt' (tape (transaction-to-hex txh.req)) ~]
|
||||
::
|
||||
%eth-send-raw-transaction
|
||||
['eth_sendRawTransaction' (tape (num-to-hex dat.req)) ~]
|
||||
@ -7399,6 +7403,12 @@
|
||||
%- prefix-hex
|
||||
(render-hex-bytes 20 `@`a)
|
||||
::
|
||||
++ transaction-to-hex
|
||||
|= h=@
|
||||
^- tape
|
||||
%- prefix-hex
|
||||
(render-hex-bytes 32 h)
|
||||
::
|
||||
++ prefix-hex
|
||||
|= a=tape
|
||||
^- tape
|
||||
|
Loading…
Reference in New Issue
Block a user