2021-07-22 07:34:42 +03:00
|
|
|
:: dice: helper functions for L2 Rollers
|
|
|
|
::
|
|
|
|
/- *dice
|
|
|
|
/+ naive, *naive-transactions
|
|
|
|
::
|
|
|
|
|%
|
2021-10-11 18:16:17 +03:00
|
|
|
++ nonce-order
|
|
|
|
|= [a=[* =nonce:naive] b=[* =nonce:naive]]
|
|
|
|
(lte nonce.a nonce.b)
|
|
|
|
::
|
2021-11-25 23:22:15 +03:00
|
|
|
++ tx-effects
|
2021-11-24 17:31:59 +03:00
|
|
|
|= [chain-t=@ =effects:naive nas=^state:naive =indices]
|
2021-11-10 19:46:22 +03:00
|
|
|
^+ indices
|
|
|
|
=< indices
|
2021-11-25 23:22:15 +03:00
|
|
|
%+ roll effects
|
|
|
|
|= [=diff:naive nas=_nas indices=_indices]
|
|
|
|
?. ?=([%tx *] diff) [nas indices]
|
|
|
|
=< [nas indices]
|
2021-11-24 17:31:59 +03:00
|
|
|
(apply-raw-tx | chain-t raw-tx.diff nas indices)
|
2021-07-22 13:05:28 +03:00
|
|
|
::
|
|
|
|
++ apply-raw-tx
|
2021-11-24 17:31:59 +03:00
|
|
|
|= [force=? chain-t=@ =raw-tx:naive nas=^state:naive =indices]
|
2021-11-25 23:22:15 +03:00
|
|
|
^- [? (list update) nas=_nas indices=_indices]
|
2021-11-24 17:31:59 +03:00
|
|
|
=+ cache=nas
|
2021-07-22 07:34:42 +03:00
|
|
|
=/ chain-t=@t (ud-to-ascii:naive chain-t)
|
2021-11-24 17:31:59 +03:00
|
|
|
?. (verify-sig-and-nonce:naive verifier chain-t nas raw-tx)
|
2021-11-25 23:22:15 +03:00
|
|
|
~& >>> [%verify-sig-and-nonce %failed tx.raw-tx]
|
2021-11-24 17:31:59 +03:00
|
|
|
[force ~ nas indices]
|
|
|
|
=^ * points.nas
|
|
|
|
(increment-nonce:naive nas from.tx.raw-tx)
|
|
|
|
?~ nex=(receive-tx:naive nas tx.raw-tx)
|
2021-11-25 23:22:15 +03:00
|
|
|
~& >>> [%receive-tx %failed]
|
2021-11-24 17:31:59 +03:00
|
|
|
[force ~ ?:(force nas cache) indices]
|
2021-07-22 13:05:28 +03:00
|
|
|
=* new-nas +.u.nex
|
|
|
|
=* effects -.u.nex
|
2021-11-24 17:31:59 +03:00
|
|
|
=^ updates indices
|
2021-11-25 23:22:15 +03:00
|
|
|
(point-effects effects cache new-nas [own spo]:indices)
|
2021-11-24 17:31:59 +03:00
|
|
|
[& updates new-nas indices]
|
2021-07-22 07:34:42 +03:00
|
|
|
::
|
2021-11-25 23:22:15 +03:00
|
|
|
++ point-effects
|
2021-11-24 17:31:59 +03:00
|
|
|
|= [=effects:naive cache=^state:naive nas=^state:naive =indices]
|
|
|
|
^- [(list update) indices=_indices]
|
2021-11-25 23:22:15 +03:00
|
|
|
=; [updates=(list update) indices=_indices]
|
|
|
|
[(flop updates) indices]
|
2021-07-22 07:34:42 +03:00
|
|
|
%+ roll effects
|
2021-11-25 23:22:15 +03:00
|
|
|
|= [=diff:naive updates=(list update) indices=_indices]
|
2021-07-22 07:34:42 +03:00
|
|
|
=, orm:naive
|
2021-11-25 23:22:15 +03:00
|
|
|
?. ?=([%point *] diff) [updates indices]
|
2021-11-24 17:31:59 +03:00
|
|
|
=* ship ship.diff
|
|
|
|
=* sponsors spo.indices
|
|
|
|
=* owners own.indices
|
2021-07-22 07:34:42 +03:00
|
|
|
=/ old=(unit point:naive)
|
2021-11-24 17:31:59 +03:00
|
|
|
(get points.cache ship)
|
2021-07-22 07:34:42 +03:00
|
|
|
=/ new=point:naive
|
2021-08-22 19:23:30 +03:00
|
|
|
(need (get points.nas ship))
|
2021-07-22 07:34:42 +03:00
|
|
|
=* event +>.diff
|
2021-11-10 19:46:22 +03:00
|
|
|
|^
|
2021-11-24 17:31:59 +03:00
|
|
|
=. sponsors sponsorship
|
2021-11-25 23:22:15 +03:00
|
|
|
=^ update owners ownership
|
|
|
|
[(welp update updates) indices]
|
2021-08-23 17:32:26 +03:00
|
|
|
::
|
2021-11-10 19:46:22 +03:00
|
|
|
++ 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
|
2021-11-25 23:22:15 +03:00
|
|
|
?~ old sponsors
|
2021-11-10 19:46:22 +03:00
|
|
|
=* 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)
|
2021-11-11 08:36:27 +03:00
|
|
|
:- *(set @p)
|
|
|
|
(~(put in *(set @p)) ship)
|
2021-11-10 19:46:22 +03:00
|
|
|
:- residents.u.receiver
|
|
|
|
(~(put in requests.u.receiver) ship)
|
|
|
|
::
|
|
|
|
%sponsor
|
2021-11-25 23:22:15 +03:00
|
|
|
?~ old sponsors
|
2021-11-10 19:46:22 +03:00
|
|
|
=* 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
|
|
|
|
==
|
2021-07-22 07:34:42 +03:00
|
|
|
::
|
2021-11-10 19:46:22 +03:00
|
|
|
++ 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))
|
|
|
|
==
|
2021-11-25 23:22:15 +03:00
|
|
|
[~ owners]
|
|
|
|
?~ to [~ owners]
|
|
|
|
:- [%point ship new u.to from]~
|
|
|
|
(~(put ju owners) u.to ship)
|
2021-11-10 19:46:22 +03:00
|
|
|
?+ -.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]
|
|
|
|
==
|
|
|
|
--
|
2021-08-22 19:23:30 +03:00
|
|
|
::
|
|
|
|
++ get-owner
|
|
|
|
|= [=point:naive =proxy:naive]
|
2021-11-25 23:22:15 +03:00
|
|
|
^- [=nonce:naive _point]
|
2021-08-22 19:23:30 +03:00
|
|
|
=* own own.point
|
|
|
|
?- proxy
|
|
|
|
%own
|
|
|
|
:- nonce.owner.own
|
|
|
|
point(nonce.owner.own +(nonce.owner.own))
|
|
|
|
::
|
|
|
|
%spawn
|
|
|
|
:- nonce.spawn-proxy.own
|
|
|
|
point(nonce.spawn-proxy.own +(nonce.spawn-proxy.own))
|
|
|
|
::
|
|
|
|
%manage
|
|
|
|
:- nonce.management-proxy.own
|
|
|
|
point(nonce.management-proxy.own +(nonce.management-proxy.own))
|
|
|
|
::
|
|
|
|
%vote
|
|
|
|
:- nonce.voting-proxy.own
|
|
|
|
point(nonce.voting-proxy.own +(nonce.voting-proxy.own))
|
|
|
|
::
|
|
|
|
%transfer
|
|
|
|
:- nonce.transfer-proxy.own
|
|
|
|
point(nonce.transfer-proxy.own +(nonce.transfer-proxy.own))
|
|
|
|
==
|
|
|
|
::
|
2021-07-22 07:34:42 +03:00
|
|
|
--
|