roller: wip roller-cli client

This commit is contained in:
yosoyubik 2021-08-22 18:23:30 +02:00
parent fbbbc834b7
commit f87658b1ad
9 changed files with 819 additions and 105 deletions

View File

@ -105,7 +105,7 @@
?. =(contract address.i.logs)
=< own
(apply-effects raw-effects nas.state own.state chain-id)
(update-ownership raw-effects nas.state new-nas own.state)
+:(update-ownership raw-effects nas.state new-nas own.state)
=. nas.state new-nas
=/ effects-1
=/ =id:block [block-hash block-number]:u.mined.i.logs

View File

@ -0,0 +1,535 @@
:: roller-cli: CLI for L2 Azimuth Rollers
::
:: TODO: commands
::
:: client | roller
:: _________|___________
:: - CLI command
:: [%track 0x1234.abcd]
:: - init subscriptions to the roller
:: watch --> /point/[0x1234.abcd] - point updates
:: watch --> /tx/[0x1234.abcd] - tx status updates
::
:: ----------------------
:: Submit Txs
:: poke --tx--> +take-tx
::
:: ---------------------
:: Receive Tx status updates
:: watch /tx/[0x1234.abcd]
::
:: <--(list roller-tx:dice)-- - init
:: <--[address roller-tx:dice]-- - update
:: <--%kick-sub-- ?: ?=(?(%confirmed %failed) tx-status)
:: ---------------------
:: Receive Point updates (i.e. nonces)
:: watch /point/[0x1234.abcd]
::
:: <-(list point:naive)- - init
:: <-[address point:naive]- - update
::
/- *dice
/+ *dice,
naive,
lib=naive-transactions,
*fake-roller,
shoe,
verb,
dbug,
default-agent,
ethereum
|%
+$ app-state
$: %0
:: TODO: keep track of sessions
::
:: sessions=(map sole-id session)
points=(jug address:ethereum [ship point:naive])
history=(jug address:ethereum roller-tx)
unsigned-txs=(jug address:ethereum [keccak tx:naive])
:: TODO: track pub/prv keys
::
:: keys=(list (pair address:ethereum address:ethereum)
==
::
+$ card card:shoe
::
+$ command
$% :: List all possible L2 tx types
::
[%l2-tx ~] :: ?
:: Loads a new address (login?)
:: — should require signing?
:: - it subscribes to the Roller, for updates to it
:: - innitially receives a list of points (if any) it controls
::
:: [%track pubkey=address:ethereum prvkey=address:ethereum]
[%track address:ethereum]
:: Table of all submitted txs, by address
::
[%history address:ethereum]
:: Table of all unsigned txs, by address
::
[%show-unsigned ~]
:: Signs and Submit an unsigned txs (signed)
::
[%submit address:ethereum tx:naive]
:: Cancels a submitted (but pending) txs
::
[%cancel ~]
:: Ships owned by an address
::
[%ships address:ethereum]
:: Example flow
::
[%example-flow ~]
==
--
=| app-state
=* state -
::
%+ verb |
%- agent:dbug
^- agent:gall
%- (agent:shoe command)
^- (shoe:shoe command)
:: => |%
:: ++ get-address-points
:: |= [roller=@p =address:ethereum]
:: :* %pass
:: /roller-points
:: %agent
:: [roller %azimuth]
:: %watch
:: /address/[address]
:: ==
:: --
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
des ~(. (default:shoe this command) bowl)
::
++ on-init on-init:def
++ on-save !>(state)
++ on-load
|= old=vase
^- (quip card _this)
[~ this(state !<(app-state old))]
:: |^
:: =+ !<(old-state=app-states old)
:: |-
:: ?- -.old-state
:: %0 $(old-state [%1 ~ ~ ~])
:: %1 $(old-state [%2 ~ ~ ~])
:: %2 [~ this(state old-state)]
:: ==
:: ++ app-states $%([%0 ~] [%1 *] app-state)
:: --
::
++ on-poke on-poke:def
++ on-watch on-watch:def
++ on-leave on-leave:def
:: +on-peek: scry paths
::
:: /x/ships/[0x1234.abcd] -> %noun (list ship)
::
++ on-peek
|= =path
^- (unit (unit cage))
|^
?+ path ~
[%x %ships @ ~] (ships i.t.t.path)
==
::
++ ships
|= wat=@t
:+ ~ ~
:- %noun
!> ^- (list ship)
?~ addr=(slaw %ux wat) ~
%+ turn
~(tap in (~(get ju points) u.addr))
head
--
::
++ on-agent
|= [=wire =sign:agent:gall]
^- (quip card _this)
|^
?+ wire (on-agent:def wire sign)
[%points @ ~] (get-points i.t.wire sign)
[%txs @ ~] (get-txs i.t.wire sign)
==
::
++ get-points
|= [wat=@t =sign:agent:gall]
^- (quip card _this)
?+ -.sign (on-agent:def wire sign)
%fact
?+ p.cage.sign (on-agent:def wire sign)
%points
?~ addr=(slaw %ux wat) (on-agent:def wire sign)
=+ !<(points=(list [ship point:naive]) q.cage.sign)
=. points.state
(~(gas ju points.state) (turn points (cork same (lead u.addr))))
[~ this]
::
%point
?~ addr=(slaw %ux wat) (on-agent:def wire sign)
=+ !<(point=[ship point:naive] q.cage.sign)
:: TODO: handle multiple sole sessions?
::
:: =/ sez=(list [=sole-id =session])
:: ~(tap by sessions)
=/ console=tape
"Point update ({(scow %p -.point)})"
=. points.state
:: FIXME: doesn't properly update point
:: handle proper insert/deletion of points
:: to account for ownership changes/nonce updates
::
(~(put ju points.state) [u.addr point])
:_ this
:_ ~
:- %shoe
:- ~
:- %sole
?. =(src our):bowl
[%txt console]
[%klr [[`%br ~ `%g] [(crip console)]~]~]
==
==
::
++ get-txs
|= [wat=@t =sign:agent:gall]
^- (quip card _this)
?+ -.sign (on-agent:def wire sign)
%fact
?~ addr=(slaw %ux wat) (on-agent:def wire sign)
?+ p.cage.sign (on-agent:def wire sign)
%txs
=+ !<(txs=(list roller-tx) q.cage.sign)
=. history.state
(~(gas ju history.state) (turn txs (cork same (lead u.addr))))
[~ this]
::
%tx
?~ addr=(slaw %ux wat) (on-agent:def wire sign)
=+ !<(=roller-tx q.cage.sign)
=/ hash=tape
=+ hash=(scow %ux hash.roller-tx)
=+ len=(lent hash)
;: weld
(swag [0 6] hash)
"..."
(swag [(sub len 4) len] hash)
==
=/ console=tape
"Tx hash: {hash} -> {(trip status.roller-tx)}"
=. history.state (update-tx u.addr roller-tx)
:: ~& console
:_ this
:_ ~
:- %shoe
:- ~
:- %sole
?. =(src our):bowl
[%txt console]
[%klr [[`%br ~ `%g] [(crip console)]~]~]
==
==
::
++ update-tx
|= [=address:ethereum =roller-tx]
%. [address roller-tx]
?+ status.roller-tx ~(put ju history.state)
%pending
~(put ju history.state)
::
%sending
%~ put ju
%- ~(del ju history.state)
[address roller-tx(status %pending)]
::
%confirmed
%~ put ju
%- ~(del ju history.state)
[address roller-tx(status %sending)]
::
%failed
:: TODO: make it not ugly
::
%~ put ju
%- %~ del ju
%- ~(del ju history.state)
[address roller-tx(status %sending)]
[address roller-tx(status %pending)]
==
--
::
++ on-arvo on-arvo:def
++ on-fail on-fail:def
::
++ command-parser
|= sole-id=@ta
^+ |~(nail *(like [? command]))
:: wait for 'enter' to run the command
::
|^
%+ stag |
:: (perk %demo %row %table %track %submit %history ~)
;~ pose
;~(plug (tag %track) ;~(pfix (jest ' 0x') hex))
;~(plug (tag %example-flow) (easy ~))
;~(plug (tag %history) ;~(pfix (jest ' 0x') hex))
;~((glue ace) (tag %submit) submit)
;~((glue ace) (tag %ships) address)
==
::
++ tag |*(a=@tas (cold a (jest a))) :: TODO (from /app/chat-cli) into stdlib
++ address ;~(pfix (jest '0x') hex)
++ sponsorship
%- perk
:~ %escape
%cancel-escape
%adopt
%reject
%detach
==
::
++ ownership
%- perk
:~ %set-management-proxy
%set-spawn-proxy
%set-transfer-proxy
==
::
++ proxies
(perk %own %spawn %manage %vote %transfer ~)
++ submit
%+ cook ,[address:naive tx:naive]
;~ (glue ace)
address
:: from=[ship proxy:naive]
::
%+ cook ,[ship proxy:naive]
%+ ifix [sel ser]
;~((glue ace) ;~(pfix sig fed:ag) proxies)
:: skim-tx:naive
::
%+ cook ,skim-tx:naive
;~ pose
:: [%transfer-point =address reset=?]
::
;~ (glue ace)
(perk %transfer-point ~)
address
;~(pose (cold & (just 'y')) (cold | (just 'n')))
==
:: [%spawn ship address:naive]
::
;~ (glue ace)
(perk %spawn ~)
;~(pfix sig fed:ag)
address
==
:: [%configure-keys encrypt=@ auth=@ crypto-suite=@ breach=?]
::
;~ (glue ace)
(perk %configure-keys ~)
address
address
dem
;~(pose (cold & (just 'y')) (cold | (just 'n')))
==
:: [?([%escape %cancel-escape %adopt %reject %detach]) ship]
::
;~((glue ace) sponsorship ;~(pfix sig fed:ag))
:: $: ?([%set-management-proxy %set-spawn-proxy %set-transfer-proxy])
:: address
:: ==
::
;~((glue ace) ownership address)
==
==
--
::
++ tab-list
|= sole-id=@ta
^- (list [@t tank])
:~ ['txs' leaf+"list available L2 transaction"]
['submit' leaf+"sends| a L2 transaction to the Roller"]
['cancel' leaf+"cancels a (pending) L2 transaction"]
['history' leaf+"shows all current submitted transactions"]
['track' leaf+"loads an ethereum address and tracks points and L2 txs"]
==
::
++ on-command
|= [sole-id=@ta =command]
^- (quip card _this)
|^
?+ -.command !!
%track (track +.command)
%submit (submit +.command)
%history (history +.command)
%ships (ships +.command)
%example-flow example-flow
==
::
++ example-flow
^- (quip card _this)
=/ address=@t '0x6deffb0cafdb11d175f123f6891aa64f01c24f7d '
=/ spawn=@t '0xf48062ae8bafd6ef19cd6cb89db93a0d0ca6ce26'
=/ track=@t 'track 0x6deffb0cafdb11d175f123f6891aa64f01c24f7d'
=/ ships=@t 'ships 0x6deffb0cafdb11d175f123f6891aa64f01c24f7d'
=/ tx1=@t
%- crip
:~ 'submit '
address
'[~wanzod own] '
'set-spawn-proxy '
address
==
=/ tx2=@t
%- crip
:~ 'submit '
address
'[~wanzod own] '
'spawn '
'~modlep-fosreg '
spawn
==
=/ failed-tx=@t
%- crip
:~ 'submit '
'0x6deffb0cafdb11d175f123f6891aa64f01c24f7d '
'[~wanzod own] '
'spawn '
'~marzod '
'0xf'
==
=/ example-a=@t '- lists ships controlled by the given address :: '
=/ example-b=@t '- receives updates signed by the given address :: '
=/ example-c=@t '- this tx will fail :: '
:_ this
:_ ~
^- card
:- %shoe
^- [(list _sole-id) shoe-effect:shoe]
:- [sole-id]~
^- shoe-effect:shoe
:- %sole
?. =(src our):bowl
[%txt "1234"]
:- %mor
:~ [%klr ~[[[~ ~ `%g] [example-a]~] [``~ [ships]~]]]
[%klr ~[[[~ ~ `%b] [example-b]~] [``~ [track]~]]]
[%klr ~[[[~ ~ `%r] [example-c]~] [``~ [failed-tx]~]]]
==
::
++ submit
|= [=address:ethereum =tx:naive]
^- (quip card _this)
=/ owner=(unit [=nonce:naive =point:naive])
=/ points=(list [=ship =point:naive])
~(tap in (~(get ju points) address))
|- ^- (unit [nonce:naive point:naive])
?~ points ~
?. =(ship.from.tx ship.i.points)
$(points t.points)
`(get-owner point.i.points proxy.from.tx)
:: =< `[nonce point.i.points]
:: (proxy-from-point:naive proxy.from.tx point.i.points)
?~ owner ~& "empty points" [~ this]
=/ =keccak
%- hash-tx:lib
(unsigned-tx:lib 1.337 nonce.u.owner (gen-tx-octs:lib tx))
=/ sig=octs (fake-sig tx address nonce.u.owner)
=. points
%+ ~(put ju points) address
[ship.from.tx point.u.owner]
:_ this
:_ ~
:* %pass
/pokepath
%agent
[our.bowl %roller]
%poke
roller-action+!>([%submit | address q.sig %don tx])
==
::
++ track
|= =address:ethereum
^- (quip card _this)
=/ [to=(list _sole-id) fec=shoe-effect:shoe]
:- [sole-id]~
:- %sole
=/ =tape "Listening to updates for {(scow %ux address)}"
?. =(src our):bowl
[%txt tape]
[%klr [[`%br ~ `%g] [(crip tape)]~]~]
:: :_ this(keys (snoc keys address))
:_ this
:~ [%shoe to fec]
:^ %pass /points/[(scot %ux address)] %agent
[[our.bowl %roller] %watch /points/[(scot %ux address)]]
::
:^ %pass /txs/[(scot %ux address)] %agent
[[our.bowl %roller] %watch /txs/[(scot %ux address)]]
==
::
++ history
|= =address:ethereum
^- (quip card _this)
:_ this
=; [to=(list _sole-id) fec=shoe-effect:shoe]
[%shoe to fec]~
:- [sole-id]~
:^ %table
:: ~[t+'address' t+'signing ship' t+'type' t+'status' t+'hash']
~[t+'signing ship' t+'type' t+'status' t+'hash']
~[14 20 9 13]
%+ turn ~(tap in (~(get ju history.state) address))
|= roller-tx
|^ ~[p+ship t+type t+status pack-hash]
::
++ pack-address
=+ addr=(scow %ux address)
=+ len=(lent addr)
:- %t
%- crip
;: weld
(swag [0 6] addr)
"..."
(swag [(sub len 4) len] addr)
==
::
++ pack-hash
=+ hash=(scow %ux hash)
=+ len=(lent hash)
:- %t
%- crip
;: weld
(swag [0 6] hash)
"..."
(swag [(sub len 4) len] hash)
==
--
::
++ ships
|= =address:ethereum
^- (quip card _this)
~& ships+(turn ~(tap in (~(get ju points) address)) head)
[~ this]
--
::
++ can-connect
|= sole-id=@ta
^- ?
?| =(~zod src.bowl)
(team:title [our src]:bowl)
==
::
++ on-connect on-connect:des
++ on-disconnect on-disconnect:des
--

View File

@ -83,7 +83,7 @@
?~ data ~
:_ $(data t.data)
^- card
[%pass / %agent [our.bowl %aggregator] %poke i.data]
[%pass / %agent [our.bowl %roller] %poke i.data]
--
--
::
@ -170,21 +170,21 @@
|= =ship
.^ (unit point:naive)
%gx
(~(scry agentio bowl) %aggregator /point/(scot %p ship)/noun)
(~(scry agentio bowl) %roller /point/(scot %p ship)/noun)
==
::
++ points
|= =address:naive
.^ (list ship)
%gx
(~(scry agentio bowl) %aggregator /points/(scot %ux address)/noun)
(~(scry agentio bowl) %roller /points/(scot %ux address)/noun)
==
::
++ spawned
|= =ship
.^ (list [@p @ux])
%gx
(~(scry agentio bowl) %aggregator /spawned/(scot %p ship)/noun)
(~(scry agentio bowl) %roller /spawned/(scot %p ship)/noun)
==
::
++ pending
@ -192,21 +192,21 @@
++ all
.^ (list pend-tx)
%gx
(~(scry agentio bowl) %aggregator /pending/noun)
(~(scry agentio bowl) %roller /pending/noun)
==
::
++ ship
|= =^ship
.^ (list pend-tx)
%gx
(~(scry agentio bowl) %aggregator /pending/(scot %p ship)/noun)
(~(scry agentio bowl) %roller /pending/(scot %p ship)/noun)
==
::
++ addr
|= =address:naive
.^ (list pend-tx)
%gx
%+ ~(scry agentio bowl) %aggregator
%+ ~(scry agentio bowl) %roller
/pending/[(scot %ux address)]/noun
==
--
@ -217,7 +217,7 @@
|= =address:naive
.^ (list roller-tx)
%gx
(~(scry agentio bowl) %aggregator /history/(scot %ux address)/noun)
(~(scry agentio bowl) %roller /history/(scot %ux address)/noun)
==
--
::
@ -225,13 +225,13 @@
|= keccak=@ux
.^ ^tx-status
%gx
(~(scry agentio bowl) %aggregator /tx/(scot %ux keccak)/status/noun)
(~(scry agentio bowl) %roller /tx/(scot %ux keccak)/status/noun)
==
::
++ next-batch
.^ time
%gx
(~(scry agentio bowl) %aggregator /next-batch/noun)
(~(scry agentio bowl) %roller /next-batch/noun)
==
::
++ nonce
@ -239,7 +239,7 @@
.^ (unit @)
%gx
%+ ~(scry agentio bowl)
%aggregator
%roller
/nonce/(scot %p ship)/[proxy]/noun
==
::
@ -247,7 +247,7 @@
.^ roller-config
%gx
%+ ~(scry agentio bowl)
%aggregator
%roller
/config/noun
==
::
@ -255,7 +255,7 @@
.^ @
%gx
%+ ~(scry agentio bowl)
%aggregator
%roller
/chain-id/noun
==
--

View File

@ -36,7 +36,6 @@
:: sending: the l2 txs currently sending/awaiting l2 confirmation
:: finding: raw-tx-hash reverse lookup for sending map
:: history: status of l2 txs by ethereum address
:: transfers: index that keeps track of transfer-proxy changes
:: next-nonce: next l1 nonce to use
:: next-batch: when then next l2 batch will be sent
:: pre: predicted l2 state
@ -52,7 +51,6 @@
::
finding=(map keccak ?(%confirmed %failed l1-tx-pointer))
history=(jug address:ethereum roller-tx)
transfers=(map ship address:ethereum)
next-nonce=(unit @ud)
next-batch=time
pre=^state:naive
@ -297,8 +295,9 @@
[%predict ~]
?+ +<.sign-arvo (on-arvo:def wire sign-arvo)
%wake
=. state (predicted-state canonical-state):do
`this(derive-p &)
=^ effects state
(predicted-state canonical-state):do
[(emit effects) this(derive-p &)]
==
::
[%owners ~]
@ -321,7 +320,38 @@
::TODO if crashed during timer, set new timer? how to detect?
(on-fail:def term tang)
::
++ on-watch on-watch:def
++ on-watch
|= =path
^- (quip card _this)
:_ this
|^
?+ path (on-watch:def path)
[%txs @ ~] [%give %fact ~ (give-txs i.t.path)]~
[%points @ ~] [%give %fact ~ (give-points i.t.path)]~
==
::
++ give-points
|= wat=@t
^- cage
:- %points
!> ^- (list [ship point:naive])
?~ addr=(slaw %ux wat) ~
%+ roll
~(tap in (~(get ju own) u.addr))
|= [=ship points=(list [ship point:naive])]
%+ snoc points
[ship (need (get:orm:naive points.pre ship))]
::
++ give-txs
|= wat=@t
^- cage
:- %txs
!> ^- (list roller-tx)
?~ addr=(slaw %ux wat) ~
%~ tap in
(~(get ju history) u.addr)
--
::
++ on-leave on-leave:def
++ on-agent
|= [=wire =sign:agent:gall]
@ -397,8 +427,9 @@
:: cache naive and ownership state
::
=^ nas own.state !<(init q.cage.sign)
=. state (predicted-state:do nas)
`this
=^ effects state
(predicted-state:do nas)
[(emit effects) this]
==
==
::
@ -469,6 +500,21 @@
[%pass path %agent [our.bowl %spider] %leave ~]
--
::
::
++ emit
|= updates=(list update)
|- ^- (list card)
?~ updates ~
=* up i.updates
=/ address=@t (scot %ux address.up)
:_ $(updates t.updates)
^- card
:+ %give %fact
?- -.i.updates
%tx [~[/txs/[address]] tx+!>(roller-tx.up)]
%point [~[/points/[address]] point+!>([ship point]:up)]
==
::
++ part-tx-to-full
|= =part-tx
^- [octs tx:naive]
@ -511,11 +557,16 @@
::
++ predicted-state
|= nas=^state:naive
^+ state
=. pre.state nas
^- (quip update _state)
=. pre.state nas
:: recreate ownership based on succesful txs
::
|^
=^ nes state apply-sending
=^ nep state apply-pending
=^ [nes=_sending ups-1=(list update)]
state apply-sending
=^ [nep=_pending ups-2=(list update)]
state apply-pending
:- (welp ups-1 ups-2)
state(sending nes, pending nep)
::
++ apply-pending
@ -523,31 +574,32 @@
::
++ apply-sending
=| valid=_sending
=| ups=(list update)
=+ sending=~(tap by sending)
|- ^+ [valid state]
?~ sending [valid state]
|- ^+ [[valid ups] state]
?~ sending [[valid ups] state]
::
=* key p.i.sending
=* val q.i.sending
=^ new-valid state
%+ apply-txs
(turn txs.val |=(=raw-tx:naive [| 0x0 raw-tx]))
%sending
=+ txs=(turn txs.val |=(=raw-tx:naive [| 0x0 raw-tx]))
=^ [new-valid=_txs nups=_ups] state
(apply-txs txs %sending)
=. valid
%+ ~(put by valid) key
val(txs (turn new-valid (cork tail tail)))
$(sending t.sending)
$(sending t.sending, ups (welp ups nups))
::
++ apply-txs
|= [txs=(list pend-tx) type=?(%pending %sending)]
=/ valid=_txs ~
=| ups=(list update)
:: =| local=(set keccak)
|- ^+ [valid state]
?~ txs [valid state]
|- ^+ [[valid ups] state]
?~ txs [[valid ups] state]
::
=* tx i.txs
=* raw-tx raw-tx.i.txs
=* ship ship.from.tx.raw-tx.i.txs
=* tx i.txs
=* raw-tx raw-tx.i.txs
=* ship ship.from.tx.raw-tx.i.txs
=/ hash=@ux (hash-raw-tx:lib raw-tx)
:: TODO: add tests to validate if this is necessary
::
@ -557,29 +609,33 @@
:: $(txs t.txs)
=/ sign-address=(unit @ux)
(extract-address:lib raw-tx pre.state chain-id)
=^ gud=? state
=^ [gud=? nups=_ups] state
(try-apply pre.state force.tx raw-tx)
:: TODO: only replace address if !=(address.tx sign-address)?
::
=? tx &(gud ?=(^ sign-address))
tx(address u.sign-address)
::
=/ =roller-tx
[ship type hash (l2-tx +<.tx.raw-tx)]
=? nups !gud
%+ snoc nups
[%tx address.tx roller-tx(status %failed)]
=? valid gud (snoc valid tx)
=? finding.state !gud
(~(put by finding.state) [hash %failed])
=? history.state !gud
=/ =roller-tx
[ship type hash (l2-tx +<.tx.raw-tx)]
%. [address.tx roller-tx(status %failed)]
~(put ju (~(del ju history.state) address.tx roller-tx))
:: $(txs t.txs, local (~(put in local) hash))
$(txs t.txs)
$(txs t.txs, ups (weld ups nups))
::
++ try-apply
|= [nas=^state:naive force=? =raw-tx:naive]
^- [? _state]
=/ [success=? predicted=_nas owners=_own]
^- [[? ups=(list update)] _state]
=/ [success=? predicted=_nas ups=(list update) owners=_own]
(apply-raw-tx:dice force raw-tx nas own chain-id)
:- success
:- [success ups]
state(pre predicted, own owners)
--
::
@ -684,15 +740,20 @@
:: =? pending not-sent
=. pending (snoc pending [force address raw-tx])
:: =? history not-sent
=. history
%+ ~(put ju history) address
[ship.from.tx.raw-tx %pending hash (l2-tx +<.tx.raw-tx)]
=? transfers =(%transfer-point (l2-tx +<.tx.raw-tx))
(~(put by transfers) ship.from.tx.raw-tx address)
=^ update-cards history
=/ =roller-tx
:* ship.from.tx.raw-tx
%pending
hash
(l2-tx +<.tx.raw-tx)
==
:- [%tx address roller-tx]~
(~(put ju history) [address roller-tx])
:: ?. not-sent ~& "skip" [~ state]
:: toggle flush flag
::
:_ state(derive-p ?:(derive-p | derive-p))
%+ weld (emit update-cards)
?. derive-p ~
:: derive predicted state in 5m.
::
@ -707,12 +768,15 @@
::
++ on-timer
^- (quip card _state)
=. state (predicted-state canonical-state)
=^ updates-1 state
(predicted-state canonical-state)
=^ cards state
?: =(~ pending) [~ state]
?: =(~ pending)
[(emit updates-1) state]
?~ next-nonce
~&([dap.bowl %no-nonce] [~ state])
=/ nonce=@ud u.next-nonce
=^ updates-2 history update-history
=: pending ~
derive-p &
next-nonce `+(u.next-nonce)
@ -727,22 +791,29 @@
%+ turn pending
|= pend-tx
(hash-raw-tx:lib raw-tx)^[address nonce]
::
history
%+ roll pending
|= [pend-tx hist=_history]
=/ tx=roller-tx
:^ ship.from.tx.raw-tx
%pending
(hash-raw-tx:lib raw-tx)
(l2-tx +<.tx.raw-tx)
%+ ~(put ju (~(del ju hist) address tx))
address
tx(status %sending)
==
[(send-roll get-address nonce) state]
:_ state
;: welp
(emit updates-1)
(emit updates-2)
(send-roll get-address nonce)
==
=^ card next-batch set-timer
[[card cards] state]
::
++ update-history
%+ roll pending
|= [pend-tx ups=(list update) his=_history]
=/ =roller-tx
:* ship.from.tx.raw-tx
%pending
(hash-raw-tx:lib raw-tx)
(l2-tx +<.tx.raw-tx)
==
=+ tx=[address roller-tx(status %sending)]
:- (snoc ups tx+tx)
%. tx
~(put ju (~(del ju his) address roller-tx))
:: +get-nonce: retrieves the latest nonce
::
++ get-nonce
@ -811,6 +882,7 @@
[~ state]
=/ =keccak (hash-raw-tx:lib raw-tx.diff)
?~ wer=(~(get by finding) keccak)
~& "keccak not in finding"
[~ state]
:: if we had already seen the tx, no-op
::
@ -818,8 +890,11 @@
~? &(?=(%confirmed u.wer) ?=(~ err.diff))
[dap.bowl %weird-double-confirm from.tx.raw-tx.diff]
[~ state]
=* nonce nonce.u.wer
=* ship ship.from.tx.raw-tx.diff
=* nonce nonce.u.wer
=* address address.u.wer
=* ship ship.from.tx.raw-tx.diff
=* tx tx.raw-tx.diff
=/ l2-tx (l2-tx +<.tx)
:: remove the tx from the sending map
::
=. sending
@ -844,23 +919,17 @@
:: ~? !forced [dap.bowl %aggregated-tx-failed-anyway err.diff]
%failed
::
=. history
=/ l2-tx (l2-tx +<.tx.raw-tx.diff)
=/ tx=roller-tx [ship %sending keccak l2-tx]
?~ addr=(get-l1-address tx.raw-tx.diff pre)
history
=/ =address:ethereum
?. =(%transfer-point l2-tx)
u.addr
:: TODO: delete this ship from the transfer?
::
(~(got by transfers) ship)
%+ ~(put ju (~(del ju history) address tx))
address
%_ tx
status ?~(err.diff %confirmed %failed)
==
=^ updates history
=/ =roller-tx [ship %sending keccak l2-tx]
=. history
(~(del ju history) address roller-tx)
=. status.roller-tx
?~(err.diff %confirmed %failed)
:- [%tx address roller-tx]~
(~(put ju history) [address roller-tx])
::
:_ state(derive-p ?:(derive-p | derive-p))
%+ weld (emit updates)
?. derive-p ~
:: derive predicted state in 5m.
::

View File

@ -444,7 +444,7 @@
[~ ~(parse error:json-rpc id)]
:_ [%result id s+'ok']
%- some
aggregator-action+!>([%cancel u.sig u.keccak u.data])
roller-action+!>([%cancel u.sig u.keccak u.data])
::
++ get-spawned
|= [id=@t params=(map @t json) scry=$-(ship (list [ship @ux]))]
@ -473,7 +473,7 @@
=+ (gen-tx-octs:lib u.tx)
:_ [%result id (hex:to-json 32 (hash-tx:lib p q))]
%- some
aggregator-action+!>([%submit | u.addr u.sig %don u.tx])
roller-action+!>([%submit | u.addr u.sig %don u.tx])
::
++ nonce
|= [id=@t params=(map @t json) scry=$-([ship proxy:naive] (unit @))]

View File

@ -16,17 +16,17 @@
::
++ apply-raw-tx
|= [force=? =raw-tx:naive nas=^state:naive own=owners chain-t=@]
^- [? nas=_nas own=_own]
^- [? nas=_nas ups=(list update) own=_own]
=+ cache-nas=nas
=/ chain-t=@t (ud-to-ascii:naive chain-t)
?. (verify-sig-and-nonce:naive verifier chain-t nas raw-tx)
~& [%verify-sig-and-nonce %failed tx.raw-tx]
[force nas own]
[force nas ~ own]
=^ * points.nas
(increment-nonce:naive nas from.tx.raw-tx)
?~ nex=(receive-tx:naive nas tx.raw-tx)
~& [%receive-tx %failed]
[force ?:(force nas cache-nas) own]
[force ?:(force nas cache-nas) ~ own]
=* new-nas +.u.nex
=* effects -.u.nex
:+ &
@ -39,35 +39,64 @@
nas=^state:naive
=owners
==
^+ owners
^- (quip update _owners)
%+ roll effects
|= [=diff:naive owners=_owners]
|= [=diff:naive ups=(list update) owners=_owners]
=, orm:naive
?. ?=([%point *] diff) owners
?. ?=([%point *] diff) [ups owners]
=* ship ship.diff
=/ old=(unit point:naive)
(get points.cache-nas ship.diff)
(get points.cache-nas ship)
=/ new=point:naive
(need (get points.nas ship.diff))
(need (get points.nas ship))
=* event +>.diff
=; [to=@ux from=@ux]
=? owners !=(from 0x0)
(~(del ju owners) from ship.diff)
?: =(to 0x0) owners
(~(put ju owners) to ship.diff)
?+ -.event [0x0 0x0]
=; [to=(unit @ux) from=(unit @ux)]
=? owners ?=(^ from)
(~(del ju owners) u.from ship)
?~ to [ups owners]
:- (snoc ups [%point u.to ship new])
(~(put ju owners) u.to ship)
?+ -.event [~ ~]
%owner
[+.event ?~(old 0x0 address.owner.own.u.old)]
[`+.event ?~(old ~ `address.owner.own.u.old)]
::
%spawn-proxy
[+.event ?~(old 0x0 address.spawn-proxy.own.u.old)]
[`+.event ?~(old ~ `address.spawn-proxy.own.u.old)]
::
%management-proxy
[+.event ?~(old 0x0 address.management-proxy.own.u.old)]
[`+.event ?~(old ~ `address.management-proxy.own.u.old)]
::
%voting-proxy
[+.event ?~(old 0x0 address.voting-proxy.own.u.old)]
[`+.event ?~(old ~ `address.voting-proxy.own.u.old)]
::
%transfer-proxy
[+.event ?~(old 0x0 address.transfer-proxy.own.u.old)]
[`+.event ?~(old ~ `address.transfer-proxy.own.u.old)]
==
::
++ get-owner
|= [=point:naive =proxy:naive]
^- [nonce=@ _point]
=* own own.point
?- proxy
%own
:- nonce.owner.own
point(nonce.owner.own +(nonce.owner.own))
::
%spawn
:- nonce.spawn-proxy.own
point(nonce.spawn-proxy.own +(nonce.spawn-proxy.own))
::
%manage
:- nonce.management-proxy.own
point(nonce.management-proxy.own +(nonce.management-proxy.own))
::
%vote
:- nonce.voting-proxy.own
point(nonce.voting-proxy.own +(nonce.voting-proxy.own))
::
%transfer
:- nonce.transfer-proxy.own
point(nonce.transfer-proxy.own +(nonce.transfer-proxy.own))
==
::
--

