Skip to content

Commit adb9138

Browse files
Krishang NadgaudaKrishang Nadgauda
authored andcommitted
Update Permissions and use it in SignatureDrop
1 parent 287f8f9 commit adb9138

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

contracts/drop/SignatureDrop.sol

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import "../feature/PrimarySale.sol";
3131
import "../feature/Ownable.sol";
3232
import "../feature/DelayedReveal.sol";
3333
import "../feature/LazyMint.sol";
34+
import "../feature/PermissionsEnumerable.sol";
3435
import "../feature/SignatureMintERC721Upgradeable.sol";
3536

3637
contract SignatureDrop is
@@ -42,12 +43,12 @@ contract SignatureDrop is
4243
Ownable,
4344
DelayedReveal,
4445
LazyMint,
46+
PermissionsEnumerable,
4547
SignatureMintERC721Upgradeable,
4648
IDropClaimCondition,
4749
ReentrancyGuardUpgradeable,
4850
ERC2771ContextUpgradeable,
4951
MulticallUpgradeable,
50-
AccessControlEnumerableUpgradeable,
5152
ERC721AUpgradeable
5253
{
5354
using StringsUpgradeable for uint256;
@@ -171,7 +172,7 @@ contract SignatureDrop is
171172
public
172173
view
173174
virtual
174-
override(ERC721AUpgradeable, AccessControlEnumerableUpgradeable)
175+
override(ERC721AUpgradeable)
175176
returns (bool)
176177
{
177178
return super.supportsInterface(interfaceId) || type(IERC2981Upgradeable).interfaceId == interfaceId;
@@ -410,7 +411,7 @@ contract SignatureDrop is
410411
internal
411412
view
412413
virtual
413-
override(ContextUpgradeable, ERC2771ContextUpgradeable)
414+
override(ContextUpgradeable, ERC2771ContextUpgradeable, Context)
414415
returns (address sender)
415416
{
416417
return ERC2771ContextUpgradeable._msgSender();
@@ -420,7 +421,7 @@ contract SignatureDrop is
420421
internal
421422
view
422423
virtual
423-
override(ContextUpgradeable, ERC2771ContextUpgradeable)
424+
override(ContextUpgradeable, ERC2771ContextUpgradeable, Context)
424425
returns (bytes calldata)
425426
{
426427
return ERC2771ContextUpgradeable._msgData();

contracts/feature/Permissions.sol

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,36 @@ import "../lib/Strings.sol";
77

88
contract Permissions is IPermissions, Context {
99

10-
mapping(bytes32 => mapping(address => bool)) public hasRole;
11-
mapping(bytes32 => bytes32) public getRoleAdmin;
10+
mapping(bytes32 => mapping(address => bool)) private _hasRole;
11+
mapping(bytes32 => bytes32) private _getRoleAdmin;
1212

1313
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
1414

15+
modifier onlyRole(bytes32 role) {
16+
_checkRole(role, _msgSender());
17+
_;
18+
}
19+
20+
function hasRole(bytes32 role, address account) public view returns (bool) {
21+
return _hasRole[role][account];
22+
}
23+
24+
function getRoleAdmin(bytes32 role) public view returns (bytes32) {
25+
return _getRoleAdmin[role];
26+
}
27+
1528
function grantRole(bytes32 role, address account) public virtual {
16-
_checkRole(getRoleAdmin[role], _msgSender());
29+
_checkRole(_getRoleAdmin[role], _msgSender());
1730

18-
hasRole[role][account] = true;
31+
_hasRole[role][account] = true;
1932

2033
emit RoleGranted(role, account, _msgSender());
2134
}
2235

2336
function revokeRole(bytes32 role, address account) public virtual {
24-
_checkRole(getRoleAdmin[role], _msgSender());
37+
_checkRole(_getRoleAdmin[role], _msgSender());
2538

26-
delete hasRole[role][account];
39+
delete _hasRole[role][account];
2740

2841
emit RoleRevoked(role, account, _msgSender());
2942
}
@@ -34,13 +47,18 @@ contract Permissions is IPermissions, Context {
3447
"Can only renounce for self"
3548
);
3649

37-
delete hasRole[role][account];
50+
delete _hasRole[role][account];
3851

3952
emit RoleRevoked(role, account, _msgSender());
4053
}
4154

55+
function _setupRole(bytes32 role, address account) internal virtual {
56+
_hasRole[role][account] = true;
57+
emit RoleGranted(role, account, _msgSender());
58+
}
59+
4260
function _checkRole(bytes32 role, address account) internal view virtual {
43-
if (!hasRole[role][account]) {
61+
if (!_hasRole[role][account]) {
4462
revert(
4563
string(
4664
abi.encodePacked(

contracts/feature/PermissionsEnumerable.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ contract PermissionsEnumerable is IPermissionsEnumerable, Permissions {
5555
_removeMember(role, account);
5656
}
5757

58+
function _setupRole(bytes32 role, address account) internal override {
59+
super._setupRole(role, account);
60+
_addMember(role, account);
61+
}
62+
5863
function _addMember(bytes32 role, address account) internal {
5964
uint256 idx = roleMembers[role].index;
6065
roleMembers[role].index += 1;

0 commit comments

Comments
 (0)