RBACWithAdmin.sol 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. pragma solidity ^0.4.24;
  2. import "../ownership/rbac/RBAC.sol";
  3. /**
  4. * @title RBACWithAdmin
  5. * @author Matt Condon (@Shrugs)
  6. * @dev It's recommended that you define constants in the contract,
  7. * like ROLE_ADMIN below, to avoid typos.
  8. * @notice RBACWithAdmin is probably too expansive and powerful for your
  9. * application; an admin is actually able to change any address to any role
  10. * which is a very large API surface. It's recommended that you follow a strategy
  11. * of strictly defining the abilities of your roles
  12. * and the API-surface of your contract.
  13. * This is just an example for example's sake.
  14. */
  15. contract RBACWithAdmin is RBAC {
  16. /**
  17. * A constant role name for indicating admins.
  18. */
  19. string public constant ROLE_ADMIN = "admin";
  20. /**
  21. * @dev modifier to scope access to admins
  22. * // reverts
  23. */
  24. modifier onlyAdmin()
  25. {
  26. checkRole(msg.sender, ROLE_ADMIN);
  27. _;
  28. }
  29. /**
  30. * @dev constructor. Sets msg.sender as admin by default
  31. */
  32. constructor()
  33. public
  34. {
  35. addRole(msg.sender, ROLE_ADMIN);
  36. }
  37. /**
  38. * @dev add a role to an address
  39. * @param addr address
  40. * @param roleName the name of the role
  41. */
  42. function adminAddRole(address addr, string roleName)
  43. onlyAdmin
  44. public
  45. {
  46. addRole(addr, roleName);
  47. }
  48. /**
  49. * @dev remove a role from an address
  50. * @param addr address
  51. * @param roleName the name of the role
  52. */
  53. function adminRemoveRole(address addr, string roleName)
  54. onlyAdmin
  55. public
  56. {
  57. removeRole(addr, roleName);
  58. }
  59. }