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-07-22 07:34:42 +03:00
|
|
|
++ apply-effects
|
|
|
|
|= [=effects:naive nas=^state:naive own=owners chain-t=@]
|
|
|
|
^+ [nas=nas own=own]
|
|
|
|
%+ roll effects
|
|
|
|
|= [=diff:naive nas=_nas own=_own]
|
|
|
|
^+ [nas own]
|
|
|
|
?. ?=([%tx *] diff) [nas own]
|
2021-07-22 13:05:28 +03:00
|
|
|
=< [nas own]
|
|
|
|
(apply-raw-tx | raw-tx.diff nas own chain-t)
|
|
|
|
::
|
|
|
|
++ apply-raw-tx
|
|
|
|
|= [force=? =raw-tx:naive nas=^state:naive own=owners chain-t=@]
|
2021-08-22 19:23:30 +03:00
|
|
|
^- [? nas=_nas ups=(list update) own=_own]
|
2021-07-22 07:34:42 +03:00
|
|
|
=+ cache-nas=nas
|
|
|
|
=/ chain-t=@t (ud-to-ascii:naive chain-t)
|
|
|
|
?. (verify-sig-and-nonce:naive verifier chain-t nas raw-tx)
|
2021-08-12 11:17:42 +03:00
|
|
|
~& [%verify-sig-and-nonce %failed tx.raw-tx]
|
2021-08-22 19:23:30 +03:00
|
|
|
[force nas ~ own]
|
2021-07-22 07:34:42 +03:00
|
|
|
=^ * points.nas
|
|
|
|
(increment-nonce:naive nas from.tx.raw-tx)
|
|
|
|
?~ nex=(receive-tx:naive nas tx.raw-tx)
|
2021-08-12 11:17:42 +03:00
|
|
|
~& [%receive-tx %failed]
|
2021-08-22 19:23:30 +03:00
|
|
|
[force ?:(force nas cache-nas) ~ own]
|
2021-07-22 13:05:28 +03:00
|
|
|
=* new-nas +.u.nex
|
|
|
|
=* effects -.u.nex
|
|
|
|
:+ &
|
|
|
|
new-nas
|
|
|
|
(update-ownership effects cache-nas new-nas own)
|
2021-07-22 07:34:42 +03:00
|
|
|
::
|
|
|
|
++ update-ownership
|
|
|
|
|= $: =effects:naive
|
|
|
|
cache-nas=^state:naive
|
2021-07-22 13:05:28 +03:00
|
|
|
nas=^state:naive
|
2021-07-22 07:34:42 +03:00
|
|
|
=owners
|
|
|
|
==
|
2021-08-27 16:59:10 +03:00
|
|
|
^- (quip update own=_owners)
|
2021-07-22 07:34:42 +03:00
|
|
|
%+ roll effects
|
2021-08-22 19:23:30 +03:00
|
|
|
|= [=diff:naive ups=(list update) owners=_owners]
|
2021-07-22 07:34:42 +03:00
|
|
|
=, orm:naive
|
2021-08-22 19:23:30 +03:00
|
|
|
?. ?=([%point *] diff) [ups owners]
|
|
|
|
=* ship ship.diff
|
2021-07-22 07:34:42 +03:00
|
|
|
=/ old=(unit point:naive)
|
2021-08-22 19:23:30 +03:00
|
|
|
(get points.cache-nas 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-08-23 17:32:26 +03:00
|
|
|
=; [to=(unit owner) from=(unit owner)]
|
|
|
|
=? owners &(?=(^ from) !=(address.u.from 0x0))
|
2021-08-22 19:23:30 +03:00
|
|
|
(~(del ju owners) u.from ship)
|
2021-08-23 17:32:26 +03:00
|
|
|
?: ?| =(~ to)
|
|
|
|
&(?=(^ to) =(address.u.to 0x0))
|
|
|
|
==
|
|
|
|
[ups owners]
|
2021-08-22 19:23:30 +03:00
|
|
|
?~ to [ups owners]
|
2021-08-27 16:59:10 +03:00
|
|
|
:_ (~(put ju owners) u.to ship)
|
|
|
|
(snoc ups [%point ship new u.to from])
|
2021-08-22 19:23:30 +03:00
|
|
|
?+ -.event [~ ~]
|
2021-07-22 07:34:42 +03:00
|
|
|
%owner
|
2021-08-23 17:32:26 +03:00
|
|
|
:- `[%own +.event]
|
|
|
|
?~ old ~
|
|
|
|
`[%own address.owner.own.u.old]
|
2021-07-22 07:34:42 +03:00
|
|
|
::
|
|
|
|
%management-proxy
|
2021-08-23 17:32:26 +03:00
|
|
|
:- `[%manage +.event]
|
|
|
|
?~ old ~
|
|
|
|
`[%manage address.management-proxy.own.u.old]
|
|
|
|
::
|
|
|
|
%spawn-proxy
|
|
|
|
:- `[%spawn +.event]
|
|
|
|
?~ old ~
|
|
|
|
`[%spawn address.spawn-proxy.own.u.old]
|
2021-07-22 07:34:42 +03:00
|
|
|
::
|
|
|
|
%voting-proxy
|
2021-08-23 17:32:26 +03:00
|
|
|
:- `[%vote +.event]
|
|
|
|
?~ old ~
|
|
|
|
`[%vote address.voting-proxy.own.u.old]
|
2021-07-22 07:34:42 +03:00
|
|
|
::
|
|
|
|
%transfer-proxy
|
2021-08-23 17:32:26 +03:00
|
|
|
:- `[%transfer +.event]
|
|
|
|
?~ old ~
|
|
|
|
`[%transfer address.transfer-proxy.own.u.old]
|
2021-07-22 07:34:42 +03:00
|
|
|
==
|
2021-08-22 19:23:30 +03:00
|
|
|
::
|
|
|
|
++ get-owner
|
|
|
|
|= [=point:naive =proxy:naive]
|
|
|
|
^- [nonce=@ _point]
|
|
|
|
=* 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
|
|
|
--
|