roller: add get-unspawned rpc

This commit is contained in:
yosoyubik 2021-09-01 11:01:39 +02:00
parent 71e2d12fde
commit 7c70ac954b
4 changed files with 46 additions and 17 deletions

View File

@ -152,6 +152,7 @@
%get-ships `(get-ships id +.params ships:scry)
%cancel-transaction (cancel-tx id +.params)
%get-spawned `(get-spawned id +.params spawned:scry)
%get-unspawned `(get-spawned id +.params unspawned:scry)
%get-owned-points `(get-ships id +.params owned:scry)
%get-transferring-for `(get-ships id +.params transfers:scry)
%get-manager-for `(get-ships id +.params manager:scry)
@ -187,11 +188,18 @@
::
++ spawned
|= =ship
.^ (list [@p @ux])
.^ (list @p)
%gx
(~(scry agentio bowl) %roller /spawned/(scot %p ship)/noun)
==
::
++ unspawned
|= =ship
.^ (list @p)
%gx
(~(scry agentio bowl) %roller /unspawned/(scot %p ship)/noun)
==
::
++ owned
|= =address:naive
.^ (list ship)

View File

@ -152,7 +152,8 @@
:: /x/tx/[0xke.ccak]/status -> %noun tx-status
:: /x/history/[0xadd.ress] -> %noun (list roller-tx)
:: /x/nonce/[~ship]/[proxy] -> %noun (unit @)
:: /x/spawned/[~ship] -> %noun (list [ship address])
:: /x/spawned/[~star] -> %noun (list ship)
:: /x/unspawned/[~star] -> %noun (list ship)
:: /x/next-batch -> %atom time
:: /x/point/[~ship] -> %noun point:naive
:: /x/ships/[0xadd.ress] -> %noun (list ship)
@ -175,6 +176,7 @@
[%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)
[%x %unspawned @ ~] (unspawned i.t.t.path)
[%x %next-batch ~] ``atom+!>(next-batch)
[%x %point @ ~] (point i.t.t.path)
[%x %ships @ ~] (ships i.t.t.path)
@ -251,20 +253,34 @@
|= wat=@t
:+ ~ ~
:- %noun
!> ^- (list [=^ship =address:ethereum])
!> ^- (list @p)
?~ star=(slaw %p wat) ~
=/ range
%+ lot:orm:naive points.pre
:: TODO: check this by spawning e.g. ~solled-hocweb
=; range
(turn range head)
=, orm:naive
:: range exclusive [star first-moon-last-planet]
:: TODO: make range inclusive ([first-planet last-planet])?
::
[`u.star `(cat 3 u.star 0x1.ffff)]
%+ turn (tap:orm:naive range)
|= [=ship =point:naive]
^- [=^ship =address:ethereum]
:- ship
address:(proxy-from-point:naive %own point)
%- tap
(lot points.pre [`u.star `(cat 3 u.star 0x1.ffff)])
::
++ unspawned
|= wat=@t
:+ ~ ~
:- %noun
!> ^- (list @p)
?~ star=(slaw %p wat) ~
=/ spawned=(set @p)
=; points
(~(gas in *(set @p)) (turn points head))
=, orm:naive
%- tap
(lot points.pre [`u.star `(cat 3 u.star 0x1.ffff)])
=/ children=(list @p)
(turn (gulf 0x1 0xffff) |=(a=@ (cat 3 u.star a)))
%+ murn children
|= =ship
?: (~(has in spawned) ship) ~
`ship
::
++ point
|= wat=@t
@ -835,6 +851,9 @@
~&([dap.bowl %no-nonce] [~ state])
=/ nonce=@ud u.next-nonce
=^ updates-2 history update-history
:: TODO: move to +on-batch-result to prevent the case the
:: tx succeds but we get a "Runtime Error: revert"?
::
=: pending ~
derive-p &
next-nonce `+(u.next-nonce)

View File

@ -449,13 +449,13 @@
roller-action+!>([%cancel u.sig u.keccak u.data])
::
++ get-spawned
|= [id=@t params=(map @t json) scry=$-(ship (list [ship @ux]))]
|= [id=@t params=(map @t json) scry=$-(@p (list @p))]
^- response:rpc
?. =((lent ~(tap by params)) 1)
~(params error:json-rpc id)
?~ ship=(ship:from-json params)
~(params error:json-rpc id)
[%result id (spawned:to-json (scry u.ship))]
[%result id (ships:to-json (scry u.ship))]
::
++ process-rpc
|= [id=@t params=(map @t json) action=l2-tx]

View File

@ -69,6 +69,8 @@
==
%- pure:m
!> ^- (each @ud @t)
:: TODO: capture if the tx fails (e.g. Runtime Error: revert)
::
?+ -.response %.n^'unexpected rpc response'
%error %.n^message.response
:: TODO: