Skip to main content

AccessControlRead

Asset Tokenization Studio Team

AccessControlRead

Read-only base for AccessControlBase (and, through it, AccessControl and AccessControlOperational). Implements all view functions of IAccessControl. Write functions are implemented once in AccessControlBase and exposed by the two subclasses with the guard modifiers appropriate to a proxy facet or a direct-inheritance contract.

Methods​

applyRoles​

function applyRoles(bytes32[] _roles, bool[] _actives, address _account) external nonpayable

Applies multiple role grants or revocations to an account in a single transaction.

The caller must hold the admin role for each role in _roles (checked per entry in the storage layer). _roles and _actives must have equal length and contain no duplicate role entries. Grant entries where the account already holds the role and revoke entries where it does not are silently skipped. Emits RolesApplied with the subset that effectively changed state.

Parameters​

NameTypeDescription
_rolesbytes32[]Array of role identifiers to process.
_activesbool[]Corresponding flags; true grants the role, false revokes it.
_accountaddressThe account to which roles are applied.

getRoleCountFor​

function getRoleCountFor(address _account) external view returns (uint256 roleCount_)

Returns the number of roles currently assigned to an account.

Parameters​

NameTypeDescription
_accountaddressThe account to query.

Returns​

NameTypeDescription
roleCount_uint256The number of roles held by _account.

getRoleMemberCount​

function getRoleMemberCount(bytes32 _role) external view returns (uint256 memberCount_)

Returns the number of accounts currently holding a role.

Parameters​

NameTypeDescription
_rolebytes32The role identifier to query.

Returns​

NameTypeDescription
memberCount_uint256The number of accounts assigned to _role.

getRoleMembers​

function getRoleMembers(bytes32 _role, uint256 _pageIndex, uint256 _pageLength) external view returns (address[] members_)

Returns a paginated slice of accounts holding a role.

_The list offset is computed as \_pageIndex _ \_pageLength. Returns an empty array when the offset meets or exceeds the member count for the role.*

Parameters​

NameTypeDescription
_rolebytes32The role identifier to query.
_pageIndexuint256Zero-based page index.
_pageLengthuint256Maximum number of addresses to return per page.

Returns​

NameTypeDescription
members_address[]Array of account addresses holding _role for the requested page.

getRolesFor​

function getRolesFor(address _account, uint256 _pageIndex, uint256 _pageLength) external view returns (bytes32[] roles_)

Returns a paginated slice of roles assigned to an account.

_The list offset is computed as \_pageIndex _ \_pageLength. Returns an empty array when the offset meets or exceeds the role count for the account.*

Parameters​

NameTypeDescription
_accountaddressThe account to query.
_pageIndexuint256Zero-based page index.
_pageLengthuint256Maximum number of roles to return per page.

Returns​

NameTypeDescription
roles_bytes32[]Array of role identifiers held by _account for the requested page.

grantRole​

function grantRole(bytes32 _role, address _account) external nonpayable returns (bool success_)

Grants a role to an account.

The caller must hold the admin role of _role (resolved dynamically via getRoleAdmin). Reverts with AccountAssignedToRole if the account already holds the role. Emits RoleGranted.

Parameters​

NameTypeDescription
_rolebytes32The role identifier to grant.
_accountaddressThe account to receive the role.

Returns​

NameTypeDescription
success_boolTrue if the role was successfully granted.

hasRole​

function hasRole(bytes32 _role, address _account) external view returns (bool)

Checks whether an account holds a specific role.

Parameters​

NameTypeDescription
_rolebytes32The role identifier to check.
_accountaddressThe account to check.

Returns​

NameTypeDescription
_0boolTrue if _account holds _role, false otherwise.

initializeAccessControl​

function initializeAccessControl() external nonpayable

Initialises the AccessControl capability on the token.

Callable once; subsequent calls revert with FacetAlreadyRegistered. Requires DEFAULT_ADMIN_ROLE. Called by the factory during deployment.

renounceRole​

function renounceRole(bytes32 _role) external nonpayable returns (bool success_)

Allows the caller to renounce a role held by their own account.

Operates on msg.sender only; no admin role is required. Reverts with AccountNotAssignedToRole if the caller does not hold the role. Emits RoleRenounced.

Parameters​

