Unverified Commit 7237b167 by Hadrien Croubois Committed by GitHub

Make some private functions internal to allow the developpement of…

Make some private functions internal to allow the developpement of "withSignature" functions (like permit) (#2568)

* add internal _setOwner in Ownable

* address issues raised in #2567

* updte changelog entry

* improve changelog and documentation

* rephrasing doc

* add cahngelog improvement lost in merge

* notify deprecation of _setupRole in changelog

* Demote caution to note

* Update CHANGELOG.md

Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
parent 5e34a84d
# Changelog # Changelog
## Unreleased
* `Ownable`: add an internal `_transferOwnership(address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568))
* `AccessControl`: add internal `_grantRole(bytes32,address)` and `_revokeRole(bytes32,address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568))
* `AccessControl`: mark `_setupRole(bytes32,address)` as deprecated in favor of `_grantRole(bytes32,address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568))
## 4.3.1 ## 4.3.1
* `TimelockController`: Add additional isOperationReady check. * `TimelockController`: Add additional isOperationReady check.
......
...@@ -178,6 +178,8 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 { ...@@ -178,6 +178,8 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
* Using this function in any other way is effectively circumventing the admin * Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}. * system imposed by {AccessControl}.
* ==== * ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/ */
function _setupRole(bytes32 role, address account) internal virtual { function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account); _grantRole(role, account);
...@@ -194,14 +196,24 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 { ...@@ -194,14 +196,24 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
emit RoleAdminChanged(role, previousAdminRole, adminRole); emit RoleAdminChanged(role, previousAdminRole, adminRole);
} }
function _grantRole(bytes32 role, address account) private { /**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) { if (!hasRole(role, account)) {
_roles[role].members[account] = true; _roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender()); emit RoleGranted(role, account, _msgSender());
} }
} }
function _revokeRole(bytes32 role, address account) private { /**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) { if (hasRole(role, account)) {
_roles[role].members[account] = false; _roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender()); emit RoleRevoked(role, account, _msgSender());
......
...@@ -25,7 +25,7 @@ abstract contract Ownable is Context { ...@@ -25,7 +25,7 @@ abstract contract Ownable is Context {
* @dev Initializes the contract setting the deployer as the initial owner. * @dev Initializes the contract setting the deployer as the initial owner.
*/ */
constructor() { constructor() {
_setOwner(_msgSender()); _transferOwnership(_msgSender());
} }
/** /**
...@@ -51,7 +51,7 @@ abstract contract Ownable is Context { ...@@ -51,7 +51,7 @@ abstract contract Ownable is Context {
* thereby removing any functionality that is only available to the owner. * thereby removing any functionality that is only available to the owner.
*/ */
function renounceOwnership() public virtual onlyOwner { function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0)); _transferOwnership(address(0));
} }
/** /**
...@@ -60,10 +60,14 @@ abstract contract Ownable is Context { ...@@ -60,10 +60,14 @@ abstract contract Ownable is Context {
*/ */
function transferOwnership(address newOwner) public virtual onlyOwner { function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address"); require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner); _transferOwnership(newOwner);
} }
function _setOwner(address newOwner) private { /**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner; address oldOwner = _owner;
_owner = newOwner; _owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner); emit OwnershipTransferred(oldOwner, newOwner);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment