Skip to content

Commit 196ebe3

Browse files
committed
Add a bool return to _grantRole and _revokeRole
1 parent ab49b3f commit 196ebe3

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

contracts/access/AccessControl.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,13 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
225225
*
226226
* May emit a {RoleGranted} event.
227227
*/
228-
function _grantRole(bytes32 role, address account) internal virtual {
228+
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
229229
if (!hasRole(role, account)) {
230230
_roles[role].members[account] = true;
231231
emit RoleGranted(role, account, _msgSender());
232+
return true;
233+
} else {
234+
return false;
232235
}
233236
}
234237

@@ -239,10 +242,13 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
239242
*
240243
* May emit a {RoleRevoked} event.
241244
*/
242-
function _revokeRole(bytes32 role, address account) internal virtual {
245+
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
243246
if (hasRole(role, account)) {
244247
_roles[role].members[account] = false;
245248
emit RoleRevoked(role, account, _msgSender());
249+
return true;
250+
} else {
251+
return false;
246252
}
247253
}
248254
}

contracts/access/AccessControlDefaultAdminRules.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,22 @@ abstract contract AccessControlDefaultAdminRules is IAccessControlDefaultAdminRu
125125
* NOTE: Exposing this function through another mechanism may make the `DEFAULT_ADMIN_ROLE`
126126
* assignable again. Make sure to guarantee this is the expected behavior in your implementation.
127127
*/
128-
function _grantRole(bytes32 role, address account) internal virtual override {
128+
function _grantRole(bytes32 role, address account) internal virtual override returns (bool) {
129129
if (role == DEFAULT_ADMIN_ROLE) {
130130
require(defaultAdmin() == address(0), "AccessControl: default admin already granted");
131131
_currentDefaultAdmin = account;
132132
}
133-
super._grantRole(role, account);
133+
return super._grantRole(role, account);
134134
}
135135

136136
/**
137137
* @dev See {AccessControl-_revokeRole}.
138138
*/
139-
function _revokeRole(bytes32 role, address account) internal virtual override {
139+
function _revokeRole(bytes32 role, address account) internal virtual override returns (bool) {
140140
if (role == DEFAULT_ADMIN_ROLE && account == _currentDefaultAdmin) {
141141
delete _currentDefaultAdmin;
142142
}
143-
super._revokeRole(role, account);
143+
return super._revokeRole(role, account);
144144
}
145145

146146
/**

contracts/access/AccessControlEnumerable.sol

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,22 @@ abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessCon
4949
/**
5050
* @dev Overload {_grantRole} to track enumerable memberships
5151
*/
52-
function _grantRole(bytes32 role, address account) internal virtual override {
53-
super._grantRole(role, account);
54-
_roleMembers[role].add(account);
52+
function _grantRole(bytes32 role, address account) internal virtual override returns (bool) {
53+
bool granted = super._grantRole(role, account);
54+
if (granted) {
55+
_roleMembers[role].add(account);
56+
}
57+
return granted;
5558
}
5659

5760
/**
5861
* @dev Overload {_revokeRole} to track enumerable memberships
5962
*/
60-
function _revokeRole(bytes32 role, address account) internal virtual override {
61-
super._revokeRole(role, account);
62-
_roleMembers[role].remove(account);
63+
function _revokeRole(bytes32 role, address account) internal virtual override returns (bool) {
64+
bool revoked = super._revokeRole(role, account);
65+
if (revoked) {
66+
_roleMembers[role].remove(account);
67+
}
68+
return revoked;
6369
}
6470
}

0 commit comments

Comments
 (0)