Governor Contract Implementation
Overviewβ
The Governor contract is a role-based authority system that supports up to 256 roles, enhancing readability and utility without needing off-chain indexing. Built on RolesAuthority and expanding upon Solmate's role-based system, it provides detailed role and permission management for authorized functions.
Inherits: RolesAuthority
Key Data Structuresβ
- Role: Struct holding a role ID and role name.
- Capability: Struct specifying a target contract, function signature, and role requirements.
- Mappings:
roleNames
: Maps role IDs to descriptive role names.
Eventsβ
- RoleNameSet: Emitted when a role name is assigned.
Functionsβ
Constructorβ
Initializes RolesAuthority
with the given owner address.
constructor(address _owner) RolesAuthority(_owner, Authority(address(this))) {}
Name | Type | Description |
---|---|---|
_owner | address | Initial owner who gains all permissions by default. |
getUsersByRoleβ
Returns addresses assigned a specific role.
function getUsersByRole(uint8 role) external view returns (address[] memory usersWithRole);
Name | Type | Description |
---|---|---|
role | uint8 | Role ID for which to list users. |
getRolesForUserβ
Returns all roles assigned to a user.
function getRolesForUser(address user) external view returns (uint8[] memory rolesForUser);
Name | Type | Description |
---|---|---|
user | address | Address of the user. |
getRolesFromByteMapβ
Converts a byte map into an array of role IDs.
function getRolesFromByteMap(bytes32 byteMap) public pure returns (uint8[] memory roleIds);
Name | Type | Description |
---|---|---|
byteMap | bytes32 | Bytes32 encoding of roles. |
getByteMapFromRolesβ
Converts an array of role IDs to a byte map.
function getByteMapFromRoles(uint8[] memory roleIds) public pure returns (bytes32);
Name | Type | Description |
---|---|---|
roleIds | uint8[] | Array of role IDs. |
getEnabledFunctionsInTargetβ
Returns function signatures enabled for a specified contract.
function getEnabledFunctionsInTarget(address _target) public view returns (bytes4[] memory _funcs);
Name | Type | Description |
---|---|---|
_target | address | Target contract address. |
getRoleNameβ
Returns the name associated with a specific role ID.
function getRoleName(uint8 role) external view returns (string memory roleName);
Name | Type | Description |
---|---|---|
role | uint8 | Role ID. |
setRoleNameβ
Sets a human-readable name for a role ID. Requires authorization.
function setRoleName(uint8 role, string memory roleName) external requiresAuth;
Name | Type | Description |
---|---|---|
role | uint8 | Role ID. |
roleName | string | Descriptive name for the role. |