You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.3 KiB
81 lines
2.3 KiB
pragma solidity ^0.4.18;
|
|
|
|
|
|
import "./Ownable.sol";
|
|
|
|
|
|
/**
|
|
* @title Whitelist
|
|
* @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions.
|
|
* @dev This simplifies the implementation of "user permissions".
|
|
*/
|
|
contract Whitelist is Ownable {
|
|
mapping(address => bool) public whitelist;
|
|
|
|
event WhitelistedAddressAdded(address addr);
|
|
event WhitelistedAddressRemoved(address addr);
|
|
|
|
/**
|
|
* @dev Throws if called by any account that's not whitelisted.
|
|
*/
|
|
modifier onlyWhitelisted() {
|
|
require(whitelist[msg.sender]);
|
|
_;
|
|
}
|
|
|
|
/**
|
|
* @dev add an address to the whitelist
|
|
* @param addr address
|
|
* @return true if the address was added to the whitelist, false if the address was already in the whitelist
|
|
*/
|
|
function addAddressToWhitelist(address addr) onlyOwner public returns(bool success) {
|
|
if (!whitelist[addr]) {
|
|
whitelist[addr] = true;
|
|
WhitelistedAddressAdded(addr);
|
|
success = true;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev add addresses to the whitelist
|
|
* @param addrs 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[] addrs) onlyOwner public returns(bool success) {
|
|
for (uint256 i = 0; i < addrs.length; i++) {
|
|
if (addAddressToWhitelist(addrs[i])) {
|
|
success = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev remove an address from the whitelist
|
|
* @param addr 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 addr) onlyOwner public returns(bool success) {
|
|
if (whitelist[addr]) {
|
|
whitelist[addr] = false;
|
|
WhitelistedAddressRemoved(addr);
|
|
success = true;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dev remove addresses from the whitelist
|
|
* @param addrs 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[] addrs) onlyOwner public returns(bool success) {
|
|
for (uint256 i = 0; i < addrs.length; i++) {
|
|
if (removeAddressFromWhitelist(addrs[i])) {
|
|
success = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|