NameTypeDescription
_rolebytes32The role identifier to renounce.

Returns​

NameTypeDescription
success_boolTrue if the role was successfully renounced.

revokeRole​

function revokeRole(bytes32 _role, address _account) external nonpayable returns (bool success_)

Revokes a role from an account.

The caller must hold the admin role of _role (resolved dynamically via getRoleAdmin). Reverts with AccountNotAssignedToRole if the account does not hold the role. Emits RoleRevoked.

Parameters​

NameTypeDescription
_rolebytes32The role identifier to revoke.
_accountaddressThe account to lose the role.

Returns​

NameTypeDescription
success_boolTrue if the role was successfully revoked.

Events​

AccessControlInitialized​

event AccessControlInitialized()

Emitted once when the AccessControl capability is initialised on a token.

Fires exclusively from initializeAccessControl after the registration succeeds.

EffectivelyRolesApplied​

event EffectivelyRolesApplied(bytes32[] roles, bool[] actives)

Emitted when one or more role changes are effectively applied.

roles and actives are parallel arrays containing the role states that resulted in effective storage mutations.

Parameters​

NameTypeDescription
rolesbytes32[]The roles whose assigned state changed.
activesbool[]The effective state applied to each role; true granted and false revoked.

RoleGranted​

event RoleGranted(address indexed operator, address indexed account, bytes32 indexed role)

Emitted when a role is granted to an account.

Parameters​

NameTypeDescription
operator indexedaddressThe address that performed the grant.
account indexedaddressThe account that received the role.
role indexedbytes32The role that was granted.

RoleRenounced​

event RoleRenounced(address indexed account, bytes32 indexed role)

Emitted when an account voluntarily renounces a role it holds.

Parameters​

NameTypeDescription
account indexedaddressThe account that renounced the role.
role indexedbytes32The role that was renounced.

RoleRevoked​

event RoleRevoked(address indexed operator, address indexed account, bytes32 indexed role)

Emitted when a role is revoked from an account.

Parameters​

NameTypeDescription
operator indexedaddressThe address that performed the revocation.
account indexedaddressThe account from which the role was revoked.
role indexedbytes32The role that was revoked.

RolesApplied​

event RolesApplied(bytes32[] roles, bool[] actives, address account)

Emitted when multiple role operations are requested for an account.

roles and actives are parallel arrays and must have the same length. Entries represent the requested role state changes, not necessarily only the effective storage mutations.

Parameters​

NameTypeDescription
rolesbytes32[]The roles processed by the batch operation.
activesbool[]The requested state for each role; true grants and false revokes.
accountaddressThe account for which the role operations are requested.

Errors​

AccountAssignedToRole​

error AccountAssignedToRole(bytes32 role, address account)

Thrown when attempting to grant a role to an account that already holds it.

Parameters​

NameTypeDescription
rolebytes32The role the account already holds.
accountaddressThe account already assigned to the role.

AccountHasNoRole​

error AccountHasNoRole(address account, bytes32 role)

Thrown when an account does not hold a required role.

Parameters​

NameTypeDescription
accountaddressThe account that lacks the role.
rolebytes32The role that is not held.

AccountHasNoRoles​

error AccountHasNoRoles(address account, bytes32[] roles)

Thrown when an account does not hold any of the specified roles.

Parameters​

NameTypeDescription
accountaddressThe account that lacks the roles.
rolesbytes32[]The roles that are not held.

AccountNotAssignedToRole​

error AccountNotAssignedToRole(bytes32 role, address account)

Thrown when attempting to revoke or renounce a role from an account that does not hold it.

Parameters​

NameTypeDescription
rolebytes32The role the account does not hold.
accountaddressThe account not assigned to the role.

CannotRenounceSoleAdmin​

error CannotRenounceSoleAdmin()

Thrown when the sole holder of DEFAULT_ADMIN_ROLE attempts to renounce it, which would permanently lock all admin-gated functions.

RolesAndActivesLengthMismatch​

error RolesAndActivesLengthMismatch(uint256 rolesLength, uint256 activesLength)

Thrown when the roles and actives arrays passed to applyRoles differ in length.

Parameters​

NameTypeDescription
rolesLengthuint256Length of the roles array.
activesLengthuint256Length of the actives array.