arcade_adapter.gno
3.72 Kb · 44 lines
1// Fixed arcade dispatch; no score-writing, fee or arbitrary-call authority.
2package memba_dao
3import (
4 "gno.land/p/samcrew/memba_weighted_host"
5 "gno.land/r/samcrew/memba_arcade_leaderboard_v1"
6)
7func arcadeState(a memba_weighted_host.ArcadeAction)memba_weighted_host.ArcadeState{
8 owner:=memba_arcade_leaderboard_v1.GetOwner();subject:=false
9 if a.Attester()!=""{subject=memba_arcade_leaderboard_v1.IsAttester(string(a.Attester()))}
10 return memba_weighted_host.ArcadeState{Owner:owner,PendingOwner:memba_arcade_leaderboard_v1.GetPendingOwner(),Paused:memba_arcade_leaderboard_v1.IsPaused(),OwnerListed:memba_arcade_leaderboard_v1.IsAttester(string(owner)),DAOListed:memba_arcade_leaderboard_v1.IsAttester(string(arcadePolicy.DAO())),SuccessorListed:memba_arcade_leaderboard_v1.IsAttester(string(arcadePolicy.Successor())),SubjectListed:subject}
11}
12func ProposeArcadeAccept(cur realm)uint64{a:=arcadePolicy.Accept();return host.ProposeArcade(a,arcadeState(a),cur)}
13func ProposeArcadeReturn(cur realm)uint64{a:=arcadePolicy.Return();return host.ProposeArcade(a,arcadeState(a),cur)}
14func ProposeArcadeAbortReturn(cur realm)uint64{a:=arcadePolicy.AbortReturn();return host.ProposeArcade(a,arcadeState(a),cur)}
15func ProposeArcadeAddAttester(cur realm,who address)uint64{a:=arcadePolicy.AddAttester(who);return host.ProposeArcade(a,arcadeState(a),cur)}
16func ProposeArcadeRemoveAttester(cur realm,who address)uint64{a:=memba_weighted_host.ArcadeRevokeAttester(who);return host.ProposeArcade(a,arcadeState(a),cur)}
17func ProposeArcadeUnpause(cur realm)uint64{a:=memba_weighted_host.ArcadeResume();return host.ProposeArcade(a,arcadeState(a),cur)}
18func EmergencyPauseArcade(cur realm){
19 a:=memba_weighted_host.ArcadeResume();before:=arcadeState(a);host.PrepareArcadeEmergencyPause(before,cur);expected:=before;expected.Paused=true
20 memba_arcade_leaderboard_v1.Pause(cross(cur),true)
21 if arcadeState(a)!=expected{panic("arcade pause postcondition mismatch")}
22}
23func executeArcade(cur realm,id uint64){
24 proposed:=host.Proposal(id).ArcadeAction;before:=arcadeState(proposed);a:=host.ConsumeArcade(id,before,cur);expected:=before
25 switch a.Kind(){
26 case memba_weighted_host.ArcadeAcceptOwner:
27 expected.Owner=arcadePolicy.DAO();expected.PendingOwner="";expected.OwnerListed=before.DAOListed;memba_arcade_leaderboard_v1.AcceptOwnership(cross(cur))
28 case memba_weighted_host.ArcadeReturnOwner:
29 expected.PendingOwner=a.Recipient();memba_arcade_leaderboard_v1.TransferOwnership(cross(cur),a.Recipient())
30 case memba_weighted_host.ArcadeAbortReturn:
31 expected.PendingOwner="";memba_arcade_leaderboard_v1.CancelOwnershipTransfer(cross(cur))
32 case memba_weighted_host.ArcadeUnpause:
33 expected.Paused=false;memba_arcade_leaderboard_v1.Pause(cross(cur),false)
34 case memba_weighted_host.ArcadeAddAttester,memba_weighted_host.ArcadeRemoveAttester:
35 listed:=a.Kind()==memba_weighted_host.ArcadeAddAttester;expected.SubjectListed=listed
36 if a.Attester()==before.Owner{expected.OwnerListed=listed};if a.Attester()==arcadePolicy.DAO(){expected.DAOListed=listed};if a.Attester()==arcadePolicy.Successor(){expected.SuccessorListed=listed}
37 if listed{memba_arcade_leaderboard_v1.AddAttester(cross(cur),a.Attester())}else{memba_arcade_leaderboard_v1.RemoveAttester(cross(cur),a.Attester())}
38 default:panic("unsupported arcade action")
39 }
40 if arcadeState(a)!=expected{panic("arcade postcondition mismatch")}
41 // Ownership operations preserve explicit appointments. IsAttester is the
42 // allowlist bit; it is not the old owner's implicit authority.
43 if a.Kind()==memba_weighted_host.ArcadeAcceptOwner && memba_arcade_leaderboard_v1.IsAttester(string(before.Owner))!=before.OwnerListed{panic("arcade old owner appointment changed")}
44}