naive: add index of points by ethereum address

This commit is contained in:
yosoyubik 2021-06-24 16:54:23 +02:00
parent e05234c179
commit d03d710796
4 changed files with 146 additions and 25 deletions

View File

@ -16,8 +16,6 @@
:: when retrying, only do so if l2 txs remain in the "frozen" txs group. :: when retrying, only do so if l2 txs remain in the "frozen" txs group.
:: on %tx diff from naive, remove the matching tx from the frozen group. :: on %tx diff from naive, remove the matching tx from the frozen group.
:: ::
::TODO remaining general work:
::
::TODO questions: ::TODO questions:
:: - it's a bit weird how we just assume the raw and tx in raw-tx to match... :: - it's a bit weird how we just assume the raw and tx in raw-tx to match...
:: ::
@ -48,7 +46,7 @@
%+ map l1-tx-pointer %+ map l1-tx-pointer
[next-gas-price=@ud txs=(list raw-tx:naive)] [next-gas-price=@ud txs=(list raw-tx:naive)]
:: ::
finding=(map keccak $?(%confirmed %failed l1-tx-pointer)) finding=(map keccak ?(%confirmed %failed l1-tx-pointer))
history=(jug address:ethereum roller-tx) history=(jug address:ethereum roller-tx)
next-nonce=(unit @ud) next-nonce=(unit @ud)
next-batch=time next-batch=time
@ -138,6 +136,8 @@
:: /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
:: /x/point/[~ship] -> %noun point:naive
:: /x/points/[0xadd.ress] -> %noun (list [ship point:naive])
:: ::
++ on-peek ++ on-peek
|= =path |= =path
@ -152,6 +152,7 @@
[%x %spawned @ ~] (spawned i.t.t.path) [%x %spawned @ ~] (spawned i.t.t.path)
[%x %next-batch ~] ``noun+!>(next-batch) [%x %next-batch ~] ``noun+!>(next-batch)
[%x %point @ ~] (point i.t.t.path) [%x %point @ ~] (point i.t.t.path)
[%x %points @ ~] (points i.t.t.path)
== ==
:: ::
++ pending-by ++ pending-by
@ -222,8 +223,8 @@
?~ star=(slaw %p wat) ~ ?~ star=(slaw %p wat) ~
=/ range =/ range
%+ lot:orm:naive points.pre %+ lot:orm:naive points.pre
:: range exclusive [star first-planet-next-star] :: range exclusive [star next-star-first-planet-]
:: TODO: make range inclusive? [first-planet last-planet] :: TODO: make range inclusive ([first-planet last-planet])?
:: ::
[`u.star `(cat 3 +(u.star) 0x1)] [`u.star `(cat 3 +(u.star) 0x1)]
%+ turn (tap:orm:naive range) %+ turn (tap:orm:naive range)
@ -237,6 +238,16 @@
?~ ship=(rush wat ;~(pfix sig fed:ag)) ?~ ship=(rush wat ;~(pfix sig fed:ag))
``noun+!>(*(unit point:naive)) ``noun+!>(*(unit point:naive))
``noun+!>((get:orm:naive points.pre u.ship)) ``noun+!>((get:orm:naive points.pre u.ship))
::
++ points
|= wat=@t
:+ ~ ~
:- %noun
!> ^- (list [ship point:naive])
?~ addr=(slaw %ux wat)
~
%~ tap in
(~(get ju owners.pre) u.addr)
-- --
:: ::
++ on-arvo ++ on-arvo

View File

