roller: add get-pending-tx rpc from l2 tx hash

This commit is contained in:
yosoyubik 2021-09-07 12:59:36 +02:00
parent cb44dccafa
commit 32cbb97b40
3 changed files with 47 additions and 9 deletions

View File

@ -161,6 +161,7 @@
%get-all-pending `(all:pending id +.params all:pending:scry)
%get-pending-by-ship `(ship:pending id +.params ship:pending:scry)
%get-pending-by-address `(addr:pending id +.params addr:pending:scry)
%get-pending-tx `(hash:pending id +.params hash:pending:scry)
%get-transaction-status `(status id +.params tx-status:scry)
%when-next-batch `(next-batch id +.params next-batch:scry)
%get-nonce `(nonce id +.params nonce:scry)
@ -258,6 +259,14 @@
%+ ~(scry agentio bowl) %roller
/pending/[(scot %ux address)]/noun
==
::
++ hash
|= keccak=@ux
.^ (unit pend-tx)
%gx
%+ ~(scry agentio bowl) %roller
/pending-tx/[(scot %ux keccak)]/noun
==
--
::
++ history

View File

@ -174,6 +174,7 @@
[%x %pending ~] ``noun+!>(pending)
[%x %pending @ ~] (pending-by i.t.t.path)
[%x %tx @ %status ~] (status i.t.t.path)
[%x %pending-tx @ ~] (transaction i.t.t.path)
[%x %history @ ~] (history i.t.t.path)
[%x %nonce @ @ ~] (nonce i.t.t.path i.t.t.t.path)
[%x %spawned @ ~] (spawned i.t.t.path)
@ -221,13 +222,29 @@
?^ status=(~(get by finding) u.keccak)
?@ u.status [u.status ~]
[%sending `+.u.status]
::TODO potentially slow!
:: TODO: potentially slow!
:: TODO: use ~(get by history) instead
=; known=?
[?:(known %pending %unknown) ~]
%+ lien pending
|= pend-tx
=(u.keccak (hash-tx:lib raw.raw-tx))
::
++ transaction
|= wat=@t
?~ keccak=(slaw %ux wat)
[~ ~]
:+ ~ ~
:- %noun
!> ^- (unit pend-tx)
:: TODO: potentially slow!
|-
?~ pending ~
=* tx i.pending
?: =(u.keccak (hash-tx:lib raw.raw-tx.tx))
`tx
$(pending t.pending)
::
++ history
|= wat=@t
:+ ~ ~

View File

@ -184,11 +184,7 @@
++ to-json
=, enjs:format
|%
++ pending
|= pending=(list pend-tx)
^- json
:- %a
%+ turn pending
++ pending-tx
|= pend-tx
^- json
%- pairs
@ -201,6 +197,11 @@
['sig' (hex (as-octs:mimes:html sig.raw-tx))]
== ==
::
++ pending-txs
|= pending=(list pend-tx)
^- json
a+(turn pending pending-tx)
::
++ en-address |=(a=@ux address+(hex 20 a))
::
++ tx
@ -524,7 +525,7 @@
^- response:rpc
?. =((lent ~(tap by params)) 0)
~(params error:json-rpc id)
[%result id (pending:to-json pending)]
[%result id (pending-txs:to-json pending)]
::
++ ship
|= [id=@t params=(map @t json) scry=$-(@p (list pend-tx))]
@ -533,7 +534,7 @@
~(params error:json-rpc id)
?~ ship=(ship:from-json params)
~(parse error:json-rpc id)
[%result id (pending:to-json (scry u.ship))]
[%result id (pending-txs:to-json (scry u.ship))]
::
++ addr
|= [id=@t params=(map @t json) scry=$-(@ux (list pend-tx))]
@ -542,7 +543,18 @@
~(params error:json-rpc id)
?~ address=(address:from-json params)
~(parse error:json-rpc id)
[%result id (pending:to-json (scry u.address))]
[%result id (pending-txs:to-json (scry u.address))]
::
++ hash
|= [id=@t params=(map @t json) scry=$-(@ux (unit pend-tx))]
^- response:rpc
?. =((lent ~(tap by params)) 1)
~(params error:json-rpc id)
?~ hash=(hash:from-json params)
~(parse error:json-rpc id)
?~ tx=(scry u.hash)
~(not-found error:json-rpc id)
[%result id (pending-tx:to-json u.tx)]
--
::
++ status