Merge branch 'yu/azimuth-rpc' into naive/aggregator

This commit is contained in:
yosoyubik 2021-05-17 17:50:45 +02:00
commit 9e7cb91398
2 changed files with 207 additions and 120 deletions

View File

@ -29,7 +29,7 @@
%- agent:dbug
::
=| state-0
=* state -
=* state -
::
^- agent:gall
=<
@ -90,7 +90,7 @@
?~ data ~
:_ ~
^- card
[%pass / %agent [our.bowl %dice] %poke u.data]
[%pass / %agent [our.bowl %aggregator] %poke u.data]
:: TODO: validate that format is e.g. 'getPoint'
:: TODO: maybe use getPoint and translate to %get-point
::
@ -131,57 +131,57 @@
%- json-response:gen
(response-to-json:json-rpc response)
=, azimuth-rpc
?. ?=([%map *] params)
?. ?=([%map *] params)
[~ ~(parse error id)]
?+ method [~ ~(method error id)]
%get-point [~ (get-point id +.params point:scry)]
%transfer-point (transfer-point id +.params)
%configure-keys (configure-keys id +.params)
%spawn (spawn id +.params)
%escape (escape id +.params)
%cancel-escape (cancel-escape id +.params)
%adopt (adopt id +.params)
%detach (detach id +.params)
%reject (reject id +.params)
%set-management-proxy (management-proxy id +.params)
%set-spawn-proxy (spawn-proxy id +.params)
%set-transfer-proxy (transfer-proxy id +.params)
%escape (escape id +.params method)
%cancel-escape (cancel-escape id +.params method)
%adopt (adopt id +.params method)
%detach (detach id +.params method)
%reject (reject id +.params method)
%set-management-proxy (management-proxy id +.params method)
%set-spawn-proxy (spawn-proxy id +.params method)
%set-transfer-proxy (transfer-proxy id +.params method)
%pending [~ (all:pending id +.params all:pending:scry)]
%pending-by-ship [~ (ship:pending id +.params ship:pending:scry)]
%pending-by-address [~ (addr:pending id +.params addr:pending:scry)]
%status [~ (status id +.params tx-status:scry)]
:: %history [~ (history id +.params all:history:scry)]
%pending-by-ship [~ (ship:pending id +.params ship:pending:scry)]
%pending-by-address [~ (addr:pending id +.params addr:pending:scry)]
%status [~ (status id +.params tx-status:scry)]
:: %history [~ (history id +.params all:history:scry)]
==
::
++ scry
|%
++ point
|= =ship
.^ (unit point:naive)
%gx
.^ (unit point:naive)
%gx
(~(scry agentio bowl) %azimuth /nas/[(scot %p ship)]/noun)
==
::
++ pending
|%
++ all
.^ (list pend-tx)
%gx
(~(scry agentio bowl) %dice /pending/noun)
.^ (list pend-tx)
%gx
(~(scry agentio bowl) %aggregator /pending/noun)
==
::
++ ship
|= =^ship
.^ (list pend-tx)
%gx
(~(scry agentio bowl) %dice /pending/[(scot %p ship)]/noun)
%gx
(~(scry agentio bowl) %aggregator /pending/[(scot %p ship)]/noun)
==
::
++ addr
|= =address:naive
.^ (list pend-tx)
%gx
%+ ~(scry agentio bowl) %dice
%gx
%+ ~(scry agentio bowl) %aggregator
/pending/[(scot %ux address)]/noun
==
--
@ -192,43 +192,43 @@
:: FIXME: use proper type from aggregator/index
::
.^ (list tx:naive)
%gx
(~(scry agentio bowl) %dice /history/noun)
==
%gx
(~(scry agentio bowl) %aggregator /history/noun)
==
::
++ ship
|= =^ship
:: FIXME: use proper type from aggregator/index
::
.^ (list tx:naive)
%gx
(~(scry agentio bowl) %dice /history/[(scot %p ship)]/noun)
==
%gx
(~(scry agentio bowl) %aggregator /history/[(scot %p ship)]/noun)
==
::
++ addr
|= =address:naive
:: FIXME: use proper type from aggregator/index
::
.^ (list tx:naive)
%gx
(~(scry agentio bowl) %dice /history/[(scot %ux address)]/noun)
==
%gx
(~(scry agentio bowl) %aggregator /history/[(scot %ux address)]/noun)
==
--
::
++ tx-status
|= keccak=@ux
.^ ^tx-status
%gx
(~(scry agentio bowl) %dice /tx/[(scot %ux keccak)]/status/noun)
%gx
(~(scry agentio bowl) %aggregator /tx/[(scot %ux keccak)]/status/noun)
==
::
++ nonce
|= [=ship =address:naive]
:: FIXME: use proper type from aggregator/index
.^ @
%gx
%+ ~(scry agentio bowl)
%dice
%gx
%+ ~(scry agentio bowl)
%aggregator
/nonce/[(scot %p ship)]/[(scot %ux address)]/atom
==
--

