Git Source
OzAccessControl
A middleware extension that implements role-based access control
Implements AccessManager with role-based access control functionality
Methods
__OzAccessControl_init
function __OzAccessControl_init(
address defaultAdmin
) internal onlyInitializing
Initializes the contract with a default admin
Parameters
Name | Type | Description |
---|
defaultAdmin | address | The address to set as the default admin |
hasRole
function hasRole(bytes32 role, address account) public view virtual returns (bool)
Returns true if account has been granted role
Parameters
Name | Type | Description |
---|
role | bytes32 | The role to check |
account | address | The account to check |
Returns
Name | Type | Description |
---|
| bool | bool True if account has role |
getRoleAdmin
function getRoleAdmin(
bytes32 role
) public view virtual returns (bytes32)
Returns the admin role that controls the specified role
Parameters
Name | Type | Description |
---|
role | bytes32 | The role to get the admin for |
Returns
Name | Type | Description |
---|
| bytes32 | bytes32 The admin role |
getRole
function getRole(
bytes4 selector
) public view virtual returns (bytes32)
Returns the role required for a function selector
Parameters
Name | Type | Description |
---|
selector | bytes4 | The function selector |
Returns
Name | Type | Description |
---|
| bytes32 | bytes32 The required role |
grantRole
function grantRole(bytes32 role, address account) public virtual
Grants role to account if caller has admin role
Parameters
Name | Type | Description |
---|
role | bytes32 | The role to grant |
account | address | The account to grant the role to |
revokeRole
function revokeRole(bytes32 role, address account) public virtual
Revokes role from account if caller has admin role
Parameters
Name | Type | Description |
---|
role | bytes32 | The role to revoke |
account | address | The account to revoke the role from |
renounceRole
function renounceRole(bytes32 role, address callerConfirmation) public virtual
Allows an account to renounce a role they have
Parameters
Name | Type | Description |
---|
role | bytes32 | The role to renounce |
callerConfirmation | address | Address of the caller for confirmation |
_setSelectorRole
function _setSelectorRole(bytes4 selector, bytes32 role) internal virtual
Sets the role required for a function selector
Parameters
Name | Type | Description |
---|
selector | bytes4 | The function selector |
role | bytes32 | The required role |
_setRoleAdmin
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual
Sets the admin role for a role
Parameters
Name | Type | Description |
---|
role | bytes32 | The role to set admin for |
adminRole | bytes32 | The new admin role |
_grantRole
function _grantRole(bytes32 role, address account) internal virtual returns (bool)
Grants a role
Parameters
Name | Type | Description |
---|
role | bytes32 | The role to grant |
account | address | The account to grant the role to |
Returns
Name | Type | Description |
---|
| bool | bool True if role was granted |
_revokeRole
function _revokeRole(bytes32 role, address account) internal virtual returns (bool)
Revokes a role
Parameters
Name | Type | Description |
---|
role | bytes32 | The role to revoke |
account | address | The account to revoke the role from |
Returns
Name | Type | Description |
---|
| bool | bool True if role was revoked |
_checkAccess
function _checkAccess() internal view virtual override
Checks access based on role required for the function selector
Implements BaseMiddleware's _checkAccess function