Search Apps Documentation Source Content File Folder Download Copy Actions Download

admin.gno

1.19 Kb ยท 74 lines
 1package admin
 2
 3import (
 4	"chain"
 5	"chain/runtime"
 6)
 7
 8const (
 9	TransferAdminEvent  = "TransferAdmin"
10	SetExplorerURLEvent = "SetExplorerURL"
11)
12
13var (
14	admin       address
15	explorerURL string = "https://app.alpha.akkadia.land"
16)
17
18func init() {
19	caller := runtime.OriginCaller()
20	admin = caller
21}
22
23func GetAdmin() address {
24	return admin
25}
26
27func TransferAdmin(cur realm, address address) {
28	caller := runtime.OriginCaller()
29
30	if caller != admin {
31		panic("admin access required to transfer admin")
32	}
33
34	if !address.IsValid() {
35		panic("invalid address")
36	}
37
38	prevAdmin := admin
39
40	chain.Emit(
41		TransferAdminEvent,
42		"from", prevAdmin.String(),
43		"to", address.String(),
44	)
45
46	admin = address
47}
48
49func IsAdmin(address address) bool {
50	return address == admin
51}
52
53// SetExplorerURL sets the explorer base URL (admin only)
54func SetExplorerURL(cur realm, url string) {
55	caller := runtime.OriginCaller()
56	if caller != admin {
57		panic("admin access required to set explorer URL")
58	}
59
60	oldURL := explorerURL
61	explorerURL = url
62
63	chain.Emit(
64		SetExplorerURLEvent,
65		"admin", caller.String(),
66		"oldURL", oldURL,
67		"newURL", url,
68	)
69}
70
71// GetExplorerURL returns the explorer base URL
72func GetExplorerURL() string {
73	return explorerURL
74}