Skip to content

Commit c41f431

Browse files
committed
Add a bool return to _grantRole and _revokeRole
1 parent 8de6eba commit c41f431

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
@@ -126,22 +126,22 @@ abstract contract AccessControlDefaultAdminRules is IAccessControlDefaultAdminRu
126126
* NOTE: Exposing this function through another mechanism may make the `DEFAULT_ADMIN_ROLE`
127127
* assignable again. Make sure to guarantee this is the expected behavior in your implementation.
128128
*/
129-
function _grantRole(bytes32 role, address account) internal virtual override {
129+
function _grantRole(bytes32 role, address account) internal virtual override returns (bool) {
130130
if (role == DEFAULT_ADMIN_ROLE) {
131131
require(defaultAdmin() == address(0), "AccessControl: default admin already granted");
132132
_currentDefaultAdmin = account;
133133
}
134-
super._grantRole(role, account);
134+
return super._grantRole(role, account);
135135
}
136136

137137
/**
138138
* @dev See {AccessControl-_revokeRole}.
139139
*/
140-
function _revokeRole(bytes32 role, address account) internal virtual override {
140+
function _revokeRole(bytes32 role, address account) internal virtual override returns (bool) {
141141
if (role == DEFAULT_ADMIN_ROLE && account == defaultAdmin()) {
142142
delete _currentDefaultAdmin;
143143
}
144-
super._revokeRole(role, account);
144+
return super._revokeRole(role, account);
145145
}
146146

147147
/**

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)