Skip to content

Instantly share code, notes, and snippets.

@Aboudjem
Created May 21, 2020 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aboudjem/5c3dac7f227ad722791c5d9d14fdb84d to your computer and use it in GitHub Desktop.
Save Aboudjem/5c3dac7f227ad722791c5d9d14fdb84d to your computer and use it in GitHub Desktop.
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