OwnableAccessControlUpgradeable
Inherits: OwnableUpgradeable
Author: transientlabs.xyz
Single owner, flexible access control mechanics
Can easily be extended by inheriting and applying additional roles
By default, only the owner can grant roles but by inheriting, but you may allow other roles to grant roles by using the internal helper.
State Variables
OwnableAccessControlStorageLocation
bytes32 private constant OwnableAccessControlStorageLocation =
0x0d0469b3d32e63681b9fc586a5627ad5e70b3d1ad20f31767e4b6c4141c7e300;
Functions
_getOwnableAccessControlStorage
function _getOwnableAccessControlStorage() private pure returns (OwnableAccessControlStorage storage $);
onlyRole
modifier onlyRole(bytes32 role);
onlyRoleOrOwner
modifier onlyRoleOrOwner(bytes32 role);
__OwnableAccessControl_init
function __OwnableAccessControl_init(address initOwner) internal onlyInitializing;
Parameters
Name | Type | Description |
---|---|---|
initOwner | address | The address of the initial owner |
__OwnableAccessControl_init_unchained
function __OwnableAccessControl_init_unchained() internal onlyInitializing;
revokeAllRoles
Function to revoke all roles currently present
Increments the _c
variables
Requires owner privileges
function revokeAllRoles() external onlyOwner;
renounceRole
Function to renounce role
function renounceRole(bytes32 role) external;
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | Bytes32 role created in inheriting contracts |
setRole
Function to grant/revoke a role to an address
Requires owner to call this function but this may be further extended using the internal helper function in inheriting contracts
function setRole(bytes32 role, address[] memory roleMembers, bool status) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | Bytes32 role created in inheriting contracts |
roleMembers | address[] | List of addresses that should have roles attached to them based on status |
status | bool | Bool whether to remove or add roleMembers to the role |
hasRole
Function to see if an address is the owner
function hasRole(bytes32 role, address potentialRoleMember) public view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | Bytes32 role created in inheriting contracts |
potentialRoleMember | address | Address to check for role membership |
getRoleMembers
Function to get role members
function getRoleMembers(bytes32 role) public view returns (address[] memory);
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | Bytes32 role created in inheriting contracts |
_setRole
Helper function to set addresses for a role
function _setRole(bytes32 role, address[] memory roleMembers, bool status) internal;
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | Bytes32 role created in inheriting contracts |
roleMembers | address[] | List of addresses that should have roles attached to them based on status |
status | bool | Bool whether to remove or add roleMembers to the role |
Events
RoleChange
event RoleChange(address indexed from, address indexed user, bool indexed approved, bytes32 role);
AllRolesRevoked
event AllRolesRevoked(address indexed from);
Errors
NotSpecifiedRole
Does not have specified role
error NotSpecifiedRole(bytes32 role);
NotRoleOrOwner
Is not specified role or owner
error NotRoleOrOwner(bytes32 role);
Structs
OwnableAccessControlStorage
struct OwnableAccessControlStorage {
uint256 c;
mapping(uint256 => mapping(bytes32 => mapping(address => bool))) roleStatus;
mapping(uint256 => mapping(bytes32 => EnumerableSet.AddressSet)) roleMembers;
}