admin.gno
2.00 Kb · 67 lines
1package memba_points_v1
2
3import "chain"
4
5// Admin surface — owner-gated. The owner is the samcrew multisig at launch and can be handed to
6// the memba_dao executor via the 2-step TransferOwnership/AcceptOwnership (never a 1-step transfer
7// to a mistyped/dead address).
8
9// AddAwarder whitelists a realm pkgpath as an authorized points source (it may call Award/Revoke).
10// Owner only. An awarder is another realm whose OWN verified flow decides who earns; this realm
11// only trusts that the source is on the list.
12func AddAwarder(cur realm, pkgpath string) {
13 assertOwner(cur)
14 if pkgpath == "" {
15 panic("awarder pkgpath must be non-empty")
16 }
17 awarders.Set(pkgpath, true)
18 chain.Emit("AwarderAdded", "pkgpath", pkgpath)
19}
20
21// RemoveAwarder revokes an awarder realm's authority. Owner only.
22func RemoveAwarder(cur realm, pkgpath string) {
23 assertOwner(cur)
24 awarders.Remove(pkgpath)
25 chain.Emit("AwarderRemoved", "pkgpath", pkgpath)
26}
27
28// Pause freezes Award/Revoke (reads stay available). Owner only.
29func Pause(cur realm, state bool) {
30 assertOwner(cur)
31 paused = state
32 chain.Emit("PauseSet", "paused", boolStr(state))
33}
34
35// TransferOwnership stages a new owner; it takes effect only after AcceptOwnership is called BY
36// that address (2-step, so a typo can't brick admin).
37func TransferOwnership(cur realm, newOwner address) {
38 assertOwner(cur)
39 if newOwner == "" {
40 panic("newOwner must be non-empty")
41 }
42 pendingOwner = newOwner
43 chain.Emit("OwnershipTransferStarted", "pending", newOwner.String())
44}
45
46// AcceptOwnership completes the handoff. Only the staged pendingOwner may call it.
47func AcceptOwnership(cur realm) {
48 if !cur.IsCurrent() {
49 panic("spoofed realm")
50 }
51 if pendingOwner == "" {
52 panic("no pending ownership transfer")
53 }
54 if cur.Previous().Address() != pendingOwner {
55 panic("unauthorized: only the pending owner may accept")
56 }
57 owner = pendingOwner
58 pendingOwner = ""
59 chain.Emit("OwnershipTransferAccepted", "owner", owner.String())
60}
61
62func boolStr(b bool) string {
63 if b {
64 return "true"
65 }
66 return "false"
67}