Whitelist.sol 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. pragma solidity ^0.4.24;
  2. import "../ownership/Ownable.sol";
  3. import "../access/rbac/RBAC.sol";
  4. /**
  5. * @title Whitelist
  6. * @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions.
  7. * This simplifies the implementation of "user permissions".
  8. */
  9. contract Whitelist is Ownable, RBAC {
  10. string public constant ROLE_WHITELISTED = "whitelist";
  11. /**
  12. * @dev Throws if operator is not whitelisted.
  13. * @param _operator address
  14. */
  15. modifier onlyIfWhitelisted(address _operator) {
  16. checkRole(_operator, ROLE_WHITELISTED);
  17. _;
  18. }
  19. /**
  20. * @dev add an address to the whitelist
  21. * @param _operator address
  22. * @return true if the address was added to the whitelist, false if the address was already in the whitelist
  23. */
  24. function addAddressToWhitelist(address _operator)
  25. public
  26. onlyOwner
  27. {
  28. addRole(_operator, ROLE_WHITELISTED);
  29. }
  30. /**
  31. * @dev getter to determine if address is in whitelist
  32. */
  33. function whitelist(address _operator)
  34. public
  35. view
  36. returns (bool)
  37. {
  38. return hasRole(_operator, ROLE_WHITELISTED);
  39. }
  40. /**
  41. * @dev add addresses to the whitelist
  42. * @param _operators addresses
  43. * @return true if at least one address was added to the whitelist,
  44. * false if all addresses were already in the whitelist
  45. */
  46. function addAddressesToWhitelist(address[] _operators)
  47. public
  48. onlyOwner
  49. {
  50. for (uint256 i = 0; i < _operators.length; i++) {
  51. addAddressToWhitelist(_operators[i]);
  52. }
  53. }
  54. /**
  55. * @dev remove an address from the whitelist
  56. * @param _operator address
  57. * @return true if the address was removed from the whitelist,
  58. * false if the address wasn't in the whitelist in the first place
  59. */
  60. function removeAddressFromWhitelist(address _operator)
  61. public
  62. onlyOwner
  63. {
  64. removeRole(_operator, ROLE_WHITELISTED);
  65. }
  66. /**
  67. * @dev remove addresses from the whitelist
  68. * @param _operators addresses
  69. * @return true if at least one address was removed from the whitelist,
  70. * false if all addresses weren't in the whitelist in the first place
  71. */
  72. function removeAddressesFromWhitelist(address[] _operators)
  73. public
  74. onlyOwner
  75. {
  76. for (uint256 i = 0; i < _operators.length; i++) {
  77. removeAddressFromWhitelist(_operators[i]);
  78. }
  79. }
  80. }