mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-01 03:23:09 +03:00
roller: add sponsorship index
This commit is contained in:
parent
856d8ed8fc
commit
e32b0a1956
@ -23,17 +23,14 @@
|
||||
::
|
||||
=, jael
|
||||
|%
|
||||
+$ versioned-state
|
||||
$% app-state
|
||||
==
|
||||
::::
|
||||
+$ app-state
|
||||
$: %0
|
||||
$: %1
|
||||
url=@ta
|
||||
=net
|
||||
whos=(set ship)
|
||||
nas=^state:naive
|
||||
own=owners
|
||||
spo=sponsors
|
||||
logs=(list =event-log:rpc:ethereum)
|
||||
==
|
||||
::
|
||||
@ -81,7 +78,27 @@
|
||||
++ on-load
|
||||
|= old=vase
|
||||
^- (quip card _this)
|
||||
`this(state !<(versioned-state old))
|
||||
|^
|
||||
=+ !<(old-state=app-states old)
|
||||
=? old-state ?=(%0 -.old-state)
|
||||
^- app-state
|
||||
=, old-state
|
||||
[%1 url net whos nas own *sponsors logs]
|
||||
?> ?=(%1 -.old-state)
|
||||
`this(state old-state)
|
||||
::
|
||||
++ app-states $%(state-0 app-state)
|
||||
::
|
||||
++ state-0
|
||||
$: %0
|
||||
url=@ta
|
||||
=net
|
||||
whos=(set ship)
|
||||
nas=^state:naive
|
||||
own=owners
|
||||
logs=(list =event-log:rpc:ethereum)
|
||||
==
|
||||
--
|
||||
::
|
||||
++ on-poke
|
||||
|= [=mark =vase]
|
||||
@ -125,6 +142,7 @@
|
||||
net.state net.poke
|
||||
url.state url.poke
|
||||
own.state ~
|
||||
spo.state ~
|
||||
logs.state ?:(?=(%default net.poke) snap ~)
|
||||
==
|
||||
%- %- slog :_ ~
|
||||
@ -139,7 +157,7 @@
|
||||
?< =(/sole/drum path)
|
||||
?: =(/event path)
|
||||
:_ this
|
||||
[%give %fact ~ %naive-state !>([nas.state own.state])]~
|
||||
[%give %fact ~ %naive-state !>([nas.state own.state spo.state])]~
|
||||
=/ who=(unit ship)
|
||||
?~ path ~
|
||||
?: ?=([@ ~] path) ~
|
||||
@ -278,22 +296,29 @@
|
||||
%& p.res
|
||||
%| ((slog 'naive-fail' p.res) `nas.state)
|
||||
==
|
||||
=. own.state
|
||||
=< own
|
||||
:: TODO: move to /lib/dice ?
|
||||
::
|
||||
=/ [new-own=_own.state new-spo=_spo.state]
|
||||
=< [own spo]
|
||||
?. =(azimuth.net address.i.logs)
|
||||
%: apply-effects:dice
|
||||
chain-id.net
|
||||
raw-effects
|
||||
nas.state
|
||||
own.state
|
||||
chain-id.net
|
||||
spo.state
|
||||
==
|
||||
%: update-ownership:dice
|
||||
%: update-indices:dice
|
||||
raw-effects
|
||||
nas.state
|
||||
new-nas
|
||||
own.state
|
||||
spo.state
|
||||
==
|
||||
=: nas.state new-nas
|
||||
own.state new-own
|
||||
spo.state new-spo
|
||||
==
|
||||
=. nas.state new-nas
|
||||
=/ effects-1
|
||||
=/ =id:block [block-hash block-number]:u.mined.i.logs
|
||||
(turn raw-effects |=(=diff:naive [id diff]))
|
||||
|
@ -157,6 +157,7 @@
|
||||
%get-spawned `(get-spawned id +.params spawned:scry)
|
||||
%get-unspawned `(get-spawned id +.params unspawned:scry)
|
||||
%spawns-remaining `(spawns-remaining id +.params unspawned:scry)
|
||||
%get-sponsored-points `(sponsored-points id +.params sponsored: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)
|
||||
@ -177,7 +178,8 @@
|
||||
%hash-raw-transaction `(hash-raw-transaction id +.params)
|
||||
:: TODO: deprecated, remove (used together with personal_sign)
|
||||
::
|
||||
%hash-transaction `(hash-transaction id +.params chain:scry | &)
|
||||
%hash-transaction ::`(hash-transaction id +.params chain:scry | &)
|
||||
`(hash-transaction id +.params chain:scry & |)
|
||||
==
|
||||
--
|
||||
::
|
||||
@ -218,6 +220,13 @@
|
||||
(~(scry agentio bowl) %roller /owned/(scot %ux address)/noun)
|
||||
==
|
||||
::
|
||||
++ sponsored
|
||||
|= parent=ship
|
||||
.^ [residents=(list ship) requests=(list ship)]
|
||||
%gx
|
||||
(~(scry agentio bowl) %roller /sponsored/(scot %p parent)/noun)
|
||||
==
|
||||
::
|
||||
++ transfers
|
||||
|= =address:naive
|
||||
.^ (list ship)
|
||||
|
@ -31,7 +31,7 @@
|
||||
::
|
||||
|%
|
||||
+$ app-state
|
||||
$: %1
|
||||
$: %2
|
||||
:: pending: the next l2 txs to be sent
|
||||
:: sending: l2 txs awaiting l2 confirmation, ordered by nonce
|
||||
:: finding: sig+raw-tx hash reverse lookup for txs in sending map
|
||||
@ -41,6 +41,7 @@
|
||||
:: next-batch: when then next l2 batch will be sent
|
||||
:: pre: predicted l2 state
|
||||
:: own: ownership of azimuth points
|
||||
:: spo: residents and escapees, per sponsor
|
||||
::
|
||||
pending=(list pend-tx)
|
||||
sending=(tree [l1-tx-pointer send-tx])
|
||||
@ -51,6 +52,7 @@
|
||||
next-batch=time
|
||||
pre=^state:naive
|
||||
own=owners
|
||||
spo=sponsors
|
||||
::
|
||||
:: pk: private key to send the roll
|
||||
:: quota: max numbers of transactions per unit of time (slice)
|
||||
@ -141,17 +143,13 @@
|
||||
=| cards=(list card)
|
||||
:: new additions to app-state
|
||||
::
|
||||
=| ship-quota=(map ship @ud)
|
||||
=/ slice=@dr ~d7
|
||||
=/ quota=@ud 7
|
||||
=/ resend-time=@dr ~m5
|
||||
=/ update-rate=@dr ~m5
|
||||
=| spo=(map ship [residents=(set ship) requests=(set ship)])
|
||||
|^
|
||||
=+ !<(old-state=app-states old)
|
||||
=? cards ?=(%0 -.old-state)
|
||||
[(set-quota:timer slice)]~
|
||||
=? old-state ?=(%0 -.old-state)
|
||||
^- app-state
|
||||
^- state-1
|
||||
=, old-state
|
||||
:* %1
|
||||
pending sending finding history
|
||||
@ -160,10 +158,20 @@
|
||||
frequency endpoint contract chain-id
|
||||
resend-time update-rate
|
||||
==
|
||||
?> ?=(%1 -.old-state)
|
||||
=? old-state ?=(%1 -.old-state)
|
||||
^- app-state
|
||||
=, old-state
|
||||
:* %2
|
||||
pending sending finding history
|
||||
ship-quota next-nonce next-batch
|
||||
pre own spo pk slice quota derive
|
||||
frequency endpoint contract chain-id
|
||||
resend-time update-rate
|
||||
==
|
||||
?> ?=(%2 -.old-state)
|
||||
[cards this(state old-state)]
|
||||
::
|
||||
++ app-states $%(state-0 app-state)
|
||||
++ app-states $%(state-0 state-1 app-state)
|
||||
++ state-0
|
||||
$: %0
|
||||
pending=(list pend-tx)
|
||||
@ -181,6 +189,29 @@
|
||||
contract=@ux
|
||||
chain-id=@
|
||||
==
|
||||
::
|
||||
++ state-1
|
||||
$: %1
|
||||
pending=(list pend-tx)
|
||||
sending=(tree [l1-tx-pointer send-tx])
|
||||
finding=(map keccak ?(%confirmed %failed [=time l1-tx-pointer]))
|
||||
history=(map address:ethereum (tree hist-tx))
|
||||
ship-quota=(map ship @ud)
|
||||
next-nonce=(unit @ud)
|
||||
next-batch=time
|
||||
pre=^state:naive
|
||||
own=owners
|
||||
pk=@
|
||||
slice=@dr
|
||||
quota=@ud
|
||||
derive=?
|
||||
frequency=@dr
|
||||
endpoint=(unit @t)
|
||||
contract=@ux
|
||||
chain-id=@
|
||||
resend-time=@dr
|
||||
update-rate=@dr
|
||||
==
|
||||
--
|
||||
::
|
||||
++ on-poke
|
||||
@ -203,6 +234,7 @@
|
||||
:: /x/nonce/[~ship]/[proxy] -> %noun (unit @)
|
||||
:: /x/spawned/[~star] -> %noun (list ship)
|
||||
:: /x/unspawned/[~star] -> %noun (list ship)
|
||||
:: /x/sponsored/[~point] -> %noun [(list ship) (list ship)]
|
||||
:: /x/next-batch -> %atom time
|
||||
:: /x/point/[~ship] -> %noun point:naive
|
||||
:: /x/ships/[0xadd.ress] -> %noun (list ship)
|
||||
@ -232,6 +264,7 @@
|
||||
[%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 %sponsored @ ~] (sponsored i.t.t.path)
|
||||
[%x %next-batch ~] ``atom+!>(next-batch)
|
||||
[%x %point @ ~] (point i.t.t.path)
|
||||
[%x %ships @ ~] (ships i.t.t.path)
|
||||
@ -358,6 +391,17 @@
|
||||
?: (~(has in spawned) ship) ~
|
||||
`ship
|
||||
::
|
||||
++ sponsored
|
||||
|= wat=@t
|
||||
:+ ~ ~
|
||||
:- %noun
|
||||
!> ^- [(list ship) (list ship)]
|
||||
?~ who=(slaw %p wat) [~ ~]
|
||||
?~ sponsor=(~(get by spo) u.who)
|
||||
[~ ~]
|
||||
:- ~(tap in residents.u.sponsor)
|
||||
~(tap in requests.u.sponsor)
|
||||
::
|
||||
++ point
|
||||
|= wat=@t
|
||||
?~ ship=(rush wat ;~(pfix sig fed:ag))
|
||||
@ -557,8 +601,10 @@
|
||||
~& > %received-azimuth-state
|
||||
:: cache naive and ownership state
|
||||
::
|
||||
=^ nas own.state
|
||||
!<([^state:naive owners] q.cage.sign)
|
||||
=+ !<([nas=^state:naive own=owners spo=sponsors] q.cage.sign)
|
||||
=: own.state own
|
||||
spo.state spo
|
||||
==
|
||||
=^ effects state
|
||||
(predicted-state:do nas)
|
||||
[(emit effects) this]
|
||||
@ -821,10 +867,10 @@
|
||||
++ try-apply
|
||||
|= [nas=^state:naive force=? =raw-tx:naive]
|
||||
^- [[? ups=(list update)] _state]
|
||||
=/ [success=? predicted=_nas ups=(list update) owners=_own]
|
||||
(apply-raw-tx:dice force raw-tx nas own chain-id)
|
||||
=/ [success=? ups=(list update) predicted=_nas owners=_own sponsors=_spo]
|
||||
(apply-raw-tx:dice force chain-id raw-tx nas own spo)
|
||||
:- [success ups]
|
||||
state(pre predicted, own owners)
|
||||
state(pre predicted, own owners, spo sponsors)
|
||||
::
|
||||
++ get-l1-address
|
||||
|= [=tx:naive nas=^state:naive]
|
||||
|
@ -343,6 +343,14 @@
|
||||
(en-address address)
|
||||
==
|
||||
::
|
||||
++ sponsored
|
||||
|= [res=(list @p) req=(list @p)]
|
||||
^- json
|
||||
%- pairs
|
||||
:~ ['residentes' (ships res)]
|
||||
['requests' (ships req)]
|
||||
==
|
||||
::
|
||||
++ tx-status |=(=^tx-status ^-(json s+status.tx-status))
|
||||
::
|
||||
++ roller-config
|
||||
@ -500,6 +508,15 @@
|
||||
~(params error:json-rpc id)
|
||||
[%result id (numb:enjs:format (lent (scry u.ship)))]
|
||||
::
|
||||
++ sponsored-points
|
||||
|= [id=@t params=(map @t json) scry=$-(@p [(list @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 (sponsored:to-json (scry u.ship))]
|
||||
::
|
||||
++ process-rpc
|
||||
|= [id=@t params=(map @t json) action=l2-tx over-quota=$-(@p ?)]
|
||||
^- [(unit cage) response:rpc]
|
||||
|
@ -9,87 +9,174 @@
|
||||
(lte nonce.a nonce.b)
|
||||
::
|
||||
++ apply-effects
|
||||
|= [=effects:naive nas=^state:naive own=owners chain-t=@]
|
||||
^+ [nas=nas own=own]
|
||||
|= [chain-t=@ =effects:naive =indices]
|
||||
^+ indices
|
||||
%+ roll effects
|
||||
|= [=diff:naive nas=_nas own=_own]
|
||||
^+ [nas own]
|
||||
?. ?=([%tx *] diff) [nas own]
|
||||
=< [nas own]
|
||||
(apply-raw-tx | raw-tx.diff nas own chain-t)
|
||||
|= [=diff:naive indices=_indices]
|
||||
?. ?=([%tx *] diff) indices::[nas own spo]
|
||||
=< indices
|
||||
(apply-raw-tx | chain-t raw-tx.diff indices)
|
||||
::
|
||||
++ apply-raw-tx
|
||||
|= [force=? =raw-tx:naive nas=^state:naive own=owners chain-t=@]
|
||||
^- [? nas=_nas ups=(list update) own=_own]
|
||||
=+ cache-nas=nas
|
||||
|= [force=? chain-t=@ =raw-tx:naive =indices]
|
||||
^- [? ups=(list update) indices=_indices]
|
||||
=+ cache-nas=nas.indices
|
||||
=/ chain-t=@t (ud-to-ascii:naive chain-t)
|
||||
?. (verify-sig-and-nonce:naive verifier chain-t nas raw-tx)
|
||||
?. (verify-sig-and-nonce:naive verifier chain-t nas.indices raw-tx)
|
||||
~& [%verify-sig-and-nonce %failed tx.raw-tx]
|
||||
[force nas ~ own]
|
||||
=^ * points.nas
|
||||
(increment-nonce:naive nas from.tx.raw-tx)
|
||||
?~ nex=(receive-tx:naive nas tx.raw-tx)
|
||||
[force ~ indices]
|
||||
=^ * points.nas.indices
|
||||
(increment-nonce:naive nas.indices from.tx.raw-tx)
|
||||
?~ nex=(receive-tx:naive nas.indices tx.raw-tx)
|
||||
~& [%receive-tx %failed]
|
||||
[force ?:(force nas cache-nas) ~ own]
|
||||
=? nas.indices !force cache-nas
|
||||
[force ~ indices]
|
||||
=* new-nas +.u.nex
|
||||
=* effects -.u.nex
|
||||
:+ &
|
||||
new-nas
|
||||
(update-ownership effects cache-nas new-nas own)
|
||||
=/ [updates=(list update) own=_own.indices spo=_spo.indices]
|
||||
(update-indices effects cache-nas new-nas [own spo]:indices)
|
||||
=: nas.indices new-nas
|
||||
own.indices own
|
||||
spo.indices spo
|
||||
==
|
||||
[& updates indices]
|
||||
::
|
||||
++ update-ownership
|
||||
++ update-indices
|
||||
|= $: =effects:naive
|
||||
cache-nas=^state:naive
|
||||
nas=^state:naive
|
||||
=owners
|
||||
=sponsors
|
||||
==
|
||||
^- (quip update own=_owners)
|
||||
^- [(list update) own=_owners spo=_sponsors]
|
||||
%+ roll effects
|
||||
|= [=diff:naive ups=(list update) owners=_owners]
|
||||
|= $: =diff:naive
|
||||
ups=(list update)
|
||||
owners=_owners
|
||||
sponsors=_sponsors
|
||||
==
|
||||
=, orm:naive
|
||||
?. ?=([%point *] diff) [ups owners]
|
||||
?. ?=([%point *] diff) [ups owners sponsors]
|
||||
=* ship ship.diff
|
||||
=/ old=(unit point:naive)
|
||||
(get points.cache-nas ship)
|
||||
=/ new=point:naive
|
||||
(need (get points.nas ship))
|
||||
=* event +>.diff
|
||||
=; [to=(unit owner) from=(unit owner)]
|
||||
=? owners &(?=(^ from) !=(address.u.from 0x0))
|
||||
(~(del ju owners) u.from ship)
|
||||
?: ?| =(~ to)
|
||||
&(?=(^ to) =(address.u.to 0x0))
|
||||
==
|
||||
[ups owners]
|
||||
?~ to [ups owners]
|
||||
:_ (~(put ju owners) u.to ship)
|
||||
(snoc ups [%point ship new u.to from])
|
||||
?+ -.event [~ ~]
|
||||
%owner
|
||||
:- `[%own +.event]
|
||||
?~ old ~
|
||||
`[%own address.owner.own.u.old]
|
||||
|^
|
||||
=^ updates owners ownership
|
||||
=+ sponsors=sponsorship
|
||||
:+ (weld ups updates)
|
||||
owners
|
||||
sponsors
|
||||
::
|
||||
%management-proxy
|
||||
:- `[%manage +.event]
|
||||
?~ old ~
|
||||
`[%manage address.management-proxy.own.u.old]
|
||||
++ sponsorship
|
||||
^+ sponsors
|
||||
?+ -.event sponsors
|
||||
%owner
|
||||
?^ old
|
||||
:: ownership change
|
||||
::
|
||||
sponsors
|
||||
:: owner event with ?=(~ old) is a spawn
|
||||
::
|
||||
=* parent who.sponsor.net.new
|
||||
?: =(parent ship) sponsors
|
||||
%+ ~(put by sponsors) parent
|
||||
?~ sponsor=(~(get by sponsors) parent)
|
||||
:_ *(set @p)
|
||||
(~(put in *(set @p)) ship)
|
||||
:_ requests.u.sponsor
|
||||
(~(put in residents.u.sponsor) ship)
|
||||
::
|
||||
%escape
|
||||
?~ old sponsors
|
||||
=* from who.sponsor.net.u.old
|
||||
=* to to.event
|
||||
=* escape escape.net.u.old
|
||||
?~ to
|
||||
:: cancel/reject escape
|
||||
::
|
||||
?~ escape sponsors
|
||||
?~ receiver=(~(get by sponsors) u.escape)
|
||||
sponsors
|
||||
%+ ~(put by sponsors) u.escape
|
||||
:- residents.u.receiver
|
||||
(~(del in requests.u.receiver) ship)
|
||||
:: normal escape
|
||||
::
|
||||
%+ ~(put by sponsors) u.to
|
||||
?~ receiver=(~(get by sponsors) u.to)
|
||||
:- *(set @pp)
|
||||
(~(put in *(set @pp)) ship)
|
||||
:- residents.u.receiver
|
||||
(~(put in requests.u.receiver) ship)
|
||||
::
|
||||
%sponsor
|
||||
?~ old sponsors
|
||||
=* from who.sponsor.net.u.old
|
||||
=* to sponsor.event
|
||||
=/ previous (~(get by sponsors) from)
|
||||
?~ to
|
||||
:: detach
|
||||
::
|
||||
?~ previous sponsors
|
||||
%+ ~(put by sponsors) from
|
||||
:_ requests.u.previous
|
||||
(~(del in residents.u.previous) ship)
|
||||
:: accepted
|
||||
::
|
||||
=/ receiver (~(get by sponsors) u.to)
|
||||
=? sponsors ?=(^ receiver)
|
||||
%+ ~(put by sponsors) u.to
|
||||
:- (~(put in residents.u.receiver) ship)
|
||||
(~(del in requests.u.receiver) ship)
|
||||
=? sponsors ?=(^ previous)
|
||||
%+ ~(put by sponsors) from
|
||||
:_ requests.u.previous
|
||||
(~(del in residents.u.previous) ship)
|
||||
sponsors
|
||||
==
|
||||
::
|
||||
%spawn-proxy
|
||||
:- `[%spawn +.event]
|
||||
?~ old ~
|
||||
`[%spawn address.spawn-proxy.own.u.old]
|
||||
::
|
||||
%voting-proxy
|
||||
:- `[%vote +.event]
|
||||
?~ old ~
|
||||
`[%vote address.voting-proxy.own.u.old]
|
||||
::
|
||||
%transfer-proxy
|
||||
:- `[%transfer +.event]
|
||||
?~ old ~
|
||||
`[%transfer address.transfer-proxy.own.u.old]
|
||||
==
|
||||
++ ownership
|
||||
^- (quip update _owners)
|
||||
=; [to=(unit owner) from=(unit owner)]
|
||||
=? owners &(?=(^ from) !=(address.u.from 0x0))
|
||||
(~(del ju owners) u.from ship)
|
||||
?: ?| =(~ to)
|
||||
&(?=(^ to) =(address.u.to 0x0))
|
||||
==
|
||||
[ups owners]
|
||||
?~ to [ups owners]
|
||||
:_ (~(put ju owners) u.to ship)
|
||||
(snoc ups [%point ship new u.to from])
|
||||
?+ -.event [~ ~]
|
||||
%owner
|
||||
:- `[%own +.event]
|
||||
?~ old ~
|
||||
`[%own address.owner.own.u.old]
|
||||
::
|
||||
%management-proxy
|
||||
:- `[%manage +.event]
|
||||
?~ old ~
|
||||
`[%manage address.management-proxy.own.u.old]
|
||||
::
|
||||
%spawn-proxy
|
||||
:- `[%spawn +.event]
|
||||
?~ old ~
|
||||
`[%spawn address.spawn-proxy.own.u.old]
|
||||
::
|
||||
%voting-proxy
|
||||
:- `[%vote +.event]
|
||||
?~ old ~
|
||||
`[%vote address.voting-proxy.own.u.old]
|
||||
::
|
||||
%transfer-proxy
|
||||
:- `[%transfer +.event]
|
||||
?~ old ~
|
||||
`[%transfer address.transfer-proxy.own.u.old]
|
||||
==
|
||||
--
|
||||
::
|
||||
++ get-owner
|
||||
|= [=point:naive =proxy:naive]
|
||||
|
@ -3,9 +3,10 @@
|
||||
/+ naive, ethereum
|
||||
::
|
||||
|%
|
||||
+$ owner [=proxy:naive =address:naive]
|
||||
+$ owners (jug owner ship)
|
||||
+$ net ?(%mainnet %ropsten %local %default)
|
||||
+$ owner [=proxy:naive =address:naive]
|
||||
+$ owners (jug owner ship)
|
||||
+$ sponsors (map ship [residents=(set ship) requests=(set ship)])
|
||||
+$ net ?(%mainnet %ropsten %local %default)
|
||||
::
|
||||
+$ config
|
||||
$% [%frequency frequency=@dr]
|
||||
@ -17,6 +18,12 @@
|
||||
[%quota quota=@ud]
|
||||
==
|
||||
::
|
||||
+$ indices
|
||||
$: nas=^state:naive
|
||||
own=owners
|
||||
spo=sponsors
|
||||
==
|
||||
::
|
||||
+$ azimuth-config
|
||||
$: refresh-rate=@dr
|
||||
==
|
||||
|
Loading…
Reference in New Issue
Block a user