RBACWithAdmin.sol 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. pragma solidity ^0.4.23;
  2. import "./RBAC.sol";
  3. /**
  4. * @title RBACWithAdmin
  5. * @author Matt Condon (@Shrugs)
  6. * @dev It's recommended that you define constants in the contract,
  7. * @dev like ROLE_ADMIN below, to avoid typos.
  8. */
  9. contract RBACWithAdmin is RBAC {
  10. /**
  11. * A constant role name for indicating admins.
  12. */
  13. string public constant ROLE_ADMIN = "admin";
  14. /**
  15. * @dev modifier to scope access to admins
  16. * // reverts
  17. */
  18. modifier onlyAdmin()
  19. {
  20. checkRole(msg.sender, ROLE_ADMIN);
  21. _;
  22. }
  23. /**
  24. * @dev constructor. Sets msg.sender as admin by default
  25. */
  26. constructor()
  27. public
  28. {
  29. addRole(msg.sender, ROLE_ADMIN);
  30. }
  31. /**
  32. * @dev add a role to an address
  33. * @param addr address
  34. * @param roleName the name of the role
  35. */
  36. function adminAddRole(address addr, string roleName)
  37. onlyAdmin
  38. public
  39. {
  40. addRole(addr, roleName);
  41. }
  42. /**
  43. * @dev remove a role from an address
  44. * @param addr address
  45. * @param roleName the name of the role
  46. */
  47. function adminRemoveRole(address addr, string roleName)
  48. onlyAdmin
  49. public
  50. {
  51. removeRole(addr, roleName);
  52. }
  53. }