@ -127,6 +127,7 @@
[~ ~(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-points [~ (get-points id +.params points:scry)]
%transfer-point (transfer-point id +.params) %transfer-point (transfer-point id +.params)
%cancel-tx (cancel-tx id +.params) %cancel-tx (cancel-tx id +.params)
%get-spawned [~ (get-spawned id +.params spawned:scry)] %get-spawned [~ (get-spawned id +.params spawned:scry)]
@ -158,6 +159,13 @@
(~(scry agentio bowl) %aggregator /point/(scot %p ship)/noun) (~(scry agentio bowl) %aggregator /point/(scot %p ship)/noun)
== ==
:: ::
++ points
|= =address:naive
.^ (list [ship point:naive])
%gx
(~(scry agentio bowl) %aggregator /points/(scot %ux address)/noun)
==
::
++ spawned ++ spawned
|= =ship |= =ship
.^ (list [@p @ux]) .^ (list [@p @ux])

View File

@ -259,6 +259,17 @@
['escape' (ship u.escape.net)]~ ['escape' (ship u.escape.net)]~
== == == ==
:: ::
++ points
|= points=(list [@p point:naive])
^- json
:- %a
%+ turn points
|= [ship=@p =point:naive]
%- pairs
:~ ['ship' (^ship ship)]
['point' (^point point)]
==
::
++ ownership ++ ownership
|= [=address:naive =nonce:naive] |= [=address:naive =nonce:naive]
^- json ^- json
@ -369,6 +380,16 @@
~(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-points
|= [id=@t params=(map @t json) scry=$-(@ux (list [@p point:naive]))]
^- response:rpc
~& ~(wyt by params)
?. =(~(wyt by params) 1)
~(params error:json-rpc id)
?~ address=(address:from-json params)
~(parse error:json-rpc id)
[%result id (points:to-json (scry u.address))]
::
++ transfer-point ++ transfer-point
|= [id=@t params=(map @t json)] |= [id=@t params=(map @t json)]
^- [(unit cage) response:rpc] ^- [(unit cage) response:rpc]

View File

@ -176,10 +176,12 @@
+$ state +$ state
$: =points $: =points
=operators =operators
=owners
dns=(list @t) dns=(list @t)
== ==
+$ points (tree [ship point]) +$ points (tree [ship point])
+$ operators (jug address address) +$ operators (jug address address)
+$ owners (jug address [ship point])
+$ effects (list diff) +$ effects (list diff)
+$ proxy ?(%own %spawn %manage %vote %transfer) +$ proxy ?(%own %spawn %manage %vote %transfer)
+$ roll (list raw-tx) +$ roll (list raw-tx)
@ -466,6 +468,35 @@
== ==
== ==
== ==
::
++ is-ownership-log
|= log=@ux
^- ?
=, log-names
?| =(log owner-changed)
=(log changed-transfer-proxy)
=(log changed-management-proxy)
=(log changed-voting-proxy)
=(log changed-spawn-proxy)
==
::
++ address-from-log
|= [log=@ux point]
^- (unit address)
=, log-names
?: =(log owner-changed)
`address.owner.own
?: =(log changed-transfer-proxy)
`address.transfer-proxy.own
?: =(log changed-management-proxy)
`address.management-proxy.own
?: =(log changed-voting-proxy)
`address.voting-proxy.own
?. =(log changed-spawn-proxy)
:: TODO: better way to handle this?
::
~>(%slog.[0 %unknown-log] ~)
`address.spawn-proxy.own
-- => -- =>
|% |%
:: Receive log from L1 transaction :: Receive log from L1 transaction
@ -508,8 +539,19 @@
=/ the-point (get-point state ship) =/ the-point (get-point state ship)
?> ?=(^ the-point) ?> ?=(^ the-point)
=* point u.the-point =* point u.the-point
=- [effects state(points (put:orm points.state ship new-point))] =; [=effects new-point=^point]
^- [=effects new-point=^point] =? owners.state (is-ownership-log log-name)
?> ?=([@ ~] t.t.topics.log)
=* to i.t.t.topics.log
?~ address=(address-from-log log-name new-point)
owners.state
?: =(deposit-address to)
(~(put ju owners.state) u.address [ship new-point])
:: remove point from previous owner and add it to new one
::
%. [to ship new-point]
~(put ju (~(del ju owners.state) u.address [ship point]))
[effects state(points (put:orm points.state ship new-point))]
:: ::
?: =(log-name changed-spawn-proxy:log-names) ?: =(log-name changed-spawn-proxy:log-names)
?> ?=(%l1 -.point) ?> ?=(%l1 -.point)
@ -696,7 +738,9 @@
=/ res=(unit [=effects new-point=^point]) (fun u.point rest) =/ res=(unit [=effects new-point=^point]) (fun u.point rest)
?~ res ?~ res
~ ~
`[effects.u.res state(points (put:orm points.state ship new-point.u.res))] :- ~
:- effects.u.res
state(points (put:orm points.state ship new-point.u.res))
:: ::
++ process-transfer-point ++ process-transfer-point
|= [=point to=address reset=?] |= [=point to=address reset=?]
@ -705,6 +749,7 @@
:: ::
?. |(=(%own proxy.from.tx) =(%transfer proxy.from.tx)) ?. |(=(%own proxy.from.tx) =(%transfer proxy.from.tx))
(debug %bad-permission ~) (debug %bad-permission ~)
=/ previous-owner address.owner.own.point
:: Execute transfer :: Execute transfer
:: ::
=/ effects-1 =/ effects-1
@ -712,10 +757,17 @@
=: address.owner.own.point to =: address.owner.own.point to
address.transfer-proxy.own.point *address address.transfer-proxy.own.point *address
== ==
=; [=effects new-point=^point]
=. owners.state
:: remove point from previous owner and add it to new one
::
%. [to ship new-point]
~(put ju (~(del ju owners.state) previous-owner [ship point]))
`[effects point]
:: Execute reset if requested :: Execute reset if requested
:: ::
?. reset ?. reset
`[effects-1 point] [effects-1 point]
:: ::
=^ effects-2 net.point =^ effects-2 net.point
?: =([0 0 0] +.keys.net.point) ?: =([0 0 0] +.keys.net.point)
@ -739,7 +791,7 @@
address.voting-proxy.own.point *address address.voting-proxy.own.point *address
address.transfer-proxy.own.point *address address.transfer-proxy.own.point *address
== ==
`[:(welp effects-1 effects-2 effects-3 effects-4) point] [:(welp effects-1 effects-2 effects-3 effects-4) point]
:: ::
++ process-spawn ++ process-spawn
|= [=ship to=address] |= [=ship to=address]
@ -766,7 +818,7 @@
?. =(+((ship-rank parent)) (ship-rank ship)) (debug %bad-rank ~) ?. =(+((ship-rank parent)) (ship-rank ship)) (debug %bad-rank ~)
:: TODO check spawnlimit :: TODO check spawnlimit
:: ::
=/ [=effects new-point=point] =^ [=effects new-point=point] owners.state
=/ point=(unit point) (get-point state ship) =/ point=(unit point) (get-point state ship)
?> ?=(^ point) :: only parsed 4 bytes ?> ?=(^ point) :: only parsed 4 bytes
:: If spawning to self, just do it :: If spawning to self, just do it
@ -778,19 +830,30 @@
=(to address.spawn-proxy.own.u.parent-point) =(to address.spawn-proxy.own.u.parent-point)
== ==
== ==
=+ new-point=u.point(address.owner.own to)
:: TODO: use get-point or duplicate sponsor logic :: TODO: use get-point or duplicate sponsor logic
:: ::
:- ~[[%point ship %dominion %l2] [%point ship %owner to]] :_ (~(put ju owners.state) to [ship new-point])
u.point(address.owner.own to) :_ new-point
~[[%point ship %dominion %l2] [%point ship %owner to]]
:: Else spawn to parent and set transfer proxy :: Else spawn to parent and set transfer proxy
:: ::
:- :~ [%point ship %dominion %l2] =* parent-address address.owner.own.u.parent-point
[%point ship %owner address.owner.own.u.parent-point] =/ new-point
[%point ship %transfer-proxy to] %= u.point
address.owner.own parent-address
address.transfer-proxy.own to
==
:: TODO: use put instead so gas is not in /lib/std?
::
:_ %- ~(gas ju owners.state)
:~ [to [ship new-point]]
[parent-address [ship new-point]]
== ==
%= u.point :_ new-point
address.owner.own address.owner.own.u.parent-point :~ [%point ship %dominion %l2]
address.transfer-proxy.own to [%point ship %owner parent-address]
[%point ship %transfer-proxy to]
== ==
`[effects state(points (put:orm points.state ship new-point))] `[effects state(points (put:orm points.state ship new-point))]
:: ::
@ -872,24 +935,42 @@
|= [=point =address] |= [=point =address]
?. |(=(%own proxy.from.tx) =(%manage proxy.from.tx)) ?. |(=(%own proxy.from.tx) =(%manage proxy.from.tx))
(debug %bad-permission ~) (debug %bad-permission ~)
:: =* ship ship.from.tx
:+ ~ [%point ship.from.tx %management-proxy address]~ =/ previous address.management-proxy.own.point
=; [=effects new-point=^point]
=. owners.state
%. [address ship new-point]
~(put ju (~(del ju owners.state) previous [ship point]))
`[effects new-point]
:- [%point ship.from.tx %management-proxy address]~
point(address.management-proxy.own address) point(address.management-proxy.own address)
:: ::
++ process-set-spawn-proxy ++ process-set-spawn-proxy
|= [=point =address] |= [=point =address]
?. |(=(%own proxy.from.tx) =(%spawn proxy.from.tx)) ?. |(=(%own proxy.from.tx) =(%spawn proxy.from.tx))
(debug %bad-permission ~) (debug %bad-permission ~)
:: =* ship ship.from.tx
:+ ~ [%point ship.from.tx %spawn-proxy address]~ =/ previous address.spawn-proxy.own.point
=; [=effects new-point=^point]
=. owners.state
%. [address ship new-point]
~(put ju (~(del ju owners.state) previous [ship point]))
`[effects new-point]
:- [%point ship.from.tx %spawn-proxy address]~
point(address.spawn-proxy.own address) point(address.spawn-proxy.own address)
:: ::
++ process-set-transfer-proxy ++ process-set-transfer-proxy
|= [=point =address] |= [=point =address]
?. |(=(%own proxy.from.tx) =(%transfer proxy.from.tx)) ?. |(=(%own proxy.from.tx) =(%transfer proxy.from.tx))
(debug %bad-permission ~) (debug %bad-permission ~)
:: =* ship ship.from.tx
:+ ~ [%point ship.from.tx %transfer-proxy address]~ =/ previous address.transfer-proxy.own.point
=; [=effects new-point=^point]
=. owners.state
%. [address ship new-point]
~(put ju (~(del ju owners.state) previous [ship point]))
`[effects new-point]
:- [%point ship.from.tx %transfer-proxy address]~
point(address.transfer-proxy.own address) point(address.transfer-proxy.own address)
-- --
-- --