View File

@ -6,6 +6,19 @@
=> :: Utilities
::
|%
+$ spawn-action
$? %escape
%cancel-escape
%adopt
%reject
%detach
==
::
+$ proxy-action
$? %set-management-proxy
%set-spawn-proxy
%set-transfer-proxy
==
:: FIXME: import tx-status, pend-tx from aggregator
::
+$ tx-status
@ -23,59 +36,79 @@
?~ data=(~(get by params) 'data') ~
%. u.data
=, dejs-soft:format
%- ot
%- ot
:~ ['encrypt' so]
['auth' so]
['crypto-suite' so]
['breach' bo]
==
::
++ address-transfer
|= params=(map @t json)
^- (unit [@ux ?])
?~ data=(~(get by params) 'data') ~
=; ans=(unit [add=(unit @ux) r=?])
?~ ans ~
?~ add.u.ans ~
(some [u.add.u.ans r.u.ans])
%. u.data
=, dejs-soft:format
%- ot
~[['address' (cu to-hex so)] ['reset' bo]]
++ data
|%
++ address-transfer
|= params=(map @t json)
^- (unit [@ux ?])
?~ data=(~(get by params) 'data') ~
=; ans=(unit [add=(unit @ux) r=?])
?~ ans ~
?~ add.u.ans ~
(some [u.add.u.ans r.u.ans])
%. u.data
=, dejs-soft:format
%- ot
~[['address' (cu to-hex so)] ['reset' bo]]
::
++ address-ship
|= params=(map @t json)
^- (unit [@p @ux])
?~ data=(~(get by params) 'data') ~
=; ans=(unit [ship=@p add=(unit @ux)])
?~ ans ~
?~ add.u.ans ~
(some [ship.u.ans u.add.u.ans])
%. u.data
=, dejs-soft:format
%- ot
:~ ['ship' (su ;~(pfix sig fed:ag))]
['address' (cu to-hex so)]
==
::
++ address
|= params=(map @t json)
^- (unit @ux)
?~ data=(~(get by params) 'data') ~
=; ans=(unit (unit @ux))
?~(ans ~ u.ans)
=, dejs-soft:format
%. u.data
(ot ['address' (cu to-hex so)]~)
::
++ ship
|= params=(map @t json)
^- (unit @p)
?~ data=(~(get by params) 'data') ~
=, dejs-soft:format
%. u.data
(ot ['ship' (su ;~(pfix sig fed:ag))]~)
--
::
++ address-ship
++ ship
|= params=(map @t json)
^- (unit [@ux @p])
?~ data=(~(get by params) 'data') ~
=; ans=(unit [add=(unit @ux) ship=@p])
?~ ans ~
?~ add.u.ans ~
(some [u.add.u.ans ship.u.ans])
%. u.data
^- (unit @p)
?~ data=(~(get by params) 'ship') ~
=, dejs-soft:format
%- ot
:~ ['address' (cu to-hex so)]
['ship' (su ;~(pfix sig fed:ag))]
==
%. u.data
(su ;~(pfix sig fed:ag))
::
++ address
|= params=(map @t json)
^- (unit @ux)
?~ data=(~(get by params) 'data') ~
?~ data=(~(get by params) 'address') ~
=; ans=(unit (unit @ux))
?~(ans ~ u.ans)
=, dejs-soft:format
%. u.data
(ot ['address' (cu to-hex so)]~)
::
++ ship
|= params=(map @t json)
^- (unit @p)
?~ data=(~(get by params) 'data') ~
=, dejs-soft:format
%. u.data
(ot ['ship' (su ;~(pfix sig fed:ag))]~)
::
((cu to-hex so) u.data)
::
++ sig
|= params=(map @t json)
^- (unit @)
@ -87,11 +120,11 @@
^- (unit [@p proxy:naive])
?~ from=(~(get by params) 'from') ~
=, dejs-soft:format
%. u.from
%. u.from
%- ot
:~ ['ship' (su ;~(pfix sig fed:ag))]
['proxy' (cu proxy:naive so)]
==
==
::
++ keccak
|= params=(map @t json)
@ -101,6 +134,17 @@
?~(ans ~ u.ans)
=, dejs-soft:format
((cu to-hex so) u.keccak)
::
++ raw
|= params=(map @t json)
^- (unit octs)
?~ raw=(~(get by params) 'raw') ~
=; ans=(unit (unit @ux))
?~ ans ~
?~ u.ans ~
(some (as-octs:mimes:html u.u.ans))
=, dejs-soft:format
((cu to-hex so) u.raw)
--
::
++ to-json
@ -162,7 +206,7 @@
++ en-address |=(a=@ux address+s+(crip "0x{((x-co:co 20) a)}"))
++ en-spawn |=([s=@p a=@ux] ~[(en-ship s) (en-address a)])
++ en-transfer |=([a=@ux r=?] ~[(en-address a) reset+b+r])
++ en-keys
++ en-keys
|= [encrypt=@ auth=@ crypto-suite=@ breach=?]
^- (list [@t json])
:~ ['encrypt' (numb encrypt)]
@ -184,7 +228,7 @@
%- pairs
:~ ['dominion' s+dominion.point]
::
:- 'ownership'
:- 'ownership'
%- pairs
=* own own.point
^- (list [@t json])
@ -216,16 +260,16 @@
?~ escape.net ~
['escape' (ship u.escape.net)]~
== ==
::
::
++ ownership
|= [=address:naive =nonce:naive]
^- json
=, enjs:format
=, enjs:format
%- pairs
:~ ['address' s+(crip "0x{((x-co:co 20) address)}")]
['nonce' (numb nonce)]
==
::
::
++ tx-status
|= =^tx-status
^- json
@ -233,8 +277,8 @@
%- pairs
:~ ['status' s+status.tx-status]
::
:- 'tx'
?~ tx.tx-status ~
:- 'tx'
?~ tx.tx-status ~
s+(crip "0x{((x-co:co 20) u.tx.tx-status)}")
==
--
@ -243,7 +287,7 @@
|= =cord
^- (unit @ux)
=/ parsed=(unit (pair @ud @ux)) (de:base16:mimes:html cord)
?~ parsed
?~ parsed
::~|(%non-hex-cord !!)
~
(some q.u.parsed)
@ -251,33 +295,52 @@
++ rpc-res
|%
++ sponsor
|= [id=@t params=(map @t json)]
|= [id=@t params=(map @t json) action=spawn-action]
^- [(unit cage) response:rpc]
?. =((lent ~(tap by params)) 3)
?. (params:validate params)
[~ ~(params error id)]
=/ sig=(unit @) (sig:from-json params)
=/ from=(unit [@p proxy:naive]) (from:from-json params)
=/ data=(unit [@ux @p]) (address-ship:from-json params)
?. &(?=(^ sig) ?=(^ from) ?=(^ data))
=/ raw=(unit octs) (raw:from-json params)
=/ data=(unit @p) (ship:data:from-json params)
?. &(?=(^ sig) ?=(^ from) ?=(^ raw) ?=(^ data))
[~ ~(parse error id)]
:_ [%result id s+'ok']
%- some
noun+!>([u.sig u.from u.data])
%- some
:- %aggregator-action
!>
=; =skim-tx:naive
[%submit | u.sig %ful u.raw u.from skim-tx]
?- action
%escape [%escape u.data]
%cancel-escape [%cancel-escape u.data]
%adopt [%adopt u.data]
%reject [%reject u.data]
%detach [%detach u.data]
==
::
++ proxy
|= [id=@t params=(map @t json)]
|= [id=@t params=(map @t json) action=proxy-action]
^- [(unit cage) response:rpc]
?. =((lent ~(tap by params)) 3)
?. (params:validate params)
[~ ~(params error id)]
=/ sig=(unit @) (sig:from-json params)
=/ from=(unit [@p proxy:naive]) (from:from-json params)
=/ data=(unit @ux) (address:from-json params)
?. &(?=(^ sig) ?=(^ from) ?=(^ data))
=/ raw=(unit octs) (raw:from-json params)
=/ data=(unit @ux) (address:data:from-json params)
?. &(?=(^ sig) ?=(^ from) ?=(^ raw) ?=(^ data))
[~ ~(parse error id)]
:_ [%result id s+'ok']
%- some
noun+!>([u.sig u.from u.data])
::
%- some
:- %aggregator-action
!>
=; =skim-tx:naive
[%submit | u.sig %ful u.raw u.from skim-tx]
?- action
%set-management-proxy [%set-management-proxy u.data]
%set-spawn-proxy [%set-spawn-proxy u.data]
%set-transfer-proxy [%set-transfer-proxy u.data]
==
--
::
++ error
@ -291,51 +354,75 @@
++ internal [%error id '-32603' 'Internal error']
++ not-found [%error id '-32000' 'Resource not found']
--
::
++ validate
|%
++ params
|= params=(map @t json)
^- ?
=((lent ~(tap by params)) 4)
--
--
|%
++ get-point
|= [id=@t params=(map @t json) scry=$-(ship (unit point:naive))]
^- response:rpc
?. =((lent ~(tap by params)) 1)
?. =((lent ~(tap by params)) 1)
~(params error id)
?~ ship=(~(get by params) 'ship')
?~ ship=(~(get by params) 'ship')
~(params error id)
?~ ship=(rush (so:dejs:format u.ship) ;~(pfix sig fed:ag))
~(params error id)
?~ point=(scry u.ship)
?~ point=(scry u.ship)
~(params error id)
[%result id (point:to-json u.point)]
::
++ transfer-point
|= [id=@t params=(map @t json)]
^- [(unit cage) response:rpc]
?. =((lent ~(tap by params)) 3)
?. (params:validate params)
[~ ~(params error id)]
=/ sig=(unit @) (sig:from-json params)
=/ from=(unit [ship @t]) (from:from-json params)
=/ data=(unit [@ux ?]) (address-transfer:from-json params)
?: |(?=(~ sig) ?=(~ from) ?=(~ data))
=/ raw=(unit octs) (raw:from-json params)
=/ data=(unit [@ux ?]) (address-transfer:data:from-json params)
?: |(?=(~ sig) ?=(~ from) ?=(~ raw) ?=(~ data))
[~ ~(parse error id)]
:_ [%result id s+'ok']
%- some
%- some
noun+!>([u.sig u.from u.data])
::
++ configure-keys
|= [id=@t params=(map @t json)]
^- [(unit cage) response:rpc]
?. =((lent ~(tap by params)) 3)
?. (params:validate params)
[~ ~(params error id)]
=/ sig=(unit @) (sig:from-json params)
=/ from=(unit [ship @t]) (from:from-json params)
=/ raw=(unit octs) (raw:from-json params)
=/ data=(unit [encrypt=@ auth=@ crypto-suite=@ breach=?])
(keys:from-json params)
?. &(?=(^ sig) ?=(^ from) ?=(^ data))
(keys:data:from-json params)
?. &(?=(^ sig) ?=(^ from) ?=(^ raw) ?=(^ data))
[~ ~(parse error id)]
:_ [%result id s+'ok']
%- some
%- some
noun+!>([u.sig u.from u.data])
::
++ spawn sponsor:rpc-res
++ spawn
|= [id=@t params=(map @t json)]
^- [(unit cage) response:rpc]
?. (params:validate params)
[~ ~(params error id)]
=/ sig=(unit @) (sig:from-json params)
=/ from=(unit [@p proxy:naive]) (from:from-json params)
=/ raw=(unit octs) (raw:from-json params)
=/ data=(unit [@p @ux]) (address-ship:data:from-json params)
?. &(?=(^ sig) ?=(^ from) ?=(^ raw) ?=(^ data))
[~ ~(parse error id)]
:_ [%result id s+'ok']
%- some
aggregator-action+!>([%submit | u.sig %ful u.raw u.from %spawn u.data])
::
++ escape sponsor:rpc-res
++ cancel-escape sponsor:rpc-res
++ adopt sponsor:rpc-res
@ -349,11 +436,11 @@
++ read-nonce
|= [id=@t params=(map @t json) scry=$-([ship proxy:naive] (unit @))]
^- response:rpc
?. =((lent ~(tap by params)) 3)
?. =((lent ~(tap by params)) 3)
~(params error id)
?~ from=(from:from-json params)
~(parse error id)
?~ nonce=(scry u.from)
?~ nonce=(scry u.from)
~(params error id)
[%result id (numb:enjs:format u.nonce)]
::
@ -363,10 +450,10 @@
|%
:: - readPendingRoll() -> (list pend-tx)
::
++ all
++ all
|= [id=@t params=(map @t json) pending=(list pend-tx)]
^- response:rpc
?. =((lent ~(tap by params)) 0)
?. =((lent ~(tap by params)) 0)
~(params error id)
[%result id (pending:to-json pending)]
:: - readPendingByShip(ship) -> (list pend-tx)
@ -374,7 +461,7 @@
++ ship
|= [id=@t params=(map @t json) scry=$-(@p (list pend-tx))]
^- response:rpc
?. =((lent ~(tap by params)) 1)
?. =((lent ~(tap by params)) 1)
~(params error id)
?~ ship=(ship:from-json params)
~(parse error id)
@ -384,7 +471,7 @@
++ addr
|= [id=@t params=(map @t json) scry=$-(@ux (list pend-tx))]
^- response:rpc
?. =((lent ~(tap by params)) 1)
?. =((lent ~(tap by params)) 1)
~(params error id)
?~ address=(address:from-json params)
~(parse error id)
@ -394,21 +481,21 @@
++ status
|= [id=@t params=(map @t json) scry=$-(@ tx-status)]
^- response:rpc
?. =((lent ~(tap by params)) 1)
?. =((lent ~(tap by params)) 1)
~(params error id)
?~ keccak=(keccak:from-json params)
~(parse error id)
[%result id (tx-status:to-json (scry u.keccak))]
::
:: ++ history
:: |= $: id=@t
:: params=(map @t json)
:: |= $: id=@t
:: params=(map @t json)
:: :: FIXME: use proper type from aggregator/index
:: ::
:: scry=$-([@p proxy:naive] (list tx:naive))
:: ==
:: ^- response:rpc
:: ?. =((lent ~(tap by params)) 1)
:: ?. =((lent ~(tap by params)) 1)
:: ~(params error id)
:: ?~ from=(from:from-json params)
:: ~(parse error id)