PathrockNetwork Gno Explorer
HomeBlocksTransactionsRealmsPackagesValidators

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/r/gnoswap/access/v1

Realm
Open in gnoweb ↗

Overview

Kind
Realm (renderable)
Name
v1
Namespace
gnoswap / access
Files
5 (README)(gnomod.toml)
Exported functions
22
Module
gno.land/r/gnoswap/access/v1
gno
0.9

Files (5)

  • README.mdmarkdown
  • gnomod.tomltoml
  • access.gnogno
  • assert.gnogno
  • errors.gnogno
access.gnogno
1package access23import (4	"chain"5	"strings"67	ufmt "gno.land/p/nt/ufmt/v0"8)910var roleAddresses map[string]address1112func init() {13	roleAddresses = make(map[string]address)14}1516// SetRoleAddress sets or updates a role's address.17// It trims surrounding whitespace from roleName, creates missing roles, and18// replaces the address for an existing role.19//20// Parameters:21//   - cur: current realm context; callers use cross(cur) when crossing into this realm22//   - roleName: role identifier; surrounding whitespace is ignored and an empty name panics23//   - roleAddress: non-empty, valid address to associate with roleName24//25// Only callable by the RBAC contract.26func SetRoleAddress(cur realm, roleName string, roleAddress address) {27	prev := cur.Previous()28	assertIsRBAC(prev.Address())2930	// capture old value for event31	oldAddr, _ := roleAddresses[strings.TrimSpace(roleName)]3233	if err := setRoleAddress(roleName, roleAddress); err != nil {34		panic(err)35	}3637	chain.Emit(38		"SetRoleAddress",39		"prevAddr", prev.Address().String(),40		"role", roleName,41		"prevRoleAddr", oldAddr.String(),42		"roleAddress", roleAddress.String(),43	)44}4546// setRoleAddress is the internal implementation of SetRoleAddress.47// Separated for testability.48func setRoleAddress(roleName string, roleAddress address) error {49	roleName = strings.TrimSpace(roleName)50	if roleName == "" {51		panic("role name cannot be empty")52	}5354	// Validate address55	if !roleAddress.IsValid() || roleAddress == address("") {56		return ufmt.Errorf(errInvalidAddress, roleName, roleAddress)57	}5859	roleAddresses[roleName] = roleAddress60	return nil61}6263// RemoveRole removes a role from the system after trimming its name.64//65// Parameters:66//   - cur: current realm context; callers use cross(cur) when crossing into this realm67//   - roleName: role identifier to trim and remove; an empty or unknown name panics68//69// Only callable by the RBAC contract.70func RemoveRole(cur realm, roleName string) {71	prev := cur.Previous()72	assertIsRBAC(prev.Address())7374	// Validate role name75	roleName = strings.TrimSpace(roleName)76	if roleName == "" {77		panic("role name cannot be empty")78	}7980	if _, ok := roleAddresses[roleName]; !ok {81		panic(ufmt.Errorf("role %s does not exist", roleName))82	}8384	delete(roleAddresses, roleName)8586	chain.Emit(87		"RemoveRole",88		"prevAddr", prev.Address().String(),89		"role", roleName,90	)91}9293// IsAuthorized reports whether caller is the address currently mapped to role.94//95// Parameters:96//   - role: role name to trim and look up97//   - caller: address to compare with the mapped role address98//99// Returns:100//   - authorized: true when role exists and caller matches its address; false when the role is absent or does not match101func IsAuthorized(role string, caller address) bool {102	addr, ok := GetAddress(role)103	if !ok {104		return false105	}106107	return caller == addr108}109110// GetAddress returns the address mapped to a role and whether that mapping exists.111//112// Parameters:113//   - role: role name to trim before lookup114//115// Returns:116//   - addr: mapped address, or the zero address when role is not present117//   - exists: true when role has a stored address; false otherwise118func GetAddress(role string) (address, bool) {119	role = strings.TrimSpace(role)120	addr, ok := roleAddresses[role]121	return addr, ok122}123124// GetRoleAddresses returns an independent map copy of all stored role addresses.125//126// Returns:127//   - roleAddresses: map from normalized role names to their configured addresses128func GetRoleAddresses() map[string]address {129	addresses := make(map[string]address)130131	for role, data := range roleAddresses {132		addresses[role] = data133	}134135	return addresses136}137138// MustGetAddress returns the address mapped to a role or panics if it is absent.139// Surrounding whitespace is ignored; an empty or unknown role is considered absent.140//141// Parameters:142//   - role: role name to trim and require in the role mapping143//144// Returns:145//   - addr: configured address for role146func MustGetAddress(role string) address {147	role = strings.TrimSpace(role)148	addr, ok := GetAddress(role)149	if !ok {150		panic(ufmt.Errorf(errRoleNotFound, role))151	}152153	return addr154}155

Functions

  • AssertHasAnyRole(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.

Rendered

RenderedRawgnoweb ↗
This realm does not provide renderable output (vm/qrender → NoRenderDeclError). View on gnoweb ↗

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.