rbac

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultAdminRole = 0x00
)

Variables

View Source
var (
	OpcodeRoleGranted = tvm.MustExtractMagic(reflect.TypeOf(RoleGranted{}))
	OpcodeRoleRevoked = tvm.MustExtractMagic(reflect.TypeOf(RoleRevoked{}))
)
View Source
var GetRoleMember = tvm.Getter[GetRoleMemberArgs, *address.Address]{
	Name: "getRoleMember",
	Decoder: tvm.NewResultDecoder(func(r *ton.ExecutionResult) (*address.Address, error) {
		sAddr, err := r.Slice(0)
		if err != nil {
			return nil, fmt.Errorf("error decoding getRoleMember result: %w", err)
		}

		addr, err := sAddr.LoadAddr()
		if err != nil {
			return nil, fmt.Errorf("error decoding getRoleMember result slice: %w", err)
		}
		return addr, nil
	}),
}
View Source
var GetRoleMemberCount = tvm.Getter[*big.Int, uint64]{
	Name: "getRoleMemberCount",
	Decoder: tvm.NewResultDecoder(func(r *ton.ExecutionResult) (uint64, error) {
		rs, err := r.Int(0)
		if err != nil {
			return 0, fmt.Errorf("error decoding getRoleMemberCount result: %w", err)
		}

		return rs.Uint64(), nil
	}),
}
View Source
var TLBs = tvm.MustNewTLBMap([]any{
	GrantRole{},
	RevokeRole{},
	RenounceRole{},
	RoleGranted{},
	RoleRevoked{},
	RoleAdminChanged{},
}).MustWithStorageType(Data{})

Functions

func GetRoleMembersView

func GetRoleMembersView(ctx context.Context, client ton.APIClientWrapped, addr *address.Address, role *big.Int) ([]*address.Address, error)

GetRoleMembersView retrieves all addresses assigned to a specific role in the RBAC contract.

Types

type Data

type Data struct {
	// Roles mapping
	Roles *tlbe.Dict[*tlbe.Uint256, RoleData] `tlb:"."`
}

AccessControl data struct, auto-serialized to/from cell.

type ExitCode

type ExitCode tvm.ExitCode
const (
	ErrorUnauthorizedAccount ExitCode = iota + 60900 // Facility ID * 100
	ErrorBadConfirmation
)

func (ExitCode) NewFrom

func (ExitCode) NewFrom(ec tvm.ExitCode) (ExitCode, error)

func (ExitCode) String

func (i ExitCode) String() string

type GetRoleMemberArgs

type GetRoleMemberArgs struct {
	Role  *big.Int
	Index uint64
}

type GrantRole

type GrantRole struct {

	// Query ID of the change request.
	QueryID uint64 `tlb:"## 64"`

	Role    *tlbe.Uint256    `tlb:"."`    // Role definition.
	Account *address.Address `tlb:"addr"` // New account to add.
	// contains filtered or unexported fields
}

@dev Grants `role` to `account`.

If `account` had not been already granted `role`, emits a {AccessControl_RoleGranted} event.

Requirements:

- the caller must have `role`'s admin role.

May emit a {AccessControl_RoleGranted} event.

type RenounceRole

type RenounceRole struct {

	// Query ID of the change request.
	QueryID uint64 `tlb:"## 64"`

	Role               *tlbe.Uint256    `tlb:"."`    // Role definition.
	CallerConfirmation *address.Address `tlb:"addr"` // Account to revoke.
	// contains filtered or unexported fields
}

@dev Revokes `role` from the calling account.

Roles are often managed via {AccessControl_GrantRole} and {AccessControl_RevokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced).

If `account` had been granted `role`, emits a {AccessControl_RoleRevoked} event.

Requirements:

- the caller must be `callerConfirmation`.

May emit a {AccessControl_RoleRevoked} event.

type RevokeRole

type RevokeRole struct {

	// Query ID of the change request.
	QueryID uint64 `tlb:"## 64"`

	Role    *tlbe.Uint256    `tlb:"."`    // Role definition.
	Account *address.Address `tlb:"addr"` // Account to revoke.
	// contains filtered or unexported fields
}

@dev Revokes `role` from `account`.

If `account` had been granted `role`, emits a {AccessControl_RoleRevoked} event.

Requirements:

- the caller must have `role`'s admin role.

May emit a {AccessControl_RoleRevoked} event.

type RoleAdminChanged

type RoleAdminChanged struct {

	// Query ID of the change request.
	QueryID uint64 `tlb:"## 64"`

	Role              *tlbe.Uint256 `tlb:"."` // Role definition.
	PreviousAdminRole *tlbe.Uint256 `tlb:"."` // Previous admin role of the specific role.
	NewAdminRole      *tlbe.Uint256 `tlb:"."` // New admin role of the specific role.
	// contains filtered or unexported fields
}

@dev Emitted when `newAdminRole` is set as “role“'s admin role, replacing `previousAdminRole`

`DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite {AccessControl_RoleAdminChanged} not being emitted to signal this.

type RoleData

type RoleData struct {
	AdminRole *tlbe.Uint256 `tlb:"."`
	// Number of members in the role
	MembersLen uint64 `tlb:"## 64"`
	// Members of the role, indexed by their address hash.
	HasRole *tlbe.Dict[common.AddressWrap, bool] `tlb:"."`
}

Internal storage struct for role data

Each role has a mapping of accounts that have been granted that role, and an admin role that can manage that role.

type RoleGranted

type RoleGranted struct {

	// Query ID of the change request.
	QueryID uint64 `tlb:"## 64"`

	Role    *tlbe.Uint256    `tlb:"."`    // Role definition.
	Account *address.Address `tlb:"addr"` // New account added.
	Sender  *address.Address `tlb:"addr"` // Account that requested the change.
	// contains filtered or unexported fields
}

@dev Emitted when `account` is granted `role`.

`sender` is the account that originated the contract call. This account bears the admin role (for the granted role). Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.

type RoleRevoked

type RoleRevoked struct {

	// Query ID of the change request.
	QueryID uint64 `tlb:"## 64"`

	Role    *tlbe.Uint256    `tlb:"."`    // Role definition.
	Account *address.Address `tlb:"addr"` // Account revoked.
	Sender  *address.Address `tlb:"addr"` // Account that requested the change.
	// contains filtered or unexported fields
}

@dev Emitted when `account` is revoked `role`.

`sender` is the account that originated the contract call:

  • if using `revokeRole`, it is the admin role bearer

- if using `renounceRole`, it is the role bearer (i.e. `account`)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL