0

I am creating a contract in which i want is like multiple owners have the rights to whitelist the user.

contract Whitelist {

    mapping(address => bool) Users;
    address private owner;
    address private otherOwner;

    function Whitelist() {
        owner = msg.sender;
    }
//Modifier for owner access
    modifier onlyOwner() {
        require(owner == msg.sender);
            _;
    }
//Function to add users
    function userAdd(address userAddress) onlyOwner {
            require(userAddress != 0x0 && !Users[userAddress]);             
            Users[userAddress] = true;    

    }
//Checking the user is whitelist
    function isWhitelisted(address passAddress) external returns (bool) {   
        return Users[passAddress];
    }

i am not getting idea about how to do that. need help. thanks in advance.

1

You can use RBAC.sol contract from OpenZeppelin https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/ownership/rbac/RBAC.sol.

It has onlyAdmin and onlyRole modifiers. Multiple users holding different roles can be added. You can have arbitrary roles e.g. WHITELISTED.

Alternatively you can use Whitelist.sol contract https://github.com/OpenZeppelin/zeppelin-solidity/pull/746/files#diff-8d5f210f8ce2e6f8d7f62f655e6f72ec

1

this is a sample of multiple owner smart contract, you can extend your contract from this contract to have the multiple owner

contract MultiOwnable {
    address public manager; // address used to set owners
    address[] public owners;
    mapping(address => bool) public ownerByAddress;

    event SetOwners(address[] owners);

    modifier onlyOwner() {
        require(ownerByAddress[msg.sender] == true);
        _;
    }

    /**
     * @dev MultiOwnable constructor sets the manager
     */
    function MultiOwnable() public {
        manager = msg.sender;
    }

    /**
     * @dev Function to set owners addresses
     */
    function setOwners(address[] _owners) public {
        require(msg.sender == manager);
        _setOwners(_owners);

    }

    function _setOwners(address[] _owners) internal {
        for(uint256 i = 0; i < owners.length; i++) {
            ownerByAddress[owners[i]] = false;
        }


        for(uint256 j = 0; j < _owners.length; j++) {
            ownerByAddress[_owners[j]] = true;
        }
        owners = _owners;
        emit SetOwners(_owners);
    }

    function getOwners() public constant returns (address[]) {
        return owners;
    }
}

contract Pausable is MultiOwnable {

    uint public endDate;

    /**
    * @dev modifier to allow actions only when the contract IS not paused
    */
    modifier whenNotPaused() {
        require(now >= endDate);
        _;
    }
}
0

Assuming you've set otherOwner, just change your modifier thusly:

require(owner == msg.sender || otherOwner == msg.sender);
0

You already use mapping to identify users that have been whitelisted. Why not also use a Map to store the admins?

contract Whitelist {
 mapping(address => uint) whitelist;
 mapping(address => uint) admins;

    function Whitelist() {
        admins[msg.sender] = true;
    }

    modifier onlyAdmin() {
        require(admin[msg.sender] == true);
            _;
    }


    function addWhitelist(address userAddress) onlyAdmin {
            require(userAddress != 0x0 && !whitelist[userAddress]);             
            whitelist[whitelist] = true;    
    }

    function isWhitelisted(address passAddress) external returns (bool) {   
        return whitelist[passAddress];
    }

    function addAdmin(address userAddress) onlyAdmin {
            require(userAddress != 0x0 && !admins[userAddress]);             
            admins[userAddress] = true;    

    }
}

You can also create different permission tiers, where there is only one owner who can add admins who can add whitelisted.

  • lot's of typos and debug error in remix editor :s – btc4cash Jun 5 '18 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.