-
Notifications
You must be signed in to change notification settings - Fork 5
/
AntsReviewRoles.sol
122 lines (103 loc) · 4.35 KB
/
AntsReviewRoles.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.6.12;
///@title Ants-Review
///@author Nazzareno Massari @naszam
///@notice AntsReviewRoles Access Management for Issuer and Peer-Reviewer
///@dev All function calls are currently implemented without side effects through TDD approach
///@dev OpenZeppelin library is used for secure contract development
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";
contract AntsReviewRoles is Ownable, AccessControl, Pausable {
/// @dev Roles
bytes32 public constant ISSUER_ROLE = keccak256("ISSUER_ROLE");
bytes32 public constant PEER_REVIEWER_ROLE = keccak256("PEER_REVIEWER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
constructor() public {
_setupRole(DEFAULT_ADMIN_ROLE, owner());
_setupRole(PAUSER_ROLE, owner());
}
/// @dev Modifiers
modifier onlyAdmin() {
require(isAdmin(msg.sender), "Caller is not an admin");
_;
}
modifier onlyIssuer() {
require(isIssuer(msg.sender), "Caller is not an issuer");
_;
}
modifier onlyPeerReviewer() {
require(isPeerReviewer(msg.sender), "Caller is not a peer-reviewer");
_;
}
/// @dev Functions
/// @notice Check if account is an Admin
/// @dev Used in onlyAdmin() modifier
/// @param account Address to check
/// @return True If the account is an Admin
function isAdmin(address account) public view returns (bool) {
return hasRole(DEFAULT_ADMIN_ROLE, account);
}
/// @notice Check if account is an Issuer
/// @dev Used in onlyIssuer() modifier
/// @param account Address to check
/// @return True If the account is an Issuer
function isIssuer(address account) public view returns (bool) {
return hasRole(ISSUER_ROLE, account);
}
/// @notice Check if account is a Peer-Reviewer
/// @dev Used in onlyPeerReviewer() modifier
/// @param account Address to check
/// @return True If the account is a Peer-Reviewer
function isPeerReviewer(address account) public view returns (bool) {
return hasRole(PEER_REVIEWER_ROLE, account);
}
/// @notice Add a new Issuer
/// @dev Access restricted only for Admins
/// @param account Address of the new Issuer
/// @return True if the account address is added as Issuer
function addIssuer(address account) external onlyAdmin returns (bool) {
require(!isIssuer(account), "Account is already an issuer");
grantRole(ISSUER_ROLE, account);
return true;
}
/// @notice Add a new Peer-Reviewer
/// @dev Access restricted only for Admins
/// @param account Address of the new Peer-Reviewer
/// @return True if the account address is added as Peer-Reviewer
function addPeerReviewer(address account) external onlyAdmin returns (bool) {
require(!isPeerReviewer(account), "Account is already a peer-reviewer");
grantRole(PEER_REVIEWER_ROLE, account);
return true;
}
/// @notice Remove an Issuer
/// @dev Access restricted only for Admins
/// @param account Address of the Issuer
/// @return True if the account address is removed as Issuer
function removeIssuer(address account) external onlyAdmin returns (bool) {
require(isIssuer(account), "Account is not an issuer");
revokeRole(ISSUER_ROLE, account);
return true;
}
/// @notice Remove a Peer-Reviewer
/// @dev Access restricted only for Admins
/// @param account Address of the Peer-Reviewer
/// @return True if the account address is removed as Peer-Reviewer
function removePeerReviewer(address account) external onlyAdmin returns (bool) {
require(isPeerReviewer(account), "Account is not a peer-reviewer");
revokeRole(PEER_REVIEWER_ROLE, account);
return true;
}
/// @notice Pause all the functions
/// @dev the caller must have the 'PAUSER_ROLE'
function pause() external {
require(hasRole(PAUSER_ROLE, msg.sender), "AntsReview: must have pauser role to pause");
_pause();
}
/// @notice Unpause all the functions
/// @dev the caller must have the 'PAUSER_ROLE'
function unpause() external {
require(hasRole(PAUSER_ROLE, msg.sender), "AntsReview: must have pauser role to unpause");
_unpause();
}
}