Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

render.gno

1.45 Kb · 60 lines
 1package rbac
 2
 3import (
 4	prbac "gno.land/p/gnoswap/rbac/v1"
 5	"gno.land/p/moul/md/v0"
 6	"gno.land/p/moul/mdtable/v0"
 7)
 8
 9// Render returns ownership and assignments for the protocol's fixed system roles.
10func Render(path string) string {
11	if path != "" {
12		return "404\n"
13	}
14
15	roles := []prbac.SystemRole{
16		prbac.ROLE_ADMIN, prbac.ROLE_DEVOPS, prbac.ROLE_COMMUNITY_POOL,
17		prbac.ROLE_GOVERNANCE, prbac.ROLE_GOV_STAKER, prbac.ROLE_XGNS,
18		prbac.ROLE_POOL, prbac.ROLE_POSITION, prbac.ROLE_ROUTER,
19		prbac.ROLE_STAKER, prbac.ROLE_EMISSION, prbac.ROLE_LAUNCHPAD,
20		prbac.ROLE_PROTOCOL_FEE,
21	}
22
23	ownershipTable := mdtable.Table{
24		Headers: []string{"Field", "Address"},
25		Rows: [][]string{
26			{"Owner", renderOwnershipAddress(GetOwner())},
27			{"Pending owner", renderOwnershipAddress(GetPendingOwner())},
28		},
29	}
30	out := md.H1("Gnoswap RBAC") +
31		"\n" +
32		md.H2("Ownership") +
33		"\n" +
34		ownershipTable.String() +
35		"\n" +
36		md.H2("System roles")
37
38	roleTable := mdtable.Table{
39		Headers: []string{"Role", "Address"},
40	}
41	for _, role := range roles {
42		roleTable.Append([]string{role.String(), renderRoleAddress(role)})
43	}
44	return out + "\n" + roleTable.String()
45}
46
47func renderOwnershipAddress(addr address) string {
48	if addr == address("") {
49		return "None"
50	}
51	return addr.String()
52}
53
54func renderRoleAddress(role prbac.SystemRole) string {
55	addr, err := GetRoleAddress(role.String())
56	if err != nil || addr == address("") {
57		return "Unassigned"
58	}
59	return md.InlineCode(addr.String())
60}