A contract module which provides a set if internal functions for implementing role control features.
bytes32 ROLES_PREFIX
bytes32 PROPOSE_ROLES_PREFIX
modifier onlyRole(uint8 role)
Modifier that throws an error if called by any account missing the role.
modifier withEveryRole(uint8[] roles)
Modifier that throws an error if called by an account without all the roles.
modifier withAnyRole(uint8[] roles)
Modifier that throws an error if called by an account without any of the roles.
function hasRole(address account, uint8 role) public view returns (bool)
Checks if an account has a role.
Name | Type | Description |
---|---|---|
account | address | The address to check |
role | uint8 | The role to check |
Name | Type | Description |
---|---|---|
[0] | bool | True if the account has the role, false otherwise |
function _toAccountRoles(uint8[] roles) internal pure returns (uint256)
Internal function to convert an array of roles to a uint256.
Name | Type | Description |
---|---|---|
roles | uint8[] | The roles to convert |
Name | Type | Description |
---|---|---|
[0] | uint256 | accountRoles The roles in uint256 format |
function _rolesKey(address account) internal view virtual returns (bytes32 key)
Internal function to get the key of the roles mapping.
Name | Type | Description |
---|---|---|
account | address | The address to get the key for |
Name | Type | Description |
---|---|---|
key | bytes32 | The key of the roles mapping |
function _getRoles(address account) internal view returns (uint256 accountRoles)
Internal function to get the roles of an account.
Name | Type | Description |
---|---|---|
account | address | The address to get the roles for |
Name | Type | Description |
---|---|---|
accountRoles | uint256 | The roles of the account in uint256 format |
function _proposalKey(address fromAccount, address toAccount) internal view virtual returns (bytes32 key)
Internal function to get the key of the proposed roles mapping.
Name | Type | Description |
---|---|---|
fromAccount | address | The address of the current role |
toAccount | address | The address of the pending role |
Name | Type | Description |
---|---|---|
key | bytes32 | The key of the proposed roles mapping |
function _getProposedRoles(address fromAccount, address toAccount) internal view returns (uint256 proposedRoles_)
Internal function to get the proposed roles of an account.
Name | Type | Description |
---|---|---|
fromAccount | address | The address of the current role |
toAccount | address | The address of the pending role |
Name | Type | Description |
---|---|---|
proposedRoles_ | uint256 | The proposed roles of the account in uint256 format |
function _addRole(address account, uint8 role) internal
Internal function to add a role to an account.
emits a RolesAdded event.
Name | Type | Description |
---|---|---|
account | address | The address to add the role to |
role | uint8 | The role to add |
function _addRoles(address account, uint8[] roles) internal
Internal function to add roles to an account.
emits a RolesAdded event. Called in the constructor to set the initial roles.
Name | Type | Description |
---|---|---|
account | address | The address to add roles to |
roles | uint8[] | The roles to add |
function _addAccountRoles(address account, uint256 accountRoles) internal
Internal function to add roles to an account.
emits a RolesAdded event. Called in the constructor to set the initial roles.
Name | Type | Description |
---|---|---|
account | address | The address to add roles to |
accountRoles | uint256 | The roles to add |
function _removeRole(address account, uint8 role) internal
Internal function to remove a role from an account.
emits a RolesRemoved event.
Name | Type | Description |
---|---|---|
account | address | The address to remove the role from |
role | uint8 | The role to remove |
function _removeRoles(address account, uint8[] roles) internal
Internal function to remove roles from an account.
emits a RolesRemoved event.
Name | Type | Description |
---|---|---|
account | address | The address to remove roles from |
roles | uint8[] | The roles to remove |
function _removeAccountRoles(address account, uint256 accountRoles) internal
Internal function to remove roles from an account.
emits a RolesRemoved event.
Name | Type | Description |
---|---|---|
account | address | The address to remove roles from |
accountRoles | uint256 | The roles to remove |
function _hasRole(uint256 accountRoles, uint8 role) internal pure returns (bool)
Internal function to check if an account has a role.
Name | Type | Description |
---|---|---|
accountRoles | uint256 | The roles of the account in uint256 format |
role | uint8 | The role to check |
Name | Type | Description |
---|---|---|
[0] | bool | True if the account has the role, false otherwise |
function _hasAllTheRoles(uint256 hasAccountRoles, uint256 mustHaveAccountRoles) internal pure returns (bool)
Internal function to check if an account has all the roles.
Name | Type | Description |
---|---|---|
hasAccountRoles | uint256 | The roles of the account in uint256 format |
mustHaveAccountRoles | uint256 | The roles the account must have |
Name | Type | Description |
---|---|---|
[0] | bool | True if the account has all the roles, false otherwise |
function _hasAnyOfRoles(uint256 hasAccountRoles, uint256 mustHaveAnyAccountRoles) internal pure returns (bool)
Internal function to check if an account has any of the roles.
Name | Type | Description |
---|---|---|
hasAccountRoles | uint256 | The roles of the account in uint256 format |
mustHaveAnyAccountRoles | uint256 | The roles to check in uint256 format |
Name | Type | Description |
---|---|---|
[0] | bool | True if the account has any of the roles, false otherwise |
function _proposeRole(address fromAccount, address toAccount, uint8 role) internal
Internal function to propose to transfer roles of message sender to a new account.
Original account must have all the proposed roles. Emits a RolesProposed event. Roles are not transferred until the new role accepts the role transfer.
Name | Type | Description |
---|---|---|
fromAccount | address | The address of the current roles |
toAccount | address | The address to transfer roles to |
role | uint8 | The role to transfer |
function _proposeRoles(address fromAccount, address toAccount, uint8[] roles) internal
Internal function to propose to transfer roles of message sender to a new account.
Original account must have all the proposed roles. Emits a RolesProposed event. Roles are not transferred until the new role accepts the role transfer.
Name | Type | Description |
---|---|---|
fromAccount | address | The address of the current roles |
toAccount | address | The address to transfer roles to |
roles | uint8[] | The roles to transfer |
function _proposeAccountRoles(address fromAccount, address toAccount, uint256 accountRoles) internal
Internal function to propose to transfer roles of message sender to a new account.
Original account must have all the proposed roles. Emits a RolesProposed event. Roles are not transferred until the new role accepts the role transfer.
Name | Type | Description |
---|---|---|
fromAccount | address | The address of the current roles |
toAccount | address | The address to transfer roles to |
accountRoles | uint256 | The account roles to transfer |
function _acceptRole(address fromAccount, address toAccount, uint8 role) internal virtual
Internal function to accept roles transferred from another account.
Pending account needs to pass all the proposed roles. Emits RolesRemoved and RolesAdded events.
Name | Type | Description |
---|---|---|
fromAccount | address | The address of the current role |
toAccount | address | |
role | uint8 | The role to accept |
function _acceptRoles(address fromAccount, address toAccount, uint8[] roles) internal virtual
Internal function to accept roles transferred from another account.
Pending account needs to pass all the proposed roles. Emits RolesRemoved and RolesAdded events.
Name | Type | Description |
---|---|---|
fromAccount | address | The address of the current role |
toAccount | address | |
roles | uint8[] | The roles to accept |
function _acceptAccountRoles(address fromAccount, address toAccount, uint256 accountRoles) internal virtual
Internal function to accept roles transferred from another account.
Pending account needs to pass all the proposed roles. Emits RolesRemoved and RolesAdded events.
Name | Type | Description |
---|---|---|
fromAccount | address | The address of the current role |
toAccount | address | |
accountRoles | uint256 | The account roles to accept |
function _transferRole(address fromAccount, address toAccount, uint8 role) internal
Internal function to transfer roles from one account to another.
Original account must have all the proposed roles.
Name | Type | Description |
---|---|---|
fromAccount | address | The address of the current role |
toAccount | address | The address to transfer role to |
role | uint8 | The role to transfer |
function _transferRoles(address fromAccount, address toAccount, uint8[] roles) internal
Internal function to transfer roles from one account to another.
Original account must have all the proposed roles.
Name | Type | Description |
---|---|---|
fromAccount | address | The address of the current role |
toAccount | address | The address to transfer role to |
roles | uint8[] | The roles to transfer |
function _transferAccountRoles(address fromAccount, address toAccount, uint256 accountRoles) internal
Internal function to transfer roles from one account to another.
Original account must have all the proposed roles.
Name | Type | Description |
---|---|---|
fromAccount | address | The address of the current role |
toAccount | address | The address to transfer role to |
accountRoles | uint256 | The account roles to transfer |