Files
dodo-contractV2/contracts/lib/PermissionManager.sol

57 lines
1.4 KiB
Solidity
Raw Normal View History

2020-10-23 01:16:52 +08:00
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import {InitializableOwnable} from "./InitializableOwnable.sol";
2020-11-05 00:26:45 +08:00
interface IPermissionManager {
function initOwner(address) external;
2020-10-23 01:16:52 +08:00
2020-12-18 01:11:33 +08:00
function isAllowed(address) external view returns (bool);
2020-11-05 00:26:45 +08:00
}
2020-10-23 01:16:52 +08:00
2020-11-05 00:26:45 +08:00
contract PermissionManager is InitializableOwnable {
2020-11-06 16:03:18 +08:00
bool public _WHITELIST_MODE_ON_;
2020-10-23 01:16:52 +08:00
2020-11-05 00:26:45 +08:00
mapping(address => bool) internal _whitelist_;
mapping(address => bool) internal _blacklist_;
2020-10-23 01:16:52 +08:00
2020-11-05 00:26:45 +08:00
function isAllowed(address account) external view returns (bool) {
2020-11-06 16:03:18 +08:00
if (_WHITELIST_MODE_ON_) {
2020-11-05 00:26:45 +08:00
return _whitelist_[account];
2020-11-06 16:03:18 +08:00
} else {
return !_blacklist_[account];
2020-11-05 00:26:45 +08:00
}
}
2020-10-23 01:16:52 +08:00
2020-11-06 16:03:18 +08:00
function openBlacklistMode() external onlyOwner {
_WHITELIST_MODE_ON_ = false;
2020-11-05 00:26:45 +08:00
}
2020-10-23 01:16:52 +08:00
2020-11-06 16:03:18 +08:00
function openWhitelistMode() external onlyOwner {
_WHITELIST_MODE_ON_ = true;
2020-11-05 00:26:45 +08:00
}
2020-10-23 01:16:52 +08:00
2020-11-05 00:26:45 +08:00
function addToWhitelist(address account) external onlyOwner {
_whitelist_[account] = true;
}
2020-10-23 01:16:52 +08:00
2020-11-05 00:26:45 +08:00
function removeFromWhitelist(address account) external onlyOwner {
_whitelist_[account] = false;
}
2020-10-23 01:16:52 +08:00
2020-11-05 00:26:45 +08:00
function addToBlacklist(address account) external onlyOwner {
_blacklist_[account] = true;
}
2020-10-23 01:16:52 +08:00
2020-11-05 00:26:45 +08:00
function removeFromBlacklist(address account) external onlyOwner {
_blacklist_[account] = false;
}
}