pragma solidity ^0.4.26;// SPDX-License-Identifier: MIT
contract WhiteListHelper{
event NewWhiteList(uint _WhiteListCount, address _creator, address _contract, uint _changeUntil);
modifier OnlyCreator(uint256 _Id) {
require(
WhitelistSettings[_Id].Creator == msg.sender,
"Only creator can access"
);
_;
}
modifier TimeRemaining(uint256 _Id){
require(
now < WhitelistSettings[_Id].ChangeUntil,
"Time for edit is finished"
);
_;
}
modifier ValidateId(uint256 _Id){
require(_Id < WhiteListCount, "Wrong ID");
_;
}
struct WhiteListItem {
// uint256 Limit;
address Creator;
uint256 ChangeUntil;
//uint256 DrawLimit;
//uint256 SignUpPrice;
address Contract;
// mapping(address => uint256) WhiteListDB;
bool isReady; // defualt false | true after first address is added
}
mapping(uint256 => mapping(address => uint256)) public WhitelistDB;
mapping(uint256 => WhiteListItem) public WhitelistSettings;
uint256 public WhiteListCost;
uint256 public WhiteListCount;
function _AddAddress(uint256 _Id, address user, uint amount) internal {
WhitelistDB[_Id][user] = amount;
}
function _RemoveAddress(uint256 _Id, address user) internal {
WhitelistDB[_Id][user] = 0;
}
function isWhiteListReady(uint256 _Id) external view returns(bool){
return WhitelistSettings[_Id].isReady;
}
//View function to Check if address is whitelisted
function Check(address _user, uint256 _id) external view returns(uint){
if (_id == 0) return uint256(-1);
return WhitelistDB[_id][_user];
}
}/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* @notice Renouncing to ownership will leave the contract without an owner.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) public onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
}// SPDX-License-Identifier: MIT
contract WhiteList is WhiteListHelper, Ownable{
constructor() public {
WhiteListCount = 1; //0 is off
MaxUsersLimit = 10;
WhiteListCost = 0.01 ether;
}
//uint256 public SignUpCost;
uint256 public MaxUsersLimit;
modifier isBelowUserLimit(uint256 _limit) {
require(_limit <= MaxUsersLimit, "Maximum User Limit exceeded");
_;
}
function setMaxUsersLimit(uint256 _limit) external onlyOwner {
MaxUsersLimit = _limit;
}
function setWhiteListCost(uint256 _newCost) external onlyOwner {
WhiteListCost = _newCost;
}
function CreateManualWhiteList(
uint256 _ChangeUntil,
address _Contract
) public payable returns (uint256 Id) {
require(msg.value >= WhiteListCost, "ether not enough");
WhitelistSettings[WhiteListCount] = WhiteListItem(
/*_Limit == 0 ? uint256(-1) :*/
// _Limit,
msg.sender,
_ChangeUntil,
_Contract,
false
);
uint256 temp = WhiteListCount;
WhiteListCount++;
emit NewWhiteList(temp, msg.sender, _Contract, _ChangeUntil);
return temp;
}
function ChangeCreator(uint256 _Id, address _NewCreator)
external
OnlyCreator(_Id)
TimeRemaining(_Id)
ValidateId(_Id)
{
WhitelistSettings[_Id].Creator = _NewCreator;
}
function ChangeContract(uint256 _Id, address _NewContract)
external
OnlyCreator(_Id)
TimeRemaining(_Id)
ValidateId(_Id)
{
WhitelistSettings[_Id].Contract = _NewContract;
}
function AddAddress(uint256 _Id, address[] _Users, uint256[] _Amount)
public
OnlyCreator(_Id)
TimeRemaining(_Id)
ValidateId(_Id)
isBelowUserLimit(_Users.length)
{
require(_Users.length == _Amount.length, "Number of users should be same as the amount length");
require(_Users.length > 0,"Need something...");
if(!WhitelistSettings[_Id].isReady){
WhitelistSettings[_Id].isReady = true;
}
for (uint256 index = 0; index < _Users.length; index++) {
_AddAddress(_Id, _Users[index], _Amount[index]);
}
}
function RemoveAddress(uint256 _Id, address[] _Users)
public
OnlyCreator(_Id)
TimeRemaining(_Id)
ValidateId(_Id)
isBelowUserLimit(_Users.length)
{
for (uint256 index = 0; index < _Users.length; index++) {
_RemoveAddress(_Id, _Users[index]);
}
}
function Register(
address _Subject,
uint256 _Id,
uint256 _Amount
) external {
if (_Id == 0) return;
require(
msg.sender == WhitelistSettings[_Id].Contract,
"Only the Contract can call this"
);
require(
WhitelistDB[_Id][_Subject] >= _Amount,
"Sorry, no alocation for Subject"
);
uint256 temp = WhitelistDB[_Id][_Subject] - _Amount;
WhitelistDB[_Id][_Subject] = temp;
assert(WhitelistDB[_Id][_Subject] == temp);
}
}
{
"compilationTarget": {
"WhiteList.sol": "WhiteList"
},
"evmVersion": "byzantium",
"libraries": {},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"constant":false,"inputs":[{"name":"_Id","type":"uint256"},{"name":"_Users","type":"address[]"}],"name":"RemoveAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_Subject","type":"address"},{"name":"_Id","type":"uint256"},{"name":"_Amount","type":"uint256"}],"name":"Register","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_ChangeUntil","type":"uint256"},{"name":"_Contract","type":"address"}],"name":"CreateManualWhiteList","outputs":[{"name":"Id","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[{"name":"_Id","type":"uint256"}],"name":"isWhiteListReady","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_limit","type":"uint256"}],"name":"setMaxUsersLimit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"WhiteListCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"address"}],"name":"WhitelistDB","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_Id","type":"uint256"},{"name":"_NewContract","type":"address"}],"name":"ChangeContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"MaxUsersLimit","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_Id","type":"uint256"},{"name":"_NewCreator","type":"address"}],"name":"ChangeCreator","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"WhitelistSettings","outputs":[{"name":"Creator","type":"address"},{"name":"ChangeUntil","type":"uint256"},{"name":"Contract","type":"address"},{"name":"isReady","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_Id","type":"uint256"},{"name":"_Users","type":"address[]"},{"name":"_Amount","type":"uint256[]"}],"name":"AddAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_newCost","type":"uint256"}],"name":"setWhiteListCost","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_user","type":"address"},{"name":"_id","type":"uint256"}],"name":"Check","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"WhiteListCost","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"}],"name":"OwnershipRenounced","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_WhiteListCount","type":"uint256"},{"indexed":false,"name":"_creator","type":"address"},{"indexed":false,"name":"_contract","type":"address"},{"indexed":false,"name":"_changeUntil","type":"uint256"}],"name":"NewWhiteList","type":"event"}]