Skip to content
Lattice

AccessControlLib

Git Source

Title: Access Control Library

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/AccessControl.sol)

A library for implementing access control in smart contracts.

Functions

accessControlStorage

function accessControlStorage() internal pure returns (AccessControlStorage storage $);

Returns

NameTypeDescription
$AccessControlStorage

onlyRole

Modifier that checks that an account has a specific role.

Reverts with an AccessControlUnauthorizedAccount error including the required role.

modifier onlyRole(bytes32 role);

Parameters

NameTypeDescription
rolebytes32The role identifier required to execute the guarded code.

registerInterface

Registers support for the IAccessControl interface via ERC165.

Sets the interface ID mapping in storage to true for ERC165 detection.

function registerInterface() internal;

__AccessControl_init

Initializes the AccessControl module with a given admin address.

Can only be called during initialization phase. Requires InitializableLib context.

function __AccessControl_init(address _admin) internal;

Parameters

NameTypeDescription
_adminaddressThe address to be granted the DEFAULT_ADMIN_ROLE.

hasRole

Checks whether a specific account has been granted a role.

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

Parameters

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

Returns

NameTypeDescription
<none>boolbool True if the account has the role, false otherwise.

checkRole

Checks if the caller has a specific role and reverts if not.

Uses msg.sender to get the caller. Reverts with AccessControlUnauthorizedAccount if not authorized.

function checkRole(bytes32 _role) internal view;

Parameters

NameTypeDescription
_rolebytes32The required role identifier.

checkRole

Checks if a specific account has a role and reverts if not.

Reverts with an AccessControlUnauthorizedAccount error if the account lacks the role.

function checkRole(bytes32 _role, address _account) internal view;

Parameters

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

getRoleAdmin

Retrieves the admin role that controls access to a specific role.

function getRoleAdmin(bytes32 _role) internal view returns (bytes32);

Parameters

NameTypeDescription
_rolebytes32The role identifier to query.

Returns

NameTypeDescription
<none>bytes32bytes32 The admin role. Use grantRole or revokeRole to modify admin privileges.
To change a role's admin, use setRoleAdmin.

grantRole

Grants a role to an account.

Only callable by accounts holding the admin role for the target role. May emit a RoleGranted event if the role wasn't previously held by the account. Requirements: the caller must have the admin role of the target role.

function grantRole(bytes32 role, address account) internal onlyRole(getRoleAdmin(role));

Parameters

NameTypeDescription
rolebytes32The role identifier to grant.
accountaddressThe account address to grant the role to.

revokeRole

Revokes a role from an account.

Only callable by accounts holding the admin role for the target role. May emit a RoleRevoked event if the account currently holds the role. Requirements: the caller must have the admin role of the target role.

function revokeRole(bytes32 role, address account) internal onlyRole(getRoleAdmin(role));

Parameters

NameTypeDescription
rolebytes32The role identifier to revoke.
accountaddressThe account address to revoke the role from.

renounceRole

Revokes a role from the calling account.

Allows accounts to lose privileges if compromised (e.g., misplaced keys or compromised devices). May emit a RoleRevoked event if the caller currently holds the role. Requirements: the callerConfirmation parameter must match the msg.sender for security.

function renounceRole(bytes32 role, address callerConfirmation) internal;

Parameters

NameTypeDescription
rolebytes32The role identifier to renounce.
callerConfirmationaddressThe caller's address as a confirmation parameter.

setRoleAdmin

Sets a new admin role for a specific role, gated on the role's current admin.

Reverts AccessControlUnauthorizedAccount unless the caller holds the role's current admin role, then delegates to _setRoleAdmin. Emits a RoleAdminChanged event.

function setRoleAdmin(bytes32 role, bytes32 adminRole) internal;

Parameters

NameTypeDescription
rolebytes32The role identifier to modify.
adminRolebytes32The new admin role that will control access to the target role.

_setRoleAdmin

Internal, UNGATED admin-role setter (mirrors OpenZeppelin's _setRoleAdmin).

Has no access restrictions — callers are responsible for gating (e.g. the public setRoleAdmin wrapper, or a module initializer running in a privileged bootstrap window). Used during initialization to pin a role's admin (e.g. making a role self-administered) before any external grant/revoke is possible. Emits a RoleAdminChanged event.

function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal;

Parameters

NameTypeDescription
rolebytes32The role identifier to modify.
adminRolebytes32The new admin role that will control access to the target role.

_grantRole

Internal function to grant a role to an account.

Internal function without access restrictions. Any caller can execute this. May emit a RoleGranted event.

function _grantRole(bytes32 role, address account) internal returns (bool);

Parameters

NameTypeDescription
rolebytes32The role identifier to grant.
accountaddressThe account address to grant the role to.

Returns

NameTypeDescription
<none>boolbool True if the role was granted, false if the account already held it.

_revokeRole

Internal function to revoke a role from an account.

Internal function without access restrictions. Any caller can execute this. May emit a RoleRevoked event.

function _revokeRole(bytes32 role, address account) internal returns (bool);

Parameters

NameTypeDescription
rolebytes32The role identifier to revoke.
accountaddressThe account address to revoke the role from.

Returns

NameTypeDescription
<none>boolbool True if the role was revoked, false if the account didn't hold it.