admin.gno

1.60 Kb ยท 87 lines
 1package faucet
 2
 3import (
 4	"errors"
 5	"std"
 6)
 7
 8func AdminSetInPause(inPause bool) string {
 9	if err := assertIsAdmin(); err != nil {
10		return err.Error()
11	}
12	gInPause = inPause
13	return ""
14}
15
16func AdminSetMessage(message string) string {
17	if err := assertIsAdmin(); err != nil {
18		return err.Error()
19	}
20	gMessage = message
21	return ""
22}
23
24func AdminSetTransferLimit(amount int64) string {
25	if err := assertIsAdmin(); err != nil {
26		return err.Error()
27	}
28	gLimit = std.NewCoin("ugnot", amount)
29	return ""
30}
31
32func AdminSetAdminAddr(addr std.Address) string {
33	if err := assertIsAdmin(); err != nil {
34		return err.Error()
35	}
36	gAdminAddr = addr
37	return ""
38}
39
40func AdminAddController(addr std.Address) string {
41	if err := assertIsAdmin(); err != nil {
42		return err.Error()
43	}
44
45	size := gControllers.Size()
46
47	if size >= gControllersMaxSize {
48		return "can not add more controllers than allowed"
49	}
50
51	if gControllers.Has(addr.String()) {
52		return addr.String() + " exists, no need to add."
53	}
54
55	gControllers.Set(addr.String(), addr)
56
57	return ""
58}
59
60func AdminRemoveController(addr std.Address) string {
61	if err := assertIsAdmin(); err != nil {
62		return err.Error()
63	}
64
65	if !gControllers.Has(addr.String()) {
66		return addr.String() + " is not on the controller list"
67	}
68
69	_, ok := gControllers.Remove(addr.String())
70
71	// it not should happen.
72	// we will check anyway to prevent issues in the underline implementation.
73
74	if !ok {
75		return addr.String() + " is not on the controller list"
76	}
77
78	return ""
79}
80
81func assertIsAdmin() error {
82	caller := std.GetOrigCaller()
83	if caller != gAdminAddr {
84		return errors.New("restricted for admin")
85	}
86	return nil
87}