urbit/app/send-txs.hoon

276 lines
6.5 KiB
Plaintext
Raw Normal View History

::
:: there's a small state machine here that goes like this (happy path):
:: =/ wen ~
:: apex
:: -> [if =(~ wen)]
:: -> apex
:: [else]
:: -> wen=`(add now ~s10)
:: -> send-next-batch
:: [n times]
:: -> eth-send-raw-transaction
:: -> sigh-send
:: -> wait 30s in behn
:: -> wake-see
:: [n times]
:: -> wen=~
:: -> eth-get-transaction-receipt
:: -> sigh-see
:: -> apex
::
/+ ceremony
::
|%
++ state
$: txs=(list @ux)
see=(set @ux)
wen=(unit @da)
==
::
++ move (pair bone card)
++ card
2018-11-09 00:25:20 +03:00
$% [%hiss wire ~ mark %hiss hiss:eyre]
2018-11-10 02:24:31 +03:00
[%info wire ship desk nori:clay]
[%rest wire @da]
[%wait wire @da]
==
--
::
|_ [bol=bowl:gall state]
::
++ this .
++ pretty-see (turn (sort (turn ~(tap in see) mug) lth) @p)
::
++ prep
|= old=(unit *)
?: ?=([~ * * ~ @da] old)
~& [%cancelling +>+>.old]
[[ost.bol %rest /see +>+>.old]~ ..prep]
[~ ..prep]
::
2018-11-10 02:24:31 +03:00
:: usage:
::
:: send all but first 50 txs from path
:: :send-txs [%/txs/txt 50]
::
:: generate txs starting from nonce 0 on fake chain at various
:: gas prices; store at path (one file per gas price)
::
:: :send-txs [% %fake 0]
::
:: generate txs starting from nonce 0 on fake chain at 11 gwei;
:: store at path
:: :send-txs [%/txs/txt %fake 0 11]
::
++ poke-noun
2018-11-10 02:24:31 +03:00
|= $: pax=path
$= argv
$@ skip=@ud
$: net=?(%fake %main %ropsten)
$= conf
$@ nonce=@ud
[nonce=@ud gas-price=@ud]
==
==
^- [(list move) _this]
2018-11-10 02:24:31 +03:00
?^ argv
?^ conf.argv
=/ tox
(sequence:ceremony now.bol [net [gas-price nonce]:conf]:argv)
[[(write-file pax tox) ~] this]
=- [- this]
%+ turn
`(list @ud)`~[2 3 5] :: 11 21 31 51 91]
|= gas-price=@ud
%+ write-file (weld pax /(scot %ud gas-price)/txt)
(sequence:ceremony now.bol net.argv gas-price nonce.conf.argv)
~& 'loading txs...'
2018-11-10 02:24:31 +03:00
=/ tox=(list cord) .^((list cord) %cx pax)
~& ?>(?=(^ tox) i.tox)
=. tox (slag +(skip.argv) tox)
=. txs
%+ turn tox
(cork trip tape-to-ux:ceremony)
~& [(lent txs) 'loaded txs']
apex
::
2018-11-10 02:24:31 +03:00
++ write-file
|= [pax=path tox=(list cord)]
^- move
?> ?=([@ desk @ *] pax)
:* ost.bol
%info
(weld /write pax)
our.bol
i.t.pax
=- &+[t.t.t.pax -]~
=/ y .^(arch %cy pax)
?~ fil.y
ins+txt+!>(tox)
mut+txt+!>(tox)
==
::
2018-11-09 00:25:20 +03:00
++ fan-requests
|= [wir=wire nodes=(list [tag=@tas url=purl:eyre]) jon=json]
:: =- ~& [batch=((list ,[bone * wire]) (turn - |=(* [- +< +>-]:+<))) jon=jon] -
^- (list move)
%+ turn nodes
|= [tag=@tas url=purl:eyre]
^- move
:- ost.bol
2018-11-09 00:25:20 +03:00
:^ %hiss (weld wir ~[tag]) ~
:+ %json-rpc-response %hiss
2018-11-09 00:25:20 +03:00
(json-request:ethereum url jon)
::
++ batch-requests
|= [wir=wire fan=? req=(list [(unit @t) request:ethe])]
^- (list move)
%^ fan-requests
wir
?: fan
:~ => (need (de-purl:html 'http://localhost:8545'))
geth+.(p.p |)
::
=> (need (de-purl:html 'http://localhost:8555'))
parity+.(p.p |)
2018-11-09 00:25:20 +03:00
==
:_ ~
=> (need (de-purl:html 'http://localhost:8545'))
geth+.(p.p |)
a+(turn req request-to-json:ethereum)
::
++ send-next-batch
^- [(list move) _this]
?: =(0 (lent txs))
~& 'all sent!'
[~ this(txs ~, see ~, wen ~)]
:: ~& send-next-batch=pretty-see
=/ new-count (sub 500 ~(wyt in see))
?: =(0 new-count)
~& %no-new-txs-yet
`this
:_ this(txs (slag new-count txs))
~& ['remaining txs: ' (lent txs)]
~& ['sending txs...' new-count]
2018-11-09 00:25:20 +03:00
%^ batch-requests /send &
%+ turn (scag new-count txs)
|= tx=@ux
:- `(crip 'id-' (scot %ux (end 3 10 tx)) ~)
[%eth-send-raw-transaction tx]
::
++ sigh-json-rpc-response-send
|= [wir=wire res=response:rpc:jstd]
^- [(list move) _this]
?: ?=(%fail -.res)
~& %send-failed
2018-11-09 00:25:20 +03:00
`this
?> ?=(%batch -.res)
:: ~& sigh-send-a=pretty-see
=. see
%- ~(uni in see)
%- silt
^- (list @ux)
%+ murn bas.res
|= r=response:rpc:jstd
^- (unit @ux)
?: ?=(%error -.r)
?: ?| =('known transaction' (end 3 17 message.r))
=('Known transaction' (end 3 17 message.r))
=('Transaction with the same ' (end 3 26 message.r))
==
2018-11-09 00:25:20 +03:00
~& [%sent-a-known-transaction--skipping wir r]
~
?: =('Nonce too low' message.r)
~& %nonce-too-low--skipping
~
~| :- 'transaction send failed, game over'
[code.r message.r]
!!
?> ?=(%result -.r)
2018-10-18 01:12:11 +03:00
:- ~
%- tape-to-ux:ceremony
(sa:dejs:format res.r)
:: ~& sigh-send-b=pretty-see
`this
::
++ apex
^- [(list move) _this]
~& :_ ~(wyt in see)
'waiting for transaction confirms... '
?. =(~ wen) [~ this]
=. wen `(add now.bol ~s10)
:: ~& apex=[wen pretty-see]
=^ moves this send-next-batch
[[[ost.bol %wait /see (need wen)] moves] this]
::
++ wake-see
|= [wir=wire ~]
^- [(list move) _this]
=. wen ~
:: ~& wake-see=[wen pretty-see]
?: =(~ see)
apex
:_ this
%^ batch-requests /see &
%+ turn ~(tap in see)
|= txh=@ux
:- `(crip 'see-0x' ((x-co:co 64) txh))
[%eth-get-transaction-receipt txh]
::
++ sigh-json-rpc-response-see
|= [wir=wire res=response:rpc:jstd]
^- [(list move) _this]
?: ?| ?=(%error -.res)
?=(%fail -.res)
==
~& [%bad-rpc-response--kicking res]
apex
:: `this
?> ?=(%batch -.res)
?: =(~ see)
apex
2018-10-11 02:59:04 +03:00
?: =(0 (lent bas.res))
::TODO node lost our txs?
~& [%txs-lost-tmp wir '!!']
apex
:: ~& sigh-see-a=pretty-see
=. see
%- ~(dif in see)
%- silt
^- (list @ux)
%+ murn bas.res
|= r=response:rpc:jstd
^- (unit @ux)
?< ?=(%batch -.r)
2018-11-09 00:25:20 +03:00
?< ?=(%fail -.r)
~| [id.r res]
=+ txh=(tape-to-ux:ceremony (trip (rsh 3 4 id.r)))
~& see-tx=[(@p (mug txh)) `@ux`txh]
=* done `txh
=* wait ~
?: ?=(%error -.r)
~& :- 'receipt fetch error'
[code.r message.r]
wait
?~ res.r wait
?> ?=(%o -.res.r)
=/ status
%- tape-to-ux:ceremony
%- sa:dejs:format
(~(got by p.res.r) 'status')
?: =(1 status)
done
~& [%see-bad-status status]
wait
:: ~& sigh-see-b=pretty-see
apex
::
++ sigh-tang
|= [wir=wire err=tang]
~& [%sigh-tang wir]
~& (slog err)
?: =(~ wen) [~ this]
=. wen `(add now.bol ~s10)
[[ost.bol %wait /see (need wen)]~ this]
--