Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding internal function to set the owner of Ownable #2463

Closed
Amxx opened this issue Jan 8, 2021 · 3 comments
Closed

Adding internal function to set the owner of Ownable #2463

Amxx opened this issue Jan 8, 2021 · 3 comments

Comments

@Amxx
Copy link
Collaborator

Amxx commented Jan 8, 2021

Some pattern require an Ownable contract to change its owner under specific condition. This would for example be necessary to implement an OwnableClaimable contract for #2369 on top of the existing Ownable.

However, the current implmentation of Ownable can only be transfered using the public transferOwnership, which has the modifier onlyOwner.

I believe it would be better to have two function, one internal that does the change, and one public that gives restricted access to the internal.

abstract contract Ownable is Context {
    ...
    function renounceOwnership() public virtual onlyOwner {
        _setOwnership(address(0));
    }

    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _setOwnership(newOwner);
    }

    function _setOwnership(address newOwner) internal {
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}
@pavlovdog
Copy link

Good point! What do you think about completely removing constructor in favor of internal function? My struggle is that contracts with constructor can't be used with proxy pattern. So I should create custom Ownable to use it in implementation contract.

I can make a PR if this thing make sense.

@Amxx
Copy link
Collaborator Author

Amxx commented Jun 8, 2021

Removing the constructor would break backward compatibility, so its a big no.

For upgradeable contract, you should use OwnableUpgradeable from the @openzeppelin/contract-upgradeable package

@frangio
Copy link
Contributor

frangio commented Nov 30, 2021

Fixed in 4.4.

@frangio frangio closed this as completed Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants