shrub/pkg/arvo/lib/dice.hoon

103 lines
2.7 KiB
Plaintext
Raw Normal View History

:: dice: helper functions for L2 Rollers
::
/- *dice
/+ naive, *naive-transactions
::
|%
++ 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]
=< [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]
=+ cache-nas=nas
=/ chain-t=@t (ud-to-ascii:naive chain-t)
?. (verify-sig-and-nonce:naive verifier chain-t nas raw-tx)
~& [%verify-sig-and-nonce %failed tx.raw-tx]
2021-08-22 19:23:30 +03:00
[force nas ~ own]
=^ * points.nas
(increment-nonce:naive nas from.tx.raw-tx)
?~ nex=(receive-tx:naive nas tx.raw-tx)
~& [%receive-tx %failed]
2021-08-22 19:23:30 +03:00
[force ?:(force nas cache-nas) ~ own]
=* new-nas +.u.nex
=* effects -.u.nex
:+ &
new-nas
(update-ownership effects cache-nas new-nas own)
::
++ update-ownership
|= $: =effects:naive
cache-nas=^state:naive
nas=^state:naive
=owners
==
2021-08-22 19:23:30 +03:00
^- (quip update _owners)
%+ roll effects
2021-08-22 19:23:30 +03:00
|= [=diff:naive ups=(list update) owners=_owners]
=, orm:naive
2021-08-22 19:23:30 +03:00
?. ?=([%point *] diff) [ups owners]
=* ship ship.diff
=/ old=(unit point:naive)
2021-08-22 19:23:30 +03:00
(get points.cache-nas ship)
=/ new=point:naive
2021-08-22 19:23:30 +03:00
(need (get points.nas ship))
=* event +>.diff
2021-08-22 19:23:30 +03:00
=; [to=(unit @ux) from=(unit @ux)]
=? owners ?=(^ from)
(~(del ju owners) u.from ship)
?~ to [ups owners]
:- (snoc ups [%point u.to ship new])
(~(put ju owners) u.to ship)
?+ -.event [~ ~]
%owner
2021-08-22 19:23:30 +03:00
[`+.event ?~(old ~ `address.owner.own.u.old)]
::
%spawn-proxy
2021-08-22 19:23:30 +03:00
[`+.event ?~(old ~ `address.spawn-proxy.own.u.old)]
::
%management-proxy
2021-08-22 19:23:30 +03:00
[`+.event ?~(old ~ `address.management-proxy.own.u.old)]
::
%voting-proxy
2021-08-22 19:23:30 +03:00
[`+.event ?~(old ~ `address.voting-proxy.own.u.old)]
::
%transfer-proxy
2021-08-22 19:23:30 +03:00
[`+.event ?~(old ~ `address.transfer-proxy.own.u.old)]
==
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))
==
::
--