Search Apps Documentation Source Content File Folder Download Copy Actions Download

protocol.gno

0.69 Kb ยท 49 lines
 1package admin
 2
 3import (
 4	"chain"
 5	"chain/runtime"
 6)
 7
 8const (
 9	SetProtocolEvent = "SetProtocol"
10)
11
12var (
13	protocolAddr address
14)
15
16func init() {
17	caller := runtime.OriginCaller()
18	protocolAddr = caller
19}
20
21func GetProtocol() address {
22	return protocolAddr
23}
24
25func SetProtocol(cur realm, addr address) {
26	caller := runtime.OriginCaller()
27
28	if caller != admin {
29		panic("admin access required to set protocol")
30	}
31
32	if !addr.IsValid() {
33		panic("invalid address")
34	}
35
36	oldAddr := protocolAddr
37	protocolAddr = addr
38
39	chain.Emit(
40		SetProtocolEvent,
41		"admin", caller.String(),
42		"oldAddr", oldAddr.String(),
43		"newAddr", addr.String(),
44	)
45}
46
47func IsProtocol(address address) bool {
48	return address == protocolAddr
49}