Roles.sol 975 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. pragma solidity ^0.4.18;
  2. /**
  3. * @title Roles
  4. * @author Francisco Giordano (@frangio)
  5. * @dev Library for managing addresses assigned to a Role.
  6. * See RBAC.sol for example usage.
  7. */
  8. library Roles {
  9. struct Role {
  10. mapping (address => bool) bearer;
  11. }
  12. /**
  13. * @dev give an address access to this role
  14. */
  15. function add(Role storage role, address addr)
  16. internal
  17. {
  18. role.bearer[addr] = true;
  19. }
  20. /**
  21. * @dev remove an address' access to this role
  22. */
  23. function remove(Role storage role, address addr)
  24. internal
  25. {
  26. role.bearer[addr] = false;
  27. }
  28. /**
  29. * @dev check if an address has this role
  30. * // reverts
  31. */
  32. function check(Role storage role, address addr)
  33. view
  34. internal
  35. {
  36. require(has(role, addr));
  37. }
  38. /**
  39. * @dev check if an address has this role
  40. * @return bool
  41. */
  42. function has(Role storage role, address addr)
  43. view
  44. internal
  45. returns (bool)
  46. {
  47. return role.bearer[addr];
  48. }
  49. }