12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- pragma solidity ^0.4.24;
- import "../ownership/Ownable.sol";
- import "../access/rbac/RBAC.sol";
- /**
- * @title Whitelist
- * @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions.
- * This simplifies the implementation of "user permissions".
- */
- contract Whitelist is Ownable, RBAC {
- string public constant ROLE_WHITELISTED = "whitelist";
- /**
- * @dev Throws if operator is not whitelisted.
- * @param _operator address
- */
- modifier onlyIfWhitelisted(address _operator) {
- checkRole(_operator, ROLE_WHITELISTED);
- _;
- }
- /**
- * @dev add an address to the whitelist
- * @param _operator address
- * @return true if the address was added to the whitelist, false if the address was already in the whitelist
- */
- function addAddressToWhitelist(address _operator)
- public
- onlyOwner
- {
- _addRole(_operator, ROLE_WHITELISTED);
- }
- /**
- * @dev getter to determine if address is in whitelist
- */
- function whitelist(address _operator)
- public
- view
- returns (bool)
- {
- return hasRole(_operator, ROLE_WHITELISTED);
- }
- /**
- * @dev add addresses to the whitelist
- * @param _operators addresses
- * @return true if at least one address was added to the whitelist,
- * false if all addresses were already in the whitelist
- */
- function addAddressesToWhitelist(address[] _operators)
- public
- onlyOwner
- {
- for (uint256 i = 0; i < _operators.length; i++) {
- addAddressToWhitelist(_operators[i]);
- }
- }
- /**
- * @dev remove an address from the whitelist
- * @param _operator address
- * @return true if the address was removed from the whitelist,
- * false if the address wasn't in the whitelist in the first place
- */
- function removeAddressFromWhitelist(address _operator)
- public
- onlyOwner
- {
- _removeRole(_operator, ROLE_WHITELISTED);
- }
- /**
- * @dev remove addresses from the whitelist
- * @param _operators addresses
- * @return true if at least one address was removed from the whitelist,
- * false if all addresses weren't in the whitelist in the first place
- */
- function removeAddressesFromWhitelist(address[] _operators)
- public
- onlyOwner
- {
- for (uint256 i = 0; i < _operators.length; i++) {
- removeAddressFromWhitelist(_operators[i]);
- }
- }
- }
|