config.gno
2.64 Kb ยท 115 lines
1package config
2
3import (
4 "std"
5
6 "gno.land/p/demo/ufmt"
7 "gno.land/p/n2p5/mgroup"
8)
9
10const (
11 originalOwner = "g1j39fhg29uehm7twwnhvnpz3ggrm6tprhq65t0t" // n2p5
12)
13
14var (
15 adminGroup = mgroup.New(originalOwner)
16 description = ""
17)
18
19// AddBackupOwner adds a backup owner to the Owner Group.
20// A backup owner can claim ownership of the contract.
21func AddBackupOwner(cur realm, addr std.Address) {
22 if err := adminGroup.AddBackupOwner(addr); err != nil {
23 panic(err)
24 }
25}
26
27// RemoveBackupOwner removes a backup owner from the Owner Group.
28// The primary owner cannot be removed.
29func RemoveBackupOwner(cur realm, addr std.Address) {
30 if err := adminGroup.RemoveBackupOwner(addr); err != nil {
31 panic(err)
32 }
33}
34
35// ClaimOwnership allows an authorized user in the ownerGroup
36// to claim ownership of the contract.
37func ClaimOwnership(cur realm) {
38 if err := adminGroup.ClaimOwnership(); err != nil {
39 panic(err)
40 }
41}
42
43// AddAdmin adds an admin to the Admin Group.
44func AddAdmin(cur realm, addr std.Address) {
45 if err := adminGroup.AddMember(addr); err != nil {
46 panic(err)
47 }
48}
49
50// RemoveAdmin removes an admin from the Admin Group.
51// The primary owner cannot be removed.
52func RemoveAdmin(cur realm, addr std.Address) {
53 if err := adminGroup.RemoveMember(addr); err != nil {
54 panic(err)
55 }
56}
57
58// Owner returns the current owner of the claims contract.
59func Owner() std.Address {
60 return adminGroup.Owner()
61}
62
63// BackupOwners returns the current backup owners of the claims contract.
64func BackupOwners() []string {
65 return adminGroup.BackupOwners()
66}
67
68// Admins returns the current admin members of the claims contract.
69func Admins() []string {
70 return adminGroup.Members()
71}
72
73// IsAdmin checks if an address is in the config adminGroup.
74func IsAdmin(addr std.Address) bool {
75 return adminGroup.IsMember(addr)
76}
77
78// toMarkdownList formats a slice of strings as a markdown list.
79func toMarkdownList(items []string) string {
80 var result string
81 for _, item := range items {
82 result += ufmt.Sprintf("- %s\n", item)
83 }
84 return result
85}
86
87func Render(path string) string {
88 owner := adminGroup.Owner().String()
89 backupOwners := toMarkdownList(BackupOwners())
90 adminMembers := toMarkdownList(Admins())
91 return ufmt.Sprintf(`
92# Config Dashboard
93
94This dashboard shows the current configuration owner, backup owners, and admin members.
95- The owner has the exclusive ability to manage the backup owners and admin members.
96- Backup owners can claim ownership of the contract and become the owner.
97- Admin members are used to authorize actions in other realms, such as [my home realm](/r/n2p5/home).
98
99#### Owner
100
101%s
102
103#### Backup Owners
104
105%s
106
107#### Admin Members
108
109%s
110
111`,
112 owner,
113 backupOwners,
114 adminMembers)
115}