View File

@ -0,0 +1,75 @@
/- *dice
/+ naive, lib=naive-transactions
::
:: Addresses derived from mnemonic:
::
:: benefit crew supreme gesture quantum web
:: media hazard theory mercy wing kitten
::
:: Available Accounts
:: ==================
:: (0) 0x6deffb0cafdb11d175f123f6891aa64f01c24f7d (100 eth)
:: (1) 0xd53208cf45fc9bd7938b200bff8814a26146688f (100 eth)
:: (2) 0x7b2a2d51e4d8fac602e20a5f6907ff9fbd88e1fd (100 eth)
:: (3) 0xf48062ae8bafd6ef19cd6cb89db93a0d0ca6ce26 (100 eth)
:: (4) 0xf84a77aeb351c49dfa87e805a659d2daddff7606 (100 eth)
:: (5) 0x167e357cf8b845370d0d408f9b389b66185b7b5b (100 eth)
:: (6) 0xcbecf3abc9878f07afc851aead2d8f1c436cc71d (100 eth)
:: (7) 0x0afc0c3f4eeea500871f464ca71eef5e54a9af36 (100 eth)
:: (8) 0x6d654ef2489674d21aed428e8a4ad8ca4820f125 (100 eth)
:: (9) 0x218f6f87683db546ad47a5dc8b480e5a9b694866 (100 eth)
:: private keys
:: ==================
:: (0) 0xa44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3
:: (1) 0x420b20f3538f7ddf4527770acbd33ed8aa858ba24eec5038bd22158f23a8a002
:: (2) 0x655eae6e301ebe9da6384f717f774f6addb165606a6990ce13e86ead710fff8b
:: (3) 0x2480c5256d843c73cba67cc966a11a647c943a41db2fa138de4e4f16d0861a6b
:: (4) 0xd6abd8fbab1db8714f1e284c11b8621cf95d0e319b4f38c54de4247f2150f1ba
:: (5) 0x95f48754f44e6930473367a0802bdac7389e7749df2b3a6dd6e87bcbe0d0e0bc
:: (6) 0x92596e42f9ee7a47e0d8c48291c768945fede98874cc250202a1f19f12c97be3
:: (7) 0xa0ae1d77d89854a55a4abdc1300e989b1981728e8e669cfb4b4179f0af1ac389
:: (8) 0x7aec9f8027edaa2408ac5ca74b5ed929e271570a0eeed848f47bcee842902c16
:: (9) 0x58d62eb79797502bc0f66cd3e7a49d00287bff53a2734b799ef09cb746340ed0
::
|%
++ prv-from-address
|= =address:naive
^- @
?: =(address 0x6def.fb0c.afdb.11d1.75f1.23f6.891a.a64f.01c2.4f7d)
0xa44d.e241.6ee6.beb2.f323.fab4.8b43.2925.
c978.5808.d33a.6ca6.d7ba.00b4.5e93.70c3
?: =(address 0xd532.08cf.45fc.9bd7.938b.200b.ff88.14a2.6146.688f)
0x420b.20f3.538f.7ddf.4527.770a.cbd3.3ed8.
aa85.8ba2.4eec.5038.bd22.158f.23a8.a002
?: =(address 0x7b2a.2d51.e4d8.fac6.02e2.0a5f.6907.ff9f.bd88.e1fd)
0x655e.ae6e.301e.be9d.a638.4f71.7f77.4f6a.
ddb1.6560.6a69.90ce.13e8.6ead.710f.ff8b
?: =(address 0xf480.62ae.8baf.d6ef.19cd.6cb8.9db9.3a0d.0ca6.ce26)
0x2480.c525.6d84.3c73.cba6.7cc9.66a1.1a64.
7c94.3a41.db2f.a138.de4e.4f16.d086.1a6b
?: =(address 0xf84a.77ae.b351.c49d.fa87.e805.a659.d2da.ddff.7606)
0xd6ab.d8fb.ab1d.b871.4f1e.284c.11b8.621c.
f95d.0e31.9b4f.38c5.4de4.247f.2150.f1ba
?: =(address 0x167e.357c.f8b8.4537.0d0d.408f.9b38.9b66.185b.7b5b)
0x95f4.8754.f44e.6930.4733.67a0.802b.dac7.
389e.7749.df2b.3a6d.d6e8.7bcb.e0d0.e0bc
?: =(address 0xcbec.f3ab.c987.8f07.afc8.51ae.ad2d.8f1c.436c.c71d)
0x9259.6e42.f9ee.7a47.e0d8.c482.91c7.6894.
5fed.e988.74cc.2502.02a1.f19f.12c9.7be3
?: =(address 0xafc.0c3f.4eee.a500.871f.464c.a71e.ef5e.54a9.af36)
0xa0ae.1d77.d898.54a5.5a4a.bdc1.300e.989b.
1981.728e.8e66.9cfb.4b41.79f0.af1a.c389
?: =(address 0x6d65.4ef2.4896.74d2.1aed.428e.8a4a.d8ca.4820.f125)
0x7aec.9f80.27ed.aa24.08ac.5ca7.4b5e.d929.
e271.570a.0eee.d848.f47b.cee8.4290.2c16
?. =(address 0x218f.6f87.683d.b546.ad47.a5dc.8b48.0e5a.9b69.4866) !!
0x58d6.2eb7.9797.502b.c0f6.6cd3.e7a4.9d00.287b.
ff53.a273.4b79.9ef0.9cb7.4634.0ed0
::
++ fake-sig
|= [=tx:naive =address:naive =nonce:naive]
^- octs
(gen-tx:lib nonce tx (prv-from-address address))
::
--

View File

@ -42,6 +42,11 @@
%set-transfer-proxy
==
::
+$ update
$% [%point =address:ethereum =ship =point:naive]
[%tx =address:ethereum =roller-tx]
==
::
:: TODO: add submission time?
::
+$ roller-tx [=ship =status hash=keccak type=l2-tx]

View File

@ -1,4 +1,4 @@
:: aggregator/send: send rollup tx
:: roller/send: send rollup tx
::
/- rpc=json-rpc, *dice
/+ naive, ethereum, ethio, strandio
@ -17,6 +17,7 @@
:: if chain expects a different nonce, don't send this transaction
::
?. =(nonce expected-nonce)
~& [%unexpected-nonce nonce expected+expected-nonce]
not-sent
:: if a gas-price of 0 was specified, fetch the recommended one
::
@ -49,7 +50,7 @@
;< balance=@ud bind:m
(get-balance:ethio endpoint address)
?: (gth max-cost balance)
~& [%insufficient-aggregator-balance address]
~& [%insufficient-roller-balance address]
not-sent
::
::NOTE this fails the thread if sending fails, which in the app gives us