From 32cbb97b404d8af73ca05c467df5782f8762ca9d Mon Sep 17 00:00:00 2001 From: yosoyubik Date: Tue, 7 Sep 2021 12:59:36 +0200 Subject: [PATCH] roller: add get-pending-tx rpc from l2 tx hash --- pkg/arvo/app/roller-rpc.hoon | 9 +++++++++ pkg/arvo/app/roller.hoon | 19 ++++++++++++++++++- pkg/arvo/lib/azimuth-roll-rpc.hoon | 28 ++++++++++++++++++++-------- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/pkg/arvo/app/roller-rpc.hoon b/pkg/arvo/app/roller-rpc.hoon index 50d0bee088..4d3622a52a 100644 --- a/pkg/arvo/app/roller-rpc.hoon +++ b/pkg/arvo/app/roller-rpc.hoon @@ -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 diff --git a/pkg/arvo/app/roller.hoon b/pkg/arvo/app/roller.hoon index 82d16c72f3..b6c4fb8747 100644 --- a/pkg/arvo/app/roller.hoon +++ b/pkg/arvo/app/roller.hoon @@ -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 :+ ~ ~ diff --git a/pkg/arvo/lib/azimuth-roll-rpc.hoon b/pkg/arvo/lib/azimuth-roll-rpc.hoon index 04c8081fd6..0a9e6a18d2 100644 --- a/pkg/arvo/lib/azimuth-roll-rpc.hoon +++ b/pkg/arvo/lib/azimuth-roll-rpc.hoon @@ -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