config.gno

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