Roles.sol 986 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. pragma solidity ^0.4.24;
  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. internal
  34. view
  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. internal
  44. view
  45. returns (bool)
  46. {
  47. return _role.bearer[_addr];
  48. }
  49. }