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

v0 source pure

Package manager is a pure port of the core permission model of OpenZeppelin Contracts AccessManager v5.6.1, taken fro...

Overview

Package manager is a pure port of the core permission model of OpenZeppelin Contracts AccessManager v5.6.1, taken from gno.land/p/onbloc/access/manager (github.com/onbloc/gno-ibc, Apache-2.0).

It is a state transition library, not a realm: it does not own storage, inspect realms, or decide who the caller is. A realm stores a State, passes the caller address, target, and selector into its methods, and exposes the management API it needs (see gno.land/r/gnoswap/order/keeper).

Model:

  • roles are uint64 identifiers; AdminRole is 0 and PublicRole is uint64 max, which every account holds;
  • permissions are scoped by target and selector; an unset selector defaults to AdminRole;
  • a closed target rejects every call;
  • each role has an admin role, a grant delay, and member records with an activation time.

Delayed operation scheduling (schedule, execute, cancel) is not ported. Panics carry string messages so they can cross realm boundaries.

Constants 3

const AdminRole, PublicRole, MinSetback

1const (
2	AdminRole  RoleId = 0
3	PublicRole RoleId = 1<<64 - 1 // uint64 max
4
5	// MinSetback is the minimum setback for a grant delay change (5 days).
6	// OpenZeppelin: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/5fd1781b1454fd1ef8e722282f86f9293cacf256/contracts/access/manager/AccessManager.sol#L164-L166
7	MinSetback uint32 = 5 * 24 * 60 * 60
8)
source

const EventTypeRoleLabel, EventTypeRoleGranted, EventTypeRoleRevoked, EventTypeRoleAdminChanged, EventTypeRoleGrantDelayChanged, EventTypeTargetClosed, EventTypeTargetFunctionRoleUpdated

1const (
2	EventTypeRoleLabel                 = "RoleLabel"
3	EventTypeRoleGranted               = "RoleGranted"
4	EventTypeRoleRevoked               = "RoleRevoked"
5	EventTypeRoleAdminChanged          = "RoleAdminChanged"
6	EventTypeRoleGrantDelayChanged     = "RoleGrantDelayChanged"
7	EventTypeTargetClosed              = "TargetClosed"
8	EventTypeTargetFunctionRoleUpdated = "TargetFunctionRoleUpdated"
9)
source

const AttributeKeyTarget, AttributeKeyRoleID, AttributeKeyLabel, AttributeKeyAccount, AttributeKeyDelay, AttributeKeySince, AttributeKeyNewMember, AttributeKeyAdmin, AttributeKeyClosed, AttributeKeySelector

 1const (
 2	AttributeKeyTarget    = "target"
 3	AttributeKeyRoleID    = "role_id"
 4	AttributeKeyLabel     = "label"
 5	AttributeKeyAccount   = "account"
 6	AttributeKeyDelay     = "delay"
 7	AttributeKeySince     = "since"
 8	AttributeKeyNewMember = "new_member"
 9	AttributeKeyAdmin     = "admin"
10	AttributeKeyClosed    = "closed"
11	AttributeKeySelector  = "selector"
12)
source

Functions 13

Types 10

type Access

struct
1type Access struct {
2	Since TimePoint
3}
source

type Delay

struct
1type Delay struct {
2	effectDate  TimePoint
3	valueBefore uint32
4	valueAfter  uint32
5}
source

Delay is a value that changes only after a setback, mirroring OpenZeppelin's packed `Delay` type. OpenZeppelin: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/5fd1781b1454fd1ef8e722282f86f9293cacf256/contracts/utils/types/Time.sol#L61

Methods on Delay

func WithUpdate

method on Delay
1func (d Delay) WithUpdate(timestamp TimePoint, newDelay uint32, minSetback uint32) (Delay, TimePoint)
source

WithUpdate schedules newDelay to take effect at timestamp plus a setback: at least minSetback, or longer when newDelay decreases the active value by more than minSetback. Returns the updated Delay and the effect timePoint. OpenZeppelin: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/5fd1781b1454fd1ef8e722282f86f9293cacf256/contracts/utils/types/Time.sol#L103-L112

type RoleConfig

struct
1type RoleConfig struct {
2	Members    map[address]Access
3	Admin      RoleId
4	GrantDelay Delay
5}
source

type RoleId

ident
1type RoleId uint64
source

Methods on RoleId

func String

method on RoleId
1func (r RoleId) String() string
source

func Uint64

method on RoleId
1func (r RoleId) Uint64() uint64
source

type State

struct
1type State struct {
2	Roles   map[RoleId]*RoleConfig
3	Targets map[string]*TargetConfig
4}
source

Methods on State

func CanCall

method on State
1func (state *State) CanCall(caller address, target string, selector Selector) CanCallResult
source

CanCall reports whether caller can call target selector immediately. This Gno port returns only immediate authorization because scheduled execution and execution delay are intentionally not ported. OpenZeppelin reference: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/5fd1781b1454fd1ef8e722282f86f9293cacf256/contracts/access/manager/AccessManager.sol#L140-L156

func CanManageTarget

method on State
1func (state *State) CanManageTarget(caller address) CanCallResult
source

func GetRoleGrantDelayEffect

method on State
1func (state *State) GetRoleGrantDelayEffect(role RoleId) TimePoint
source

GetRoleGrantDelayEffect returns when role's scheduled grant delay change takes effect. No OpenZeppelin equivalent; added to avoid direct field access.

func GrantRole

method on State
1func (state *State) GrantRole(role RoleId, account address) bool
source

func RevokeRole

method on State
1func (state *State) RevokeRole(role RoleId, account address) bool
source

func SetGrantDelay

method on State
1func (state *State) SetGrantDelay(role RoleId, newDelay uint32)
source

SetGrantDelay schedules newDelay behind a setback; it never overwrites the active delay on the spot. Callers read GetRoleGrantDelay for the current value or GetRoleGrantDelayEffect for the effect timePoint. AdminRole is not locked here (unlike SetRoleAdmin) — OpenZeppelin only rejects PublicRole. OpenZeppelin: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/5fd1781b1454fd1ef8e722282f86f9293cacf256/contracts/access/manager/AccessManager.sol#L262-L264,L362-L371

func SetRoleAdmin

method on State
1func (state *State) SetRoleAdmin(role RoleId, admin RoleId)
source

func SetTargetClosed

method on State
1func (state *State) SetTargetClosed(target string, closed bool)
source

type TargetConfig

struct
1type TargetConfig struct {
2	FunctionRoles map[Selector]RoleId
3	Closed        bool
4}
source

type TimePoint

ident
1type TimePoint int64
source

Methods on TimePoint

func After

method on TimePoint
1func (t TimePoint) After(other TimePoint) bool
source

func Before

method on TimePoint
1func (t TimePoint) Before(other TimePoint) bool
source

func Equal

method on TimePoint
1func (t TimePoint) Equal(other TimePoint) bool
source

func Int64

method on TimePoint
1func (t TimePoint) Int64() int64
source

func IsZero

method on TimePoint
1func (t TimePoint) IsZero() bool
source

func String

method on TimePoint
1func (t TimePoint) String() string
source

Dependencies

Source Files 13