mirror of
https://github.com/urbit/shrub.git
synced 2024-12-24 11:24:21 +03:00
naive: add cancel pending transaction
This commit is contained in:
parent
7e9a2bcfcd
commit
c715ef59fd
@ -77,7 +77,7 @@
|
|||||||
::
|
::
|
||||||
+$ action
|
+$ action
|
||||||
$% [%submit force=? sig=@ tx=part-tx]
|
$% [%submit force=? sig=@ tx=part-tx]
|
||||||
[%cancel sig=@ keccak=@]
|
[%cancel sig=@ keccak=@ =l2-tx]
|
||||||
[%commit ~] ::TODO maybe pk=(unit @) later
|
[%commit ~] ::TODO maybe pk=(unit @) later
|
||||||
[%config config]
|
[%config config]
|
||||||
==
|
==
|
||||||
@ -130,14 +130,13 @@
|
|||||||
==
|
==
|
||||||
[cards this]
|
[cards this]
|
||||||
:: +on-peek: scry paths
|
:: +on-peek: scry paths
|
||||||
::TODO reevaluate wrt recent flow changes
|
|
||||||
::
|
::
|
||||||
:: /x/pending -> %noun (list pend-tx)
|
:: /x/pending -> %noun (list pend-tx)
|
||||||
:: /x/pending/[~ship] -> %noun (list pend-tx)
|
:: /x/pending/[~ship] -> %noun (list pend-tx)
|
||||||
:: /x/pending/[0xadd.ress] -> %noun (list pend-tx)
|
:: /x/pending/[0xadd.ress] -> %noun (list pend-tx)
|
||||||
:: /x/tx/[0xke.ccak]/status -> %noun tx-status
|
:: /x/tx/[0xke.ccak]/status -> %noun tx-status
|
||||||
:: /x/nonce/[~ship]/[proxy] -> %noun (unit @)
|
:: /x/nonce/[~ship]/[proxy] -> %noun (unit @)
|
||||||
:: /x/spawned/[~ship] -> %noun (list [ship address)
|
:: /x/spawned/[~ship] -> %noun (list [ship address])
|
||||||
:: /x/next-batch -> %atom time
|
:: /x/next-batch -> %atom time
|
||||||
::
|
::
|
||||||
++ on-peek
|
++ on-peek
|
||||||
@ -434,7 +433,7 @@
|
|||||||
%don [(gen-tx-octs:lib +.part-tx) +.part-tx]
|
%don [(gen-tx-octs:lib +.part-tx) +.part-tx]
|
||||||
%ful +.part-tx
|
%ful +.part-tx
|
||||||
==
|
==
|
||||||
:: +canonical-state: load current state instead of cached state
|
:: +canonical-state: load current l2 state instead
|
||||||
::
|
::
|
||||||
++ canonical-state
|
++ canonical-state
|
||||||
.^ ^state:naive
|
.^ ^state:naive
|
||||||
@ -452,8 +451,6 @@
|
|||||||
++ predicted-state
|
++ predicted-state
|
||||||
|= nas=^state:naive
|
|= nas=^state:naive
|
||||||
^- [_pending _nas]
|
^- [_pending _nas]
|
||||||
:: apply our pending transactions
|
|
||||||
::
|
|
||||||
|^
|
|^
|
||||||
=^ new-sending nas apply-sending
|
=^ new-sending nas apply-sending
|
||||||
=. sending new-sending
|
=. sending new-sending
|
||||||
@ -468,7 +465,6 @@
|
|||||||
=* key p.i.sending
|
=* key p.i.sending
|
||||||
=* val q.i.sending
|
=* val q.i.sending
|
||||||
=^ new-valid nas
|
=^ new-valid nas
|
||||||
:: prepends force=%.n to all txs
|
|
||||||
%- update-txs
|
%- update-txs
|
||||||
(turn txs.val |=(=raw-tx:naive [| 0x0 raw-tx]))
|
(turn txs.val |=(=raw-tx:naive [| 0x0 raw-tx]))
|
||||||
=. valid
|
=. valid
|
||||||
@ -519,13 +515,8 @@
|
|||||||
?- -.action
|
?- -.action
|
||||||
%commit on-timer
|
%commit on-timer
|
||||||
%config (on-config +.action)
|
%config (on-config +.action)
|
||||||
%cancel !! ::TODO
|
%cancel (cancel-tx +.action)
|
||||||
::
|
%submit (take-tx force.action sig.action (part-tx-to-full tx.action))
|
||||||
%submit
|
|
||||||
%^ take-tx
|
|
||||||
force.action
|
|
||||||
sig.action
|
|
||||||
(part-tx-to-full tx.action)
|
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
++ on-config
|
++ on-config
|
||||||
@ -557,6 +548,62 @@
|
|||||||
++ get-address
|
++ get-address
|
||||||
^- address:ethereum
|
^- address:ethereum
|
||||||
(address-from-prv:key:ethereum pk)
|
(address-from-prv:key:ethereum pk)
|
||||||
|
:: +cancel-tx: cancel a pending transaction
|
||||||
|
::
|
||||||
|
++ cancel-tx
|
||||||
|
|= [sig=@ =keccak =l2-tx]
|
||||||
|
^- (quip card _state)
|
||||||
|
?^ status=(~(get by finding) keccak)
|
||||||
|
~? lverb [dap.bowl %tx-not-pending status+u.status]
|
||||||
|
[~ state]
|
||||||
|
:: "cancel: 0x1234abcd"
|
||||||
|
::
|
||||||
|
=/ message=octs
|
||||||
|
%: cad:naive 3
|
||||||
|
8^'cancel: '
|
||||||
|
::
|
||||||
|
=; hash=@t
|
||||||
|
(met 3 hash)^hash
|
||||||
|
(crip "0x{((x-co:co 20) keccak)}")
|
||||||
|
::
|
||||||
|
~
|
||||||
|
==
|
||||||
|
?~ addr=(verify-sig sig message)
|
||||||
|
~? lverb [dap.bowl %cancel-sig-fail]
|
||||||
|
[~ state]
|
||||||
|
=. history
|
||||||
|
%+ ~(del ju history) u.addr
|
||||||
|
[[%pending ~] keccak l2-tx]
|
||||||
|
=. pending
|
||||||
|
%+ skip pending
|
||||||
|
|= pend-tx
|
||||||
|
=(keccak (hash-raw-tx raw-tx))
|
||||||
|
[~ state]
|
||||||
|
:: TODO: move to /lib/naive-transactions
|
||||||
|
::
|
||||||
|
++ verify-sig
|
||||||
|
|= [sig=@ txdata=octs]
|
||||||
|
^- (unit address:naive)
|
||||||
|
|^
|
||||||
|
:: Reversed of the usual r-s-v order because Ethereum integers are
|
||||||
|
:: big-endian
|
||||||
|
::
|
||||||
|
=^ v sig (take 3)
|
||||||
|
=^ s sig (take 3 32)
|
||||||
|
=^ r sig (take 3 32)
|
||||||
|
:: In Ethereum, v is generally 27 + recid, and verifier expects a
|
||||||
|
:: recid. Old versions of geth used 0 + recid, so most software
|
||||||
|
:: now supports either format. See:
|
||||||
|
::
|
||||||
|
:: https://github.com/ethereum/go-ethereum/issues/2053
|
||||||
|
::
|
||||||
|
=? v (gte v 27) (sub v 27)
|
||||||
|
(verifier:lib txdata v r s)
|
||||||
|
::
|
||||||
|
++ take
|
||||||
|
|= =bite
|
||||||
|
[(end bite sig) (rsh bite sig)]
|
||||||
|
--
|
||||||
:: +take-tx: accept submitted l2 tx into the :pending list
|
:: +take-tx: accept submitted l2 tx into the :pending list
|
||||||
::
|
::
|
||||||
++ take-tx
|
++ take-tx
|
||||||
@ -716,6 +763,7 @@
|
|||||||
:: unexpected tx failures here. would that be useful? probably not?
|
:: unexpected tx failures here. would that be useful? probably not?
|
||||||
:: ~? !forced [dap.bowl %aggregated-tx-failed-anyway err.diff]
|
:: ~? !forced [dap.bowl %aggregated-tx-failed-anyway err.diff]
|
||||||
%failed
|
%failed
|
||||||
|
::
|
||||||
=. history
|
=. history
|
||||||
=/ tx=roller-tx
|
=/ tx=roller-tx
|
||||||
:+ [%sending ~]
|
:+ [%sending ~]
|
||||||
|
@ -127,8 +127,9 @@
|
|||||||
[~ ~(parse error:json-rpc id)]
|
[~ ~(parse error:json-rpc id)]
|
||||||
?+ method [~ ~(method error:json-rpc id)]
|
?+ method [~ ~(method error:json-rpc id)]
|
||||||
%get-point [~ (get-point id +.params point:scry)]
|
%get-point [~ (get-point id +.params point:scry)]
|
||||||
%get-spawned [~ (get-spawned id +.params spawned:scry)]
|
|
||||||
%transfer-point (transfer-point id +.params)
|
%transfer-point (transfer-point id +.params)
|
||||||
|
%cancel-tx (cancel-tx id +.params)
|
||||||
|
%get-spawned [~ (get-spawned id +.params spawned:scry)]
|
||||||
%configure-keys (configure-keys id +.params)
|
%configure-keys (configure-keys id +.params)
|
||||||
%spawn (spawn id +.params)
|
%spawn (spawn id +.params)
|
||||||
%escape (escape id +.params method)
|
%escape (escape id +.params method)
|
||||||
|
@ -99,7 +99,7 @@
|
|||||||
|= params=(map @t json)
|
|= params=(map @t json)
|
||||||
^- (unit @)
|
^- (unit @)
|
||||||
?~ sig=(~(get by params) 'sig') ~
|
?~ sig=(~(get by params) 'sig') ~
|
||||||
(so u.sig)
|
(ni u.sig)
|
||||||
::
|
::
|
||||||
++ from
|
++ from
|
||||||
|= params=(map @t json)
|
|= params=(map @t json)
|
||||||
@ -125,6 +125,13 @@
|
|||||||
?~ raw=(~(get by params) 'raw') ~
|
?~ raw=(~(get by params) 'raw') ~
|
||||||
?~ ans=(so u.raw) ~
|
?~ ans=(so u.raw) ~
|
||||||
(some (as-octs:mimes:html u.ans))
|
(some (as-octs:mimes:html u.ans))
|
||||||
|
::
|
||||||
|
++ l2-tx
|
||||||
|
|= params=(map @t json)
|
||||||
|
^- (unit ^l2-tx)
|
||||||
|
?~ type=(~(get by params) 'type') ~
|
||||||
|
%. u.type
|
||||||
|
(cu ^l2-tx so)
|
||||||
--
|
--
|
||||||
::
|
::
|
||||||
++ to-json
|
++ to-json
|
||||||
@ -362,17 +369,6 @@
|
|||||||
~(not-found error:json-rpc id)
|
~(not-found error:json-rpc id)
|
||||||
[%result id (point:to-json u.point)]
|
[%result id (point:to-json u.point)]
|
||||||
::
|
::
|
||||||
++ get-spawned
|
|
||||||
|= [id=@t params=(map @t json) scry=$-(ship (list [ship @ux]))]
|
|
||||||
^- response:rpc
|
|
||||||
?. =((lent ~(tap by params)) 1)
|
|
||||||
~(params error:json-rpc id)
|
|
||||||
?~ ship=(~(get by params) 'ship')
|
|
||||||
~(params error:json-rpc id)
|
|
||||||
?~ ship=(rush (so:dejs:format u.ship) ;~(pfix sig fed:ag))
|
|
||||||
~(params error:json-rpc id)
|
|
||||||
[%result id (spawned:to-json (scry u.ship))]
|
|
||||||
::
|
|
||||||
++ transfer-point
|
++ transfer-point
|
||||||
|= [id=@t params=(map @t json)]
|
|= [id=@t params=(map @t json)]
|
||||||
^- [(unit cage) response:rpc]
|
^- [(unit cage) response:rpc]
|
||||||
@ -385,9 +381,32 @@
|
|||||||
?: |(?=(~ sig) ?=(~ from) ?=(~ raw) ?=(~ data))
|
?: |(?=(~ sig) ?=(~ from) ?=(~ raw) ?=(~ data))
|
||||||
[~ ~(parse error:json-rpc id)]
|
[~ ~(parse error:json-rpc id)]
|
||||||
:_ [%result id s+'ok']
|
:_ [%result id s+'ok']
|
||||||
|
::
|
||||||
|
++ cancel-tx
|
||||||
|
|= [id=@t params=(map @t json)]
|
||||||
|
^- [(unit cage) response:rpc]
|
||||||
|
?. =(~(wyt by params) 3)
|
||||||
|
[~ ~(params error:json-rpc id)]
|
||||||
|
=/ sig=(unit @) (sig:from-json params)
|
||||||
|
=/ keccak=(unit @ux) (hash:from-json params)
|
||||||
|
=/ l2=(unit l2-tx) (l2-tx:from-json params)
|
||||||
|
?. &(?=(^ sig) ?=(^ keccak) ?=(^ l2))
|
||||||
|
[~ ~(parse error:json-rpc id)]
|
||||||
|
:_ [%result id s+'ok']
|
||||||
%- some
|
%- some
|
||||||
:- %aggregator-action
|
:- %aggregator-action
|
||||||
!>([%submit | u.sig %ful u.raw u.from %transfer-point u.data])
|
!>([%cancel u.sig u.keccak u.l2])
|
||||||
|
::
|
||||||
|
++ get-spawned
|
||||||
|
|= [id=@t params=(map @t json) scry=$-(ship (list [ship @ux]))]
|
||||||
|
^- response:rpc
|
||||||
|
?. =((lent ~(tap by params)) 1)
|
||||||
|
~(params error:json-rpc id)
|
||||||
|
?~ ship=(~(get by params) 'ship')
|
||||||
|
~(params error:json-rpc id)
|
||||||
|
?~ ship=(rush (so:dejs:format u.ship) ;~(pfix sig fed:ag))
|
||||||
|
~(params error:json-rpc id)
|
||||||
|
[%result id (spawned:to-json (scry u.ship))]
|
||||||
::
|
::
|
||||||
++ configure-keys
|
++ configure-keys
|
||||||
|= [id=@t params=(map @t json)]
|
|= [id=@t params=(map @t json)]
|
||||||
|
Loading…
Reference in New Issue
Block a user