Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

appstore_adapter.gno

6.34 Kb · 50 lines
 1package memba_dao
 2import("strings";"gno.land/p/samcrew/memba_weighted_host";"gno.land/r/samcrew/memba_appstore_v3")
 3func appstoreState(a memba_weighted_host.AppstoreAction)memba_weighted_host.AppstoreState{
 4 owner:=memba_appstore_v3.GetOwner();s:=memba_weighted_host.AppstoreState{Owner:owner,PendingOwner:memba_appstore_v3.GetPendingOwner(),Treasury:memba_appstore_v3.GetTreasury(),Fee:memba_appstore_v3.GetRegistrationFee(),Paused:memba_appstore_v3.IsPaused(),Sealed:memba_appstore_v3.IsSeedingSealed(),OwnerCurator:memba_appstore_v3.IsCurator(string(owner)),DAOCurator:memba_appstore_v3.IsCurator(string(appstorePolicy.DAO())),SuccessorCurator:memba_appstore_v3.IsCurator(string(appstorePolicy.Successor()))}
 5 if a.Kind()==memba_weighted_host.AppstoreAddCurator||a.Kind()==memba_weighted_host.AppstoreRemoveCurator{s.SubjectCurator=memba_appstore_v3.IsCurator(string(a.Recipient()))}
 6 if a.IsListing(){l:=memba_appstore_v3.GetGovernanceListing(a.Path(),a.Kind()==memba_weighted_host.AppstoreClearFlags);s.Listing=memba_weighted_host.AppstoreListing{Exists:l.Exists,ContentHash:l.ContentHash,Status:l.Status,Reason:l.Reason,Credit:l.Credit,Flags:l.Flags,ClearKeys:l.ClearKeys}}
 7 return s
 8}
 9func proposeAppstore(cur realm,a memba_weighted_host.AppstoreAction)uint64{return host.ProposeAppstore(a,appstoreState(a),cur)}
