MinterRole.sol 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. pragma solidity ^0.5.0;
  2. import "../../GSN/Context.sol";
  3. import "../Roles.sol";
  4. contract MinterRole is Context {
  5. using Roles for Roles.Role;
  6. event MinterAdded(address indexed account);
  7. event MinterRemoved(address indexed account);
  8. Roles.Role private _minters;
  9. constructor () internal {
  10. _addMinter(_msgSender());
  11. }
  12. modifier onlyMinter() {
  13. require(isMinter(_msgSender()), "MinterRole: caller does not have the Minter role");
  14. _;
  15. }
  16. function isMinter(address account) public view returns (bool) {
  17. return _minters.has(account);
  18. }
  19. function addMinter(address account) public onlyMinter {
  20. _addMinter(account);
  21. }
  22. function renounceMinter() public {
  23. _removeMinter(_msgSender());
  24. }
  25. function _addMinter(address account) internal {
  26. _minters.add(account);
  27. emit MinterAdded(account);
  28. }
  29. function _removeMinter(address account) internal {
  30. _minters.remove(account);
  31. emit MinterRemoved(account);
  32. }
  33. }