Access Control Grant Module
Grant roles to accounts within a diamond
- Internal functions for role granting, suitable for custom facets.
- Leverages the diamond storage pattern for shared state management.
- Emits
RoleGrantedevent upon successful role assignment. - Reverts with
AccessControlUnauthorizedAccountif caller lacks admin rights.
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 for granting roles to specific accounts. Facets can import and utilize this module to manage role assignments using shared diamond storage. Changes to role assignments are immediately reflected across all facets that access the same storage.
Storage
AccessControlStorage
storage struct for the AccessControl. storage-location: erc8042:compose.accesscontrol
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("compose.accesscontrol")) |
Functions
getStorage
Returns the storage for the AccessControl.
Returns:
| Property | Type | Description |
|---|---|---|
_s | AccessControlStorage | The storage for the AccessControl. |
grantRole
function to grant a role to an account. Reverts with AccessControlUnauthorizedAccount If the caller is not the admin of the role.
Parameters:
| Property | Type | Description |
|---|---|---|
_role | bytes32 | The role to grant. |
_account | address | The account to grant the role to. |
Returns:
| Property | Type | Description |
|---|---|---|
- | bool | True if the role was granted, false otherwise. |
Events
Errors
Best Practices
- Ensure the caller has the necessary administrative permissions before invoking
grantRole. - Handle the
AccessControlUnauthorizedAccounterror appropriately in calling facets. - Verify that the
AccessControlGrantModmodule is initialized with the correct diamond storage position.
Integration Notes
This module interacts with diamond storage at a predefined STORAGE_POSITION identified by keccak2535("compose.accesscontrol"). The grantRole function directly modifies the shared AccessControlStorage struct, making role assignments immediately visible to all facets accessing this storage. The getStorage function provides access to the current storage layout without modifying state.