Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

admin.gno

3.49 Kb · 115 lines
  1package memba_appstore_v3
  2
  3import "chain"
  4
  5// Admin surface — owner-gated. The owner is the samcrew multisig at launch and can
  6// be handed to the memba_dao executor via the 2-step TransferOwnership/AcceptOwnership
  7// (never a 1-step transfer to a mistyped/dead address).
  8
  9// SetRegistrationFee sets the flat listing fee in ugnot (0..MaxRegistrationFee).
 10// Zero is allowed (a fee waiver). Owner only.
 11func SetRegistrationFee(cur realm, fee int64) {
 12	assertOwner()
 13	if fee < 0 || fee > MaxRegistrationFee {
 14		panic("fee out of range [0, MaxRegistrationFee]")
 15	}
 16	registrationFee = fee
 17	chain.Emit("RegistrationFeeSet", "fee", itoa64(uint64(fee)))
 18}
 19
 20// SetTreasury repoints the fee recipient. Must be non-empty (an empty treasury would
 21// fail-close RegisterApp). Owner only. Keep this in sync with
 22// memba_market_config.GetTreasury().
 23func SetTreasury(cur realm, addr address) {
 24	assertOwner()
 25	if addr == "" {
 26		panic("treasury must be non-empty")
 27	}
 28	treasury = addr
 29	chain.Emit("TreasurySet", "treasury", addr.String())
 30}
 31
 32// AddCurator grants the curate role (approve pending listings). Owner only.
 33func AddCurator(cur realm, addr address) {
 34	assertOwner()
 35	if addr == "" {
 36		panic("curator must be non-empty")
 37	}
 38	curators.Set(addr.String(), true)
 39	chain.Emit("CuratorAdded", "curator", addr.String())
 40}
 41
 42// RemoveCurator revokes the curate role. Owner only.
 43func RemoveCurator(cur realm, addr address) {
 44	assertOwner()
 45	curators.Remove(addr.String())
 46	chain.Emit("CuratorRemoved", "curator", addr.String())
 47}
 48
 49// Pause is the kill switch: while paused, RegisterApp aborts (reads stay available).
 50// Owner only.
 51func Pause(cur realm, state bool) {
 52	assertOwner()
 53	paused = state
 54	chain.Emit("PauseSet", "paused", boolStr(state))
 55}
 56
 57// TransferOwnership stages a new owner; it takes effect only after AcceptOwnership
 58// is called BY that address (2-step, so a typo can't brick admin). A later call
 59// replaces the staged address; CancelOwnershipTransfer withdraws it.
 60func TransferOwnership(cur realm, newOwner address) {
 61	assertOwner()
 62	if newOwner == "" {
 63		panic("newOwner must be non-empty")
 64	}
 65	if !newOwner.IsValid() {
 66		panic("invalid address: " + newOwner.String())
 67	}
 68	if newOwner == owner {
 69		panic("newOwner is the current owner")
 70	}
 71	pendingOwner = newOwner
 72	chain.Emit("OwnershipTransferStarted", "pending", newOwner.String())
 73}
 74
 75// CancelOwnershipTransfer withdraws a staged handoff. Owner only.
 76func CancelOwnershipTransfer(cur realm) {
 77	assertOwner()
 78	if pendingOwner == "" {
 79		panic("no pending ownership transfer")
 80	}
 81	cancelled := pendingOwner
 82	pendingOwner = ""
 83	chain.Emit("OwnershipTransferCancelled", "pending", cancelled.String())
 84}
 85
 86// GetPendingOwner returns the staged successor, or the empty address.
 87func GetPendingOwner() address { return pendingOwner }
 88
 89// AcceptOwnership completes the handoff. Only the staged pendingOwner may call it.
 90// The former owner's curator grant is revoked atomically; the successor can
 91// curate immediately and may explicitly re-appoint the former owner later.
 92func AcceptOwnership(cur realm) {
 93	if !cur.IsCurrent() {
 94		panic("spoofed realm")
 95	}
 96	if pendingOwner == "" {
 97		panic("no pending ownership transfer")
 98	}
 99	if cur.Previous().Address() != pendingOwner {
100		panic("unauthorized: only the pending owner may accept")
101	}
102	previous := owner
103	curators.Set(pendingOwner.String(), true)
104	curators.Remove(previous.String())
105	owner = pendingOwner
106	pendingOwner = ""
107	chain.Emit("OwnershipTransferAccepted", "owner", owner.String())
108}
109
110func boolStr(b bool) string {
111	if b {
112		return "true"
113	}
114	return "false"
115}