Skip to content

Commit

Permalink
Create pi_network_module_1: AccessControl.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 28, 2024
1 parent f474206 commit 274dffd
Showing 1 changed file with 35 additions and 0 deletions.
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];
}
}

0 comments on commit 274dffd

Please sign in to comment.