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

types.gno

2.03 Kb · 65 lines
 1package rbac
 2
 3// SystemRole represents a reserved system-role name that cannot be removed once registered.
 4type SystemRole string
 5
 6const (
 7	ROLE_ADMIN          SystemRole = "admin"
 8	ROLE_DEVOPS         SystemRole = "devops"
 9	ROLE_COMMUNITY_POOL SystemRole = "community_pool"
10	ROLE_GOVERNANCE     SystemRole = "governance"
11	ROLE_GOV_STAKER     SystemRole = "gov_staker"
12	ROLE_XGNS           SystemRole = "xgns"
13	ROLE_POOL           SystemRole = "pool"
14	ROLE_POSITION       SystemRole = "position"
15	ROLE_ROUTER         SystemRole = "router"
16	ROLE_STAKER         SystemRole = "staker"
17	ROLE_EMISSION       SystemRole = "emission"
18	ROLE_LAUNCHPAD      SystemRole = "launchpad"
19	ROLE_PROTOCOL_FEE   SystemRole = "protocol_fee"
20)
21
22// MUST BE IMMUTABLE, DO NOT MODIFY.
23// _systemRoleNames is a map of system role names to SystemRole values by performance.
24var _systemRoleNames = map[string]SystemRole{
25	"admin":          ROLE_ADMIN,
26	"devops":         ROLE_DEVOPS,
27	"community_pool": ROLE_COMMUNITY_POOL,
28	"governance":     ROLE_GOVERNANCE,
29	"gov_staker":     ROLE_GOV_STAKER,
30	"xgns":           ROLE_XGNS,
31	"pool":           ROLE_POOL,
32	"position":       ROLE_POSITION,
33	"router":         ROLE_ROUTER,
34	"staker":         ROLE_STAKER,
35	"emission":       ROLE_EMISSION,
36	"launchpad":      ROLE_LAUNCHPAD,
37	"protocol_fee":   ROLE_PROTOCOL_FEE,
38}
39
40// String returns the string representation of the SystemRole.
41// Returns "Unknown" if the role is not a valid system role.
42//
43// Returns:
44//   - string: Registered system-role name, or "Unknown" when r is not in the system-role registry.
45func (r SystemRole) String() string {
46	roleName := string(r)
47	if _, ok := _systemRoleNames[roleName]; !ok {
48		return "Unknown"
49	}
50
51	return roleName
52}
53
54// IsSystemRole returns true if roleName is a system role.
55//
56// Parameters:
57//   - roleName: Exact string key to check against the reserved system-role registry.
58//
59// Returns:
60//   - bool: true when roleName names a registered system role; false otherwise.
61func IsSystemRole(roleName string) bool {
62	_, ok := _systemRoleNames[roleName]
63
64	return ok
65}