Created
May 21, 2020 22:33
-
-
Save Aboudjem/5c3dac7f227ad722791c5d9d14fdb84d to your computer and use it in GitHub Desktop.
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
pragma solidity ^0.6.0; | |
import "openzeppelin-solidity/contracts/access/Roles.sol"; | |
import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; | |
contract AgentRole is Ownable { | |
using Roles for Roles.Role; | |
event AgentAdded(address indexed account); | |
event AgentRemoved(address indexed account); | |
Roles.Role private _agents; | |
modifier onlyAgent() { | |
require(isAgent(msg.sender), "AgentRole: caller does not have the Agent role"); | |
_; | |
} | |
function isAgent(address account) public view returns (bool) { | |
return _agents.has(account); | |
} | |
function addAgent(address account) public onlyOwner { | |
_addAgent(account); | |
} | |
function removeAgent(address account) public onlyOwner { | |
_removeAgent(account); | |
} | |
function _addAgent(address account) internal { | |
_agents.add(account); | |
emit AgentAdded(account); | |
} | |
function _removeAgent(address account) internal { | |
_agents.remove(account); | |
emit AgentRemoved(account); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment