|
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0; |
|
|
|
|
|
|
|
import "./ERC165.sol"; |
|
import "./EnumerableSet.sol"; |
|
import "./Ownable.sol"; |
|
import "./IAdminControl.sol"; |
|
|
|
abstract contract AdminControl is Ownable, IAdminControl, ERC165 { |
|
using EnumerableSet for EnumerableSet.AddressSet; |
|
|
|
|
|
EnumerableSet.AddressSet private _admins; |
|
|
|
|
|
|
|
|
|
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { |
|
return interfaceId == type(IAdminControl).interfaceId |
|
|| super.supportsInterface(interfaceId); |
|
} |
|
|
|
|
|
|
|
|
|
modifier adminRequired() { |
|
require(owner() == msg.sender || _admins.contains(msg.sender), "AdminControl: Must be owner or admin"); |
|
_; |
|
} |
|
|
|
|
|
|
|
|
|
function getAdmins() external view override returns (address[] memory admins) { |
|
admins = new address[](_admins.length()); |
|
for (uint i = 0; i < _admins.length(); i++) { |
|
admins[i] = _admins.at(i); |
|
} |
|
return admins; |
|
} |
|
|
|
|
|
|
|
|
|
function approveAdmin(address admin) external override onlyOwner { |
|
if (!_admins.contains(admin)) { |
|
emit AdminApproved(admin, msg.sender); |
|
_admins.add(admin); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
function revokeAdmin(address admin) external override onlyOwner { |
|
if (_admins.contains(admin)) { |
|
emit AdminRevoked(admin, msg.sender); |
|
_admins.remove(admin); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
function isAdmin(address admin) public override view returns (bool) { |
|
return (owner() == admin || _admins.contains(admin)); |
|
} |
|
|
|
} |