AccessControl
Unauthorized
Emitted when msg.sender
is not authorized to operate the contract.
InvalidRoleId
Emitted when roleId
is invalid.
AuthorizePersonnel
Emitted when a new address is added to an roleId
.
AuthorizeOperator
Emitted when an roleId
is added as an operator of a function in the contract.
onlyOperator
Modifier to check if msg.sender
is authorized to operate a given interfaceId from one of the contract's function.
onlyOwner
Modifier to check if msg.sender
is the owner of the contract.
constructor
Initializes the contract setting the deployer as the initial owner.
owner
Returns the address of the current owner.
setRole
This function sets a role for an address.
Emits an {AuthorizePersonnel} event.
Requirements:
msg.sender
must be the owner of the contract._roleId
must not be 0.
setOperator
This function sets an authorized role as the operator of a given interface id.
Emits an {AuthorizeOperator} event.
Requirements:
msg.sender
must be the owner of the contract._roleId
must not be 0.
hasRole
_This function checks if an address holds a given roleId
.
NOTE
The owner of the contract is always authorized.
isOperator
This function checks if an authorizedId
is allowed to operate a given _interfaceId
.
NOTE
The owner of the contract is always authorized.
AccessControl Summarize
The Access Control feature in the smart contract is designed to manage the permissions and roles within the Web3Task. It uses a combination of role-based access control and attribute-based access control to ensure that only authorized users can perform certain operations.
Role-Based Access Control: This feature allows the contract owner to assign roles to addresses. Each role is represented by a unique role ID, and an address can be assigned to multiple roles. The contract owner can also set an address as an operator for a given interface ID, which allows the address to operate a given interface ID.
Attribute-Based Access Control: This feature allows the contract owner to assign attributes to addresses. Each attribute is represented by a unique attribute ID, and an address can be assigned to multiple attributes. The contract owner can also set an address as an operator for a given interface ID, which allows the address to operate a given interface ID.
Modifiers: The contract includes two modifiers,
onlyOperator
andonlyOwner
, which are used to restrict access to certain functions. TheonlyOperator
modifier checks if the sender is an operator for a given interface ID and role ID, and theonlyOwner
modifier checks if the sender is the owner of the contract.Events: The contract emits events when an address is authorized or deauthorized for a role or an interface ID, and when an address is authorized or deauthorized as an operator for an interface ID.
Functions: The contract includes functions to set a role for an address, set an operator for an interface ID, check if an address holds a given role, and check if an address is an operator for a given interface ID.
Last updated