Solidity API
AccessControl
RoleData
struct RoleData {
struct EnumerableSet.AddressSet members;
bytes32 adminRole;
}
_roles
mapping(bytes32 => struct AccessControl.RoleData) _roles
DEFAULT_ADMIN_ROLE
bytes32 DEFAULT_ADMIN_ROLE
RoleGranted
event RoleGranted(bytes32 role, address account, address sender)
_Emitted when account
is granted role
.
sender
is the account that originated the contract call, an admin role
bearer except when using {setupRole}.
RoleRevoked
event RoleRevoked(bytes32 role, address account, address sender)
_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
)_
hasRole
function hasRole(bytes32 role, address account) public view returns (bool)
Returns true
if account
has been granted role
.
getRoleMemberCount
function getRoleMemberCount(bytes32 role) public view returns (uint256)
Returns the number of accounts that have role
. Can be used
together with {getRoleMember} to enumerate all bearers of a role.
getRoleMember
function getRoleMember(bytes32 role, uint256 index) public view returns (address)
_Returns one of the accounts that have role
. index
must be a
value between 0 and {getRoleMemberCount}, non-inclusive.
Role bearers are not sorted in any particular way, and their ordering may change at any point.
WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure you perform all queries on the same block. See the following https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] for more information._
getRoleMemberIndex
function getRoleMemberIndex(bytes32 role, address account) public view returns (uint256)
Returns the index of the account that have role
.
getRoleAdmin
function getRoleAdmin(bytes32 role) public view returns (bytes32)
_Returns the admin role that controls role
. See {grantRole} and
{revokeRole}.
To change a role's admin, use {setRoleAdmin}.
grantRole
function grantRole(bytes32 role, address account) public virtual
_Grants role
to account
.
If account
had not been already granted role
, emits a {RoleGranted}
event.
Requirements:
- the caller must have
role
's admin role._
revokeRole
function revokeRole(bytes32 role, address account) public virtual
_Revokes role
from account
.
If account
had been granted role
, emits a {RoleRevoked} event.
Requirements:
- the caller must have
role
's admin role._
renounceRole
function renounceRole(bytes32 role, address account) public virtual
_Revokes role
from the calling account.
Roles are often managed via {grantRole} and {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 the calling account had been granted role
, emits a {RoleRevoked}
event.
Requirements:
- the caller must be
account
._
_setupRole
function _setupRole(bytes32 role, address account) internal virtual
_Grants role
to account
.
If account
had not been already granted role
, emits a {RoleGranted}
event. Note that unlike {grantRole}, this function doesn't perform any
checks on the calling account.
[WARNING]
This function should only be called from the constructor when setting up the initial roles for the system.
Using this function in any other way is effectively circumventing the admin system imposed by {AccessControl}. ====_
_setRoleAdmin
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual
Sets adminRole
as role
's admin role.
_grantRole
function _grantRole(bytes32 role, address account) private
_revokeRole
function _revokeRole(bytes32 role, address account) private