-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create pi_network_module_1: AccessControl.sol
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...rk/features/pi_network_smart_contract_architecture/pi_network_module_1: AccessControl.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/access/Roles.sol"; | ||
|
||
contract AccessControl { | ||
using Roles for address; | ||
|
||
// Mapping of roles to addresses | ||
mapping (address => Role) public roles; | ||
|
||
// Enum for roles | ||
enum Role { ADMIN, DEVELOPER, USER } | ||
|
||
// Modifier to restrict access to admins | ||
modifier onlyAdmin() { | ||
require(roles[msg.sender] == Role.ADMIN, "Only admins can access this function"); | ||
_; | ||
} | ||
|
||
// Modifier to restrict access to developers | ||
modifier onlyDeveloper() { | ||
require(roles[msg.sender] == Role.DEVELOPER, "Only developers can access this function"); | ||
_; | ||
} | ||
|
||
// Function to add a new role | ||
function addRole(address _address, Role _role) public onlyAdmin { | ||
roles[_address] = _role; | ||
} | ||
|
||
// Function to remove a role | ||
function removeRole(address _address) public onlyAdmin { | ||
delete roles[_address]; | ||
} | ||
} |