1package access23import (4 "chain"56 prbac "gno.land/p/gnoswap/rbac/v1"7 ufmt "gno.land/p/nt/ufmt/v0"8)910// rbacPackagePath is the package path of the RBAC contract11// Used to verify that role management functions are called only by RBAC12const rbacPackagePath = "gno.land/r/gnoswap/rbac/v1"1314// AssertIsRlmCurrent panics if the realm token is not the current crossing frame.15//16// Parameters:17// - _: leading realm-call discriminator; callers pass 018// - rlm: realm context token that must represent the current crossing frame19func AssertIsRlmCurrent(_ int, rlm realm) {20 if !rlm.IsCurrent() {21 panic(errSpoofedRealm)22 }23}2425// AssertIsAdminOrGovernance panics unless caller is the configured admin or governance address.26//27// Parameters:28// - caller: address whose authorization is checked against the admin and governance roles29func AssertIsAdminOrGovernance(caller address) {30 if IsAuthorized(prbac.ROLE_ADMIN.String(), caller) || IsAuthorized(prbac.ROLE_GOVERNANCE.String(), caller) {31 return32 }3334 panic(ufmt.Errorf(errUnauthorizedAdminOrGov, caller))35}3637// AssertIsAdmin panics unless caller is the configured admin address.38//39// Parameters:40// - caller: address whose authorization is checked against the admin role41func AssertIsAdmin(caller address) {42 AssertIsAuthorized(prbac.ROLE_ADMIN.String(), caller)43}4445// AssertIsGovernance panics unless caller is the configured governance address.46//47// Parameters:48// - caller: address whose authorization is checked against the governance role49func AssertIsGovernance(caller address) {50 AssertIsAuthorized(prbac.ROLE_GOVERNANCE.String(), caller)51}5253// AssertIsGovStaker panics unless caller is the configured governance-staker address.54//55// Parameters:56// - caller: address whose authorization is checked against the governance-staker role57func AssertIsGovStaker(caller address) {58 AssertIsAuthorized(prbac.ROLE_GOV_STAKER.String(), caller)59}6061// AssertIsRouter panics unless caller is the configured router address.62//63// Parameters:64// - caller: address whose authorization is checked against the router role65func AssertIsRouter(caller address) {66 AssertIsAuthorized(prbac.ROLE_ROUTER.String(), caller)67}6869// AssertIsPool panics unless caller is the configured pool address.70//71// Parameters:72// - caller: address whose authorization is checked against the pool role73func AssertIsPool(caller address) {74 AssertIsAuthorized(prbac.ROLE_POOL.String(), caller)75}7677// AssertIsPosition panics unless caller is the configured position address.78//79// Parameters:80// - caller: address whose authorization is checked against the position role81func AssertIsPosition(caller address) {82 AssertIsAuthorized(prbac.ROLE_POSITION.String(), caller)83}8485// AssertIsStaker panics unless caller is the configured staker address.86//87// Parameters:88// - caller: address whose authorization is checked against the staker role89func AssertIsStaker(caller address) {90 AssertIsAuthorized(prbac.ROLE_STAKER.String(), caller)91}9293// AssertIsLaunchpad panics unless caller is the configured launchpad address.94//95// Parameters:96// - caller: address whose authorization is checked against the launchpad role97func AssertIsLaunchpad(caller address) {98 AssertIsAuthorized(prbac.ROLE_LAUNCHPAD.String(), caller)99}100101// AssertIsEmission panics unless caller is the configured emission address.102//103// Parameters:104// - caller: address whose authorization is checked against the emission role105func AssertIsEmission(caller address) {106 AssertIsAuthorized(prbac.ROLE_EMISSION.String(), caller)107}108109// AssertIsProtocolFee panics unless caller is the configured protocol-fee address.110//111// Parameters:112// - caller: address whose authorization is checked against the protocol-fee role113func AssertIsProtocolFee(caller address) {114 AssertIsAuthorized(prbac.ROLE_PROTOCOL_FEE.String(), caller)115}116117// AssertIsGovXGNS panics unless caller is the configured xGNS governance address.118//119// Parameters:120// - caller: address whose authorization is checked against the xGNS governance role121func AssertIsGovXGNS(caller address) {122 AssertIsAuthorized(prbac.ROLE_XGNS.String(), caller)123}124125// AssertIsAuthorized panics if caller does not have the specified role or if the role is absent.126//127// Parameters:128// - roleName: role identifier whose configured address is required129// - caller: address that must match the configured address for roleName130func AssertIsAuthorized(roleName string, caller address) {131 addr, ok := GetAddress(roleName)132 if !ok {133 panic(ufmt.Errorf(errRoleNotFound, roleName))134 }135136 if caller != addr {137 panic(ufmt.Errorf(errUnauthorized, caller, roleName))138 }139}140141// AssertHasAnyRole checks roleNames in order and panics unless caller matches one.142// It panics immediately if a checked role is absent, even if a later role might match.143//144// Parameters:145// - caller: address compared against each configured role address146// - roleNames: ordered role identifiers to check; each missing role causes a panic147func AssertHasAnyRole(caller address, roleNames ...string) {148 for _, roleName := range roleNames {149 addr, ok := GetAddress(roleName)150 if !ok {151 panic(ufmt.Errorf(errRoleNotFound, roleName))152 }153154 if caller == addr {155 return156 }157 }158159 panic(ufmt.Errorf(errUnauthorizedAnyRole, caller, roleNames))160}161162// AssertIsValidAddress panics if addr is not a valid address.163//164// Parameters:165// - addr: address value to validate166func AssertIsValidAddress(addr address) {167 if !addr.IsValid() {168 panic(ufmt.Errorf(errInvalidAddressShort, addr))169 }170}171172// assertIsRBAC panics if the caller is not the RBAC contract.173// Used internally to protect role management functions.174func assertIsRBAC(caller address) {175 rbacAddress := chain.PackageAddress(rbacPackagePath)176177 if caller != rbacAddress {178 panic(ufmt.Errorf(errUnauthorizedRBAC, caller))179 }180}181AssertHasAnyRole(caller string, roleNames ...string)
AssertIsAdmin(caller string)
AssertIsAdminOrGovernance(caller string)
AssertIsAuthorized(roleName string, caller string)
AssertIsEmission(caller string)
AssertIsGovernance(caller string)
AssertIsGovStaker(caller string)
AssertIsGovXGNS(caller string)
AssertIsLaunchpad(caller string)
AssertIsPool(caller string)
AssertIsPosition(caller string)
AssertIsProtocolFee(caller string)
AssertIsRlmCurrent(int, rlm interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string})
AssertIsRouter(caller string)
AssertIsStaker(caller string)
AssertIsValidAddress(addr string)
GetAddress(role string) (string, bool)
GetRoleAddresses() map[string].uverse.address
IsAuthorized(role string, caller string) bool
MustGetAddress(role string) string
RemoveRole(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, roleName string)
SetRoleAddress(cur interface {.seal func(); Address func() .uverse.address; IsCode func() bool; IsCurrent func() bool; IsEphemeral func() bool; IsUser func() bool; IsUserCall func() bool; IsUserRun func() bool; PkgPath func() string; Previous func() .uverse.realm; String func() string; Sub func(string) .uverse.realm; Subpath func() string}, roleName string, roleAddress string)
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
Render unavailable
rate limit exceeded — the render query is served by the Gnoland archive RPC.
vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.