-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAccessProtected.sol
44 lines (37 loc) · 1.39 KB
/
AccessProtected.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.14;
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
/**
@title Access Limiter to multiple owner-specified accounts.
@dev Exposes the onlyAdmin modifier, which will revert (ADMIN_ACCESS_REQUIRED) if the caller is not the owner nor the admin.
*/
abstract contract AccessProtected is Context {
mapping(address => bool) private _admins; // user address => admin? mapping
event AdminAccessSet(address indexed _admin, bool _enabled);
constructor() {
_admins[_msgSender()] = true;
emit AdminAccessSet(_msgSender(), true);
}
/**
* Throws if called by any account that isn't an admin or an owner.
*/
modifier onlyAdmin() {
require(_admins[_msgSender()], "ADMIN_ACCESS_REQUIRED");
_;
}
function isAdmin(address _addressToCheck) external view returns (bool) {
return _admins[_addressToCheck];
}
/**
* @notice Set/unset Admin Access for a given address.
*
* @param admin - Address of the new admin (or the one to be removed)
* @param isEnabled - Enable/Disable Admin Access
*/
function setAdmin(address admin, bool isEnabled) public onlyAdmin {
require(admin != address(0), "INVALID_ADDRESS");
_admins[admin] = isEnabled;
emit AdminAccessSet(admin, isEnabled);
}
}