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

Optimize Ownable and Pausable modifiers' size impact #3347

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions contracts/access/Ownable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ abstract contract Ownable is Context {
_transferOwnership(_msgSender());
}

/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}

/**
* @dev Returns the address of the current owner.
*/
Expand All @@ -37,11 +45,10 @@ abstract contract Ownable is Context {
}

/**
* @dev Throws if called by any account other than the owner.
* @dev Throws if the sender is not the owner.
*/
modifier onlyOwner() {
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}

/**
Expand Down
32 changes: 23 additions & 9 deletions contracts/security/Pausable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ abstract contract Pausable is Context {
_paused = false;
}

/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}

/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
Expand All @@ -49,7 +42,7 @@ abstract contract Pausable is Context {
* - The contract must not be paused.
*/
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_requireNotPaused();
_;
}

Expand All @@ -61,10 +54,31 @@ abstract contract Pausable is Context {
* - The contract must be paused.
*/
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_requirePaused();
_;
}

/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}

/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}

/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}

/**
* @dev Triggers stopped state.
*
Expand Down