10func ProposeAppstoreAccept(cur realm)uint64{return proposeAppstore(cur,appstorePolicy.Accept())}
11func ProposeAppstoreReturn(cur realm)uint64{return proposeAppstore(cur,appstorePolicy.Return())}
12func ProposeAppstoreAbortReturn(cur realm)uint64{return proposeAppstore(cur,appstorePolicy.AbortReturn())}
13func ProposeAppstoreTreasury(cur realm)uint64{return proposeAppstore(cur,appstorePolicy.SetTreasury())}
14func ProposeAppstoreFee(cur realm,fee int64)uint64{return proposeAppstore(cur,memba_weighted_host.AppstoreRegistrationFee(fee))}
15func ProposeAppstoreCurator(cur realm,who address,grant bool)uint64{return proposeAppstore(cur,memba_weighted_host.AppstoreCurator(who,grant))}
16func ProposeAppstoreUnpause(cur realm)uint64{return proposeAppstore(cur,memba_weighted_host.AppstoreResume())}
17func ProposeAppstoreSeal(cur realm)uint64{return proposeAppstore(cur,memba_weighted_host.AppstoreSealImport())}
18func ProposeAppstoreApprove(cur realm,path string)uint64{return proposeAppstore(cur,memba_weighted_host.AppstoreModeration(memba_weighted_host.AppstoreApprove,path,""))}
19func ProposeAppstoreReject(cur realm,path,reason string)uint64{return proposeAppstore(cur,memba_weighted_host.AppstoreModeration(memba_weighted_host.AppstoreReject,path,reason))}
20func ProposeAppstoreDelist(cur realm,path string)uint64{return proposeAppstore(cur,memba_weighted_host.AppstoreModeration(memba_weighted_host.AppstoreDelist,path,""))}
21func ProposeAppstoreRestore(cur realm,path string)uint64{return proposeAppstore(cur,memba_weighted_host.AppstoreModeration(memba_weighted_host.AppstoreRestore,path,""))}
22func ProposeAppstoreClearFlags(cur realm,path string)uint64{return proposeAppstore(cur,memba_weighted_host.AppstoreModeration(memba_weighted_host.AppstoreClearFlags,path,""))}
23func EmergencyPauseAppstore(cur realm){a:=memba_weighted_host.AppstoreResume();before:=appstoreState(a);host.PrepareAppstoreEmergencyPause(before,cur);expected:=before;expected.Paused=true;memba_appstore_v3.Pause(cross(cur),true);if appstoreState(a)!=expected{panic("appstore pause postcondition mismatch")}}
24func executeAppstore(cur realm,id uint64){
25 proposed:=host.Proposal(id).AppstoreAction;before:=appstoreState(proposed);a:=host.ConsumeAppstore(id,before,cur);expected:=before
26 switch a.Kind(){
27 case memba_weighted_host.AppstoreAccept:
28  expected.Owner=appstorePolicy.DAO();expected.PendingOwner="";expected.OwnerCurator=true;expected.DAOCurator=true;if before.Owner==appstorePolicy.Successor(){expected.SuccessorCurator=false};memba_appstore_v3.AcceptOwnership(cross(cur))
29 case memba_weighted_host.AppstoreReturn:expected.PendingOwner=a.Recipient();memba_appstore_v3.TransferOwnership(cross(cur),a.Recipient())
30 case memba_weighted_host.AppstoreAbortReturn:expected.PendingOwner="";memba_appstore_v3.CancelOwnershipTransfer(cross(cur))
31 case memba_weighted_host.AppstoreFee:expected.Fee=a.Fee();memba_appstore_v3.SetRegistrationFee(cross(cur),a.Fee())
32 case memba_weighted_host.AppstoreTreasury:expected.Treasury=a.Recipient();memba_appstore_v3.SetTreasury(cross(cur),a.Recipient())
33 case memba_weighted_host.AppstoreUnpause:expected.Paused=false;memba_appstore_v3.Pause(cross(cur),false)
34 case memba_weighted_host.AppstoreSeal:expected.Sealed=true;memba_appstore_v3.FinalizeSeed(cross(cur))
35 case memba_weighted_host.AppstoreAddCurator,memba_weighted_host.AppstoreRemoveCurator:
36  grant:=a.Kind()==memba_weighted_host.AppstoreAddCurator;expected.SubjectCurator=grant;if a.Recipient()==before.Owner{expected.OwnerCurator=grant};if a.Recipient()==appstorePolicy.DAO(){expected.DAOCurator=grant};if a.Recipient()==appstorePolicy.Successor(){expected.SuccessorCurator=grant};if grant{memba_appstore_v3.AddCurator(cross(cur),a.Recipient())}else{memba_appstore_v3.RemoveCurator(cross(cur),a.Recipient())}
37 case memba_weighted_host.AppstoreApprove:expected.Listing.Status="live";memba_appstore_v3.ApproveApp(cross(cur),a.Path())
38 case memba_weighted_host.AppstoreReject:expected.Listing.Status="rejected";expected.Listing.Reason=a.Reason();expected.Listing.Credit=true;memba_appstore_v3.RejectApp(cross(cur),a.Path(),a.Reason())
39 case memba_weighted_host.AppstoreDelist:expected.Listing.Status="delisted";memba_appstore_v3.DelistApp(cross(cur),a.Path())
40 case memba_weighted_host.AppstoreRestore:expected.Listing.Status="pending";memba_appstore_v3.RestoreApp(cross(cur),a.Path())
41 case memba_weighted_host.AppstoreClearFlags:
42  keys:=strings.Split(before.Listing.ClearKeys,",");if len(keys)>memba_appstore_v3.MaxClearBatch||len(keys)>before.Listing.Flags{panic("invalid appstore clear batch")};expected.Listing.Flags-=len(keys);expected.Listing.ClearKeys=""
43  memba_appstore_v3.ClearFlags(cross(cur),a.Path())
44  for _,who:=range keys{if memba_appstore_v3.HasGovernanceFlag(a.Path(),who){panic("appstore clear dedupe postcondition mismatch")}}
45 default:panic("unsupported appstore action")
46 }
47 after:=appstoreState(a);if a.Kind()==memba_weighted_host.AppstoreClearFlags{after.Listing.ClearKeys=""}
48 if after!=expected{panic("appstore postcondition mismatch")}
49 if a.Kind()==memba_weighted_host.AppstoreAccept&&memba_appstore_v3.IsCurator(string(before.Owner)){panic("appstore previous curator retained")}
50}