1package home
2
3import (
4 "errors"
5 "std"
6)
7
8var (
9 mainAddr = std.Address("g1ej0qca5ptsw9kfr64ey8jvfy9eacga6mpj2z0y") // matija's main address
10 backupAddr std.Address // backup address
11
12 errorInvalidAddr = errors.New("config: invalid address")
13 errorUnauthorized = errors.New("config: unauthorized")
14)
15
16func Address() std.Address {
17 return mainAddr
18}
19
20func Backup() std.Address {
21 return backupAddr
22}
23
24func SetAddress(newAddress std.Address) error {
25 if !newAddress.IsValid() {
26 return errorInvalidAddr
27 }
28
29 if err := checkAuthorized(); err != nil {
30 return err
31 }
32
33 mainAddr = newAddress
34 return nil
35}
36
37func SetBackup(newAddress std.Address) error {
38 if !newAddress.IsValid() {
39 return errorInvalidAddr
40 }
41
42 if err := checkAuthorized(); err != nil {
43 return err
44 }
45
46 backupAddr = newAddress
47 return nil
48}
49
50func checkAuthorized() error {
51 caller := std.GetOrigCaller()
52 if caller != mainAddr && caller != backupAddr {
53 return errorUnauthorized
54 }
55
56 return nil
57}
58
59func AssertAuthorized() {
60 caller := std.GetOrigCaller()
61 if caller != mainAddr && caller != backupAddr {
62 panic(errorUnauthorized)
63 }
64}
config.gno
1.13 Kb ยท 64 lines