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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

admin.gno

1.84 Kb · 77 lines
 1package rooms
 2
 3import "chain"
 4
 5// The admin can pause new activity, set the fee for rooms opened later (at
 6// most MaxFeeBps), move the treasury, and verify assets, each verification
 7// counting only VerifyDelay later. A pause stops Open, Join, deposits, Lock,
 8// Offer and Fill; it never stops Withdraw, Unlock or Cancel, so deposits
 9// can always leave. The admin has no way to move anyone's assets.
10
11var (
12	admin        address // set to the deployer in init
13	pendingAdmin address
14	paused       bool
15)
16
17// SetPaused stops or resumes new activity.
18func SetPaused(cur realm, value bool) {
19	assertAdmin(cur)
20	paused = value
21	state := "resumed"
22	if value {
23		state = "paused"
24	}
25	chain.Emit("Paused", "state", state)
26}
27
28// ProposeAdmin names the next admin; the change happens when that address
29// calls AcceptAdmin. Pass "" to withdraw a proposal.
30func ProposeAdmin(cur realm, next string) {
31	assertAdmin(cur)
32	if next == "" {
33		pendingAdmin = ""
34		return
35	}
36	addr := address(next)
37	if !addr.IsValid() {
38		panic("next admin is not a valid address")
39	}
40	pendingAdmin = addr
41	chain.Emit("AdminProposed", "next", addr.String())
42}
43
44// AcceptAdmin completes a handover started with ProposeAdmin.
45func AcceptAdmin(cur realm) {
46	who := callerOf(cur)
47	if pendingAdmin == "" || who != pendingAdmin {
48		panic("you are not the proposed admin")
49	}
50	admin = who
51	pendingAdmin = ""
52	chain.Emit("AdminChanged", "admin", who.String())
53}
54
55// IsPaused reports whether new activity is stopped.
56func IsPaused() bool {
57	return paused
58}
59
60// Admin returns the current admin address, or "" when there is none.
61func Admin() string {
62	return admin.String()
63}
64
65func assertAdmin(cur realm) {
66	who := callerOf(cur)
67	refuseCoins(cur)
68	if admin == "" || who != admin {
69		panic("admin only")
70	}
71}
72
73func assertNotPaused() {
74	if paused {
75		panic("trade rooms are paused: you can still withdraw, unlock and cancel")
76	}
77}