Contract won't compile

:computer: Environment

openzeppelin 2.8.2
:memo:Details

I want to write a blacklist.sol in my own access control schem,but when i extend ownable.sol,there always has some error that i cannot fix it ,i check all the blackspace,around,around…can anyone tell me how to fix it?thank you very much!!!

图片
:1234: Code to reproduce

pragma solidity ^0.6.0;

import "@openzeppelin/contracts/access/Ownable.sol";


contract Blacklist is Ownable {
    mapping(address => bool) public blacklist;

    event AddBlacklist(address account);
    event RemoveBlacklist(address account);

    function isBlacklist (address _account) 
        public
        view 
        onlyOwner 
        returns(bool)
    {
        return blacklist[_account];
    }

    function AddBlacklist (address _account) 
        public    
        onlyOwner 
    {
        require(
            !isBlacklist(_account),
        );

        blacklist[_account] = true;
        emit AddToBlacklist(_account);
    }


    function RemoveBlacklist(address _account) 
        public 
        onlyOwner 
    {
        require(
            isBlacklist(_account),
        );
        
        delete blacklist[_account];
        emit RemoveBlacklist(_account);

1 Like

Hi @wangyuyue,

Welcome to the community forum :wave:.

In order to compile, I added reasons to the require (there was just a hanging comma), rename the events as these duplicated function names. I also had to comment out the onlyUsers modifier.

pragma solidity ^0.6.0;

import "@openzeppelin/contracts/access/Ownable.sol";

contract Blacklist is Ownable {
    mapping(address => bool) public blacklist;

    event Blacklisted(address account);
    event Unblacklisted(address account);

    // modifier onlyUsers() {
    //     require(userId[msg.sender] != 0, "Blacklist: not a user");
    //     _;
    // }

    function isBlacklist(address _account)
        public
        view
        onlyOwner
        returns (bool)
    {
        return blacklist[_account];
    }

    function AddBlacklist(address _account) public onlyOwner {
        require(!isBlacklist(_account), "Blacklist: already listed");

        blacklist[_account] = true;
        emit Blacklisted(_account);
    }

    function RemoveBlacklist(address _account) public onlyOwner {
        require(isBlacklist(_account), "Blacklist: not listed");

        delete blacklist[_account];
        emit Unblacklisted(_account);
    }
}

I suggest looking at Using AccessControl to create a Deny List.

thank you so much! you are so wonderful.hhhh
as you suggest,acutually, i want to write a contract that using blacklist.sol and AccessControl.sol to limit illegal user’s access…

1 Like