Skip to content Search Apps Documentation Source Content 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.

operator.gno

1.03 Kb · 55 lines
 1package admin
 2
 3import (
 4	"chain"
 5
 6	"gno.land/p/akkadia/beta/accesscontrol"
 7	"gno.land/p/nt/bptree/v0"
 8)
 9
10const (
11	SetOperatorEvent   = "SetOperator"
12	UnsetOperatorEvent = "UnsetOperator"
13)
14
15var (
16	operatorAddrs *bptree.BPTree = bptree.NewBPTree32()
17)
18
19func SetOperator(cur realm, addr address) {
20	accesscontrol.AssertIsAdmin(0, cur, IsAdmin)
21
22	assertValidAddress(addr)
23	operatorAddrs.Set(addr.String(), true)
24
25	chain.Emit(
26		SetOperatorEvent,
27		"address", addr.String(),
28	)
29}
30
31func GetOperators() []address {
32	result := []address{}
33	operatorAddrs.Iterate("", "", func(addr string, _ any) bool {
34		result = append(result, address(addr))
35		return false
36	})
37	return result
38}
39
40func UnsetOperator(cur realm, addr address) {
41	accesscontrol.AssertIsAdmin(0, cur, IsAdmin)
42	assertValidAddress(addr)
43	if !operatorAddrs.Has(addr.String()) {
44		panic("address is not an operator")
45	}
46	operatorAddrs.Remove(addr.String())
47	chain.Emit(
48		UnsetOperatorEvent,
49		"address", addr.String(),
50	)
51}
52
53func IsOperator(addr address) bool {
54	return operatorAddrs.Has(addr.String())
55}