Access Control Pausable Module
Manages role pausing and checks within a diamond
- Internal functions for role pausing and status checks, intended for use within custom facets.
- Utilizes diamond storage pattern via
ACCESS_CONTROL_STORAGE_POSITIONfor shared state. - Emits
RolePausedandRoleUnpausedevents for off-chain monitoring. - Reverts with custom errors
AccessControlRolePausedandAccessControlUnauthorizedAccount.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This module provides internal functions to pause and unpause specific roles, controlling whether accounts can perform actions associated with those roles. It leverages diamond storage for state management, ensuring that pausing decisions are universally visible across all facets interacting with the same storage. This enhances security by allowing temporary suspension of role-based operations.
Storage
AccessControlPausableStorage
Storage struct for AccessControlPausable. storage-location: erc8042:compose.accesscontrol.pausable
AccessControlStorage
Storage struct for AccessControl (reused struct definition). Must match the struct definition in AccessControlDataFacet / AccessControlDataMod. storage-location: erc8042:compose.accesscontrol
State Variables
| Property | Type | Description |
|---|---|---|
ACCESS_CONTROL_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol")) |
PAUSABLE_STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol.pausable")) |
Functions
getAccessControlStorage
Returns the storage for AccessControl.
Returns:
| Property | Type | Description |
|---|---|---|
s | AccessControlStorage | The AccessControl storage struct. |
getStorage
Returns the storage for AccessControlPausable.
Returns:
| Property | Type | Description |
|---|---|---|
s | AccessControlPausableStorage | The AccessControlPausable storage struct. |
isRolePaused
function to check if a role is paused.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to check. |
Returns:
| Property | Type | Description |
|---|---|---|
- | bool | True if the role is paused, false otherwise. |
pauseRole
function to pause a role.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to pause. |
requireRoleNotPaused
function to check if an account has a role and if the role is not paused. Notes: - Reverts with AccessControlUnauthorizedAccount If the account does not have the role. - Reverts with AccessControlRolePaused If the role is paused.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to check. |
_account | address | The account to check the role for. |
unpauseRole
function to unpause a role.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to unpause. |
Events
Errors
Best Practices
- Call
requireRoleNotPausedbefore executing role-dependent logic to enforce active role status. - Ensure the
AccessControlPausableModis correctly initialized with the diamond's storage pointer. - Handle
AccessControlRolePausedandAccessControlUnauthorizedAccounterrors when usingrequireRoleNotPausedin external-facing functions.
Integration Notes
This module interacts with diamond storage at the position identified by ACCESS_CONTROL_STORAGE_POSITION. It manages the paused state of roles within the AccessControlPausableStorage struct, which is shared across all facets. Functions like pauseRole and unpauseRole modify this shared state, making the changes immediately visible to any other facet that reads from the same storage position. The requireRoleNotPaused function reads this state to enforce restrictions.