mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 16:51:42 +03:00
naive: add ownership index to /app/azimuth
This commit is contained in:
parent
8ea0ee004e
commit
5eb07edde5
@ -163,7 +163,7 @@
|
||||
|= =address:naive
|
||||
.^ (list [ship point:naive])
|
||||
%gx
|
||||
(~(scry agentio bowl) %aggregator /points/(scot %ux address)/noun)
|
||||
(~(scry agentio bowl) %azimuth /points/(scot %ux address)/noun)
|
||||
==
|
||||
::
|
||||
++ spawned
|
||||
|
@ -12,10 +12,11 @@
|
||||
=, jael
|
||||
|%
|
||||
++ app-state
|
||||
$: %2
|
||||
$: %3
|
||||
url=@ta
|
||||
whos=(set ship)
|
||||
nas=^state:naive
|
||||
own=owners
|
||||
logs=(list =event-log:rpc:ethereum)
|
||||
==
|
||||
+$ poke-data
|
||||
@ -29,6 +30,7 @@
|
||||
+$ tagged-diff [=id:block diff:naive]
|
||||
::
|
||||
+$ network ?(%mainnet %ropsten %local)
|
||||
+$ owners (jug address:naive [ship point:naive])
|
||||
--
|
||||
::
|
||||
|%
|
||||
@ -68,15 +70,43 @@
|
||||
?: =(data '0x') *@ux
|
||||
(hex-to-num:ethereum data)
|
||||
::
|
||||
++ update-ownership
|
||||
|= [=diff:naive own=owners old=(unit point:naive) new=point:naive]
|
||||
^+ own
|
||||
?. ?=([%point *] diff) own
|
||||
=* event +>.diff
|
||||
=; [to=@ux from=@ux]
|
||||
=? own !=(from 0x0)
|
||||
?> ?=(^ old)
|
||||
(~(del ju own) from [ship.diff u.old])
|
||||
?: =(to 0x0) own
|
||||
(~(put ju own) to [ship.diff new])
|
||||
?+ -.event [0x0 0x0]
|
||||
%owner
|
||||
[+.event ?~(old 0x0 address.owner.own.u.old)]
|
||||
::
|
||||
%spawn-proxy
|
||||
[+.event ?~(old 0x0 address.transfer-proxy.own.u.old)]
|
||||
::
|
||||
%management-proxy
|
||||
[+.event ?~(old 0x0 address.management-proxy.own.u.old)]
|
||||
::
|
||||
%voting-proxy
|
||||
[+.event ?~(old 0x0 address.voting-proxy.own.u.old)]
|
||||
::
|
||||
%transfer-proxy
|
||||
[+.event ?~(old 0x0 address.spawn-proxy.own.u.old)]
|
||||
==
|
||||
::
|
||||
++ run-logs
|
||||
|= [nas=^state:naive logs=(list event-log:rpc:ethereum) =network]
|
||||
^- [(list tagged-diff) ^state:naive]
|
||||
=/ [contract=@ux * chain-id=@ *] (get-network network)
|
||||
|= [state=app-state logs=(list event-log:rpc:ethereum)]
|
||||
^- [(list tagged-diff) _state]
|
||||
=/ [contract=@ux * chain-id=@ *] (get-network net)
|
||||
?~ logs
|
||||
`nas
|
||||
`state
|
||||
?~ mined.i.logs
|
||||
$(logs t.logs)
|
||||
=^ raw-effects nas
|
||||
=/ [raw-effects=effects:naive new-nas=_nas.state]
|
||||
=/ =^input:naive
|
||||
?: =(contract address.i.logs)
|
||||
=/ data (data-to-hex data.i.logs)
|
||||
@ -88,16 +118,26 @@
|
||||
[%bat u.input.u.mined.i.logs]
|
||||
=/ res
|
||||
%- mule
|
||||
|.((%*(. naive lac |) verifier chain-id nas input))
|
||||
|.((%*(. naive lac |) verifier chain-id nas.state input))
|
||||
?- -.res
|
||||
%& p.res
|
||||
%| ((slog 'naive-fail' p.res) `nas)
|
||||
%| ((slog 'naive-fail' p.res) `nas.state)
|
||||
==
|
||||
=. own.state
|
||||
%+ roll raw-effects
|
||||
|= [=diff:naive own=_own.state]
|
||||
^+ own
|
||||
=, orm:naive
|
||||
?. ?=([%point *] diff) own
|
||||
=/ old=(unit point:naive) (get points.nas.state ship.diff)
|
||||
=/ new=point:naive (need (get points.new-nas ship.diff))
|
||||
(update-ownership diff own old new)
|
||||
=. nas.state new-nas
|
||||
=/ effects-1
|
||||
=/ =id:block [block-hash block-number]:u.mined.i.logs
|
||||
(turn raw-effects |=(=diff:naive [id diff]))
|
||||
=^ effects-2 nas $(logs t.logs)
|
||||
[(welp effects-1 effects-2) nas]
|
||||
=^ effects-2 state $(logs t.logs)
|
||||
[(welp effects-1 effects-2) state]
|
||||
::
|
||||
++ to-udiffs
|
||||
|= effects=(list tagged-diff)
|
||||
@ -199,14 +239,28 @@
|
||||
- %2
|
||||
nas *^state:naive
|
||||
==
|
||||
`this(state ?>(?=(%2 -.old-state) old-state))
|
||||
=? old-state ?=(%2 -.old-state)
|
||||
%= old-state
|
||||
- %3
|
||||
own *owners
|
||||
==
|
||||
`this(state ?>(?=(%3 -.old-state) old-state))
|
||||
::
|
||||
++ app-states $%(app-state-0 app-state-1 app-state)
|
||||
++ app-states $%(app-state-0 app-state-1 app-state-2 app-state)
|
||||
++ app-state-2
|
||||
$: %2
|
||||
url=@ta
|
||||
whos=(set ship)
|
||||
nas=^state:naive
|
||||
own=*
|
||||
logs=(list =event-log:rpc:ethereum)
|
||||
==
|
||||
++ app-state-1
|
||||
$: %1
|
||||
url=@ta
|
||||
whos=(set ship)
|
||||
nas=*
|
||||
own=*
|
||||
logs=(list =event-log:rpc:ethereum)
|
||||
==
|
||||
++ app-state-0
|
||||
@ -214,6 +268,7 @@
|
||||
url=@ta
|
||||
whos=(set ship)
|
||||
nas=*
|
||||
own=*
|
||||
logs=(list =event-log-0)
|
||||
==
|
||||
::
|
||||
@ -239,7 +294,7 @@
|
||||
?+ q.vase !!
|
||||
%rerun
|
||||
~& [%rerunning (lent logs.state)]
|
||||
=^ effects nas.state (run-logs *^state:naive logs.state net)
|
||||
=^ effects state (run-logs state logs.state)
|
||||
`this
|
||||
::
|
||||
%resub
|
||||
@ -288,8 +343,17 @@
|
||||
|= =path
|
||||
^- (unit (unit cage))
|
||||
?+ path (on-peek:def path)
|
||||
[%x %logs ~] ``logs+!>(logs.state)
|
||||
[%x %nas ~] ``nas+!>(nas.state)
|
||||
[%x %logs ~] ``logs+!>(logs.state)
|
||||
[%x %nas ~] ``nas+!>(nas.state)
|
||||
[%x %points @ ~]
|
||||
=* wat i.t.t.path
|
||||
:+ ~ ~
|
||||
:- %noun
|
||||
!> ^- (list [ship point:naive])
|
||||
?~ addr=(slaw %ux wat)
|
||||
~
|
||||
%~ tap in
|
||||
(~(get ju own.state) u.addr)
|
||||
==
|
||||
::
|
||||
++ on-agent
|
||||
@ -311,9 +375,9 @@
|
||||
%logs (welp logs.state loglist.diff)
|
||||
==
|
||||
=? nas.state ?=(%history -.diff) *^state:naive
|
||||
=^ effects nas.state
|
||||
=^ effects state
|
||||
=; nas=^state:naive
|
||||
(run-logs nas loglist.diff net)
|
||||
(run-logs state(nas nas) loglist.diff)
|
||||
?- -.diff
|
||||
:: %history *^state:naive
|
||||
%history nas.state
|
||||
|
@ -176,12 +176,10 @@
|
||||
+$ state
|
||||
$: =points
|
||||
=operators
|
||||
=owners
|
||||
dns=(list @t)
|
||||
==
|
||||
+$ points (tree [ship point])
|
||||
+$ operators (jug address address)
|
||||
+$ owners (jug address [ship point])
|
||||
+$ effects (list diff)
|
||||
+$ proxy ?(%own %spawn %manage %vote %transfer)
|
||||
+$ roll (list raw-tx)
|
||||
@ -468,35 +466,6 @@
|
||||
==
|
||||
==
|
||||
==
|
||||
::
|
||||
++ 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
|
||||
@ -539,19 +508,8 @@
|
||||
=/ the-point (get-point state ship)
|
||||
?> ?=(^ the-point)
|
||||
=* point u.the-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))]
|
||||
=- [effects state(points (put:orm points.state ship new-point))]
|
||||
^- [=effects new-point=^point]
|
||||
::
|
||||
?: =(log-name changed-spawn-proxy:log-names)
|
||||
?> ?=(%l1 -.point)
|
||||
@ -738,9 +696,7 @@
|
||||
=/ res=(unit [=effects new-point=^point]) (fun u.point rest)
|
||||
?~ 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
|
||||
|= [=point to=address reset=?]
|
||||
@ -749,7 +705,6 @@
|
||||
::
|
||||
?. |(=(%own proxy.from.tx) =(%transfer proxy.from.tx))
|
||||
(debug %bad-permission ~)
|
||||
=/ previous-owner address.owner.own.point
|
||||
:: Execute transfer
|
||||
::
|
||||
=/ effects-1
|
||||
@ -757,17 +712,10 @@
|
||||
=: address.owner.own.point to
|
||||
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
|
||||
::
|
||||
?. reset
|
||||
[effects-1 point]
|
||||
`[effects-1 point]
|
||||
::
|
||||
=^ effects-2 net.point
|
||||
?: =([0 0 0] +.keys.net.point)
|
||||
@ -791,7 +739,7 @@
|
||||
address.voting-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
|
||||
|= [=ship to=address]
|
||||
@ -818,7 +766,7 @@
|
||||
?. =(+((ship-rank parent)) (ship-rank ship)) (debug %bad-rank ~)
|
||||
:: TODO check spawnlimit
|
||||
::
|
||||
=^ [=effects new-point=point] owners.state
|
||||
=/ [=effects new-point=point]
|
||||
=/ point=(unit point) (get-point state ship)
|
||||
?> ?=(^ point) :: only parsed 4 bytes
|
||||
:: If spawning to self, just do it
|
||||
@ -830,30 +778,19 @@
|
||||
=(to address.spawn-proxy.own.u.parent-point)
|
||||
==
|
||||
==
|
||||
=+ new-point=u.point(address.owner.own to)
|
||||
:: TODO: use get-point or duplicate sponsor logic
|
||||
::
|
||||
:_ (~(put ju owners.state) to [ship new-point])
|
||||
:_ new-point
|
||||
~[[%point ship %dominion %l2] [%point ship %owner to]]
|
||||
:- ~[[%point ship %dominion %l2] [%point ship %owner to]]
|
||||
u.point(address.owner.own to)
|
||||
:: Else spawn to parent and set transfer proxy
|
||||
::
|
||||
=* parent-address address.owner.own.u.parent-point
|
||||
=/ new-point
|
||||
%= 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]]
|
||||
:- :~ [%point ship %dominion %l2]
|
||||
[%point ship %owner address.owner.own.u.parent-point]
|
||||
[%point ship %transfer-proxy to]
|
||||
==
|
||||
:_ new-point
|
||||
:~ [%point ship %dominion %l2]
|
||||
[%point ship %owner parent-address]
|
||||
[%point ship %transfer-proxy to]
|
||||
%= u.point
|
||||
address.owner.own address.owner.own.u.parent-point
|
||||
address.transfer-proxy.own to
|
||||
==
|
||||
`[effects state(points (put:orm points.state ship new-point))]
|
||||
::
|
||||
@ -935,42 +872,24 @@
|
||||
|= [=point =address]
|
||||
?. |(=(%own proxy.from.tx) =(%manage proxy.from.tx))
|
||||
(debug %bad-permission ~)
|
||||
=* ship ship.from.tx
|
||||
=/ 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 ship.from.tx %management-proxy address]~
|
||||
point(address.management-proxy.own address)
|
||||
::
|
||||
++ process-set-spawn-proxy
|
||||
|= [=point =address]
|
||||
?. |(=(%own proxy.from.tx) =(%spawn proxy.from.tx))
|
||||
(debug %bad-permission ~)
|
||||
=* ship ship.from.tx
|
||||
=/ 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 ship.from.tx %spawn-proxy address]~
|
||||
point(address.spawn-proxy.own address)
|
||||
::
|
||||
++ process-set-transfer-proxy
|
||||
|= [=point =address]
|
||||
?. |(=(%own proxy.from.tx) =(%transfer proxy.from.tx))
|
||||
(debug %bad-permission ~)
|
||||
=* ship ship.from.tx
|
||||
=/ 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 ship.from.tx %transfer-proxy address]~
|
||||
point(address.transfer-proxy.own address)
|
||||
--
|
||||
--
|
||||
|
@ -759,14 +759,5 @@
|
||||
^+ a
|
||||
=+ d=(get b)
|
||||
(~(put by a) b (~(put in d) c))
|
||||
:: TODO: remove in favour of only using put?
|
||||
::
|
||||
++ gas
|
||||
|* b=(list [p=* q=*])
|
||||
=> .(b `(list _?>(?=([[* ^] ^] a) [p=p q=n.q]:n.a))`b)
|
||||
|- ^+ a
|
||||
?~ b
|
||||
a
|
||||
$(b t.b, a (put p.i.b q.i.b))
|
||||
--
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user