Skip to content

Commit d42cb17

Browse files
authored
add modifier onlyOwner in Ownable (#185)
* add modifier onlyOwner in Ownable * make owner private
1 parent e44a8ca commit d42cb17

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

contracts/feature/Ownable.sol

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@ import "./interface/IOwnable.sol";
1111

1212
abstract contract Ownable is IOwnable {
1313
/// @dev Owner of the contract (purpose: OpenSea compatibility)
14-
address public override owner;
14+
address private _owner;
15+
16+
/// @dev Reverts if caller is not the owner.
17+
modifier onlyOwner() {
18+
if (msg.sender != _owner) {
19+
revert Ownable__NotAuthorized();
20+
}
21+
_;
22+
}
23+
24+
/// @dev Returns the owner of the contract.
25+
function owner() public view returns (address) {
26+
return _owner;
27+
}
1528

1629
/// @dev Lets a contract admin set a new owner for the contract. The new owner must be a contract admin.
1730
function setOwner(address _newOwner) external override {
@@ -23,8 +36,8 @@ abstract contract Ownable is IOwnable {
2336

2437
/// @dev Lets a contract admin set a new owner for the contract. The new owner must be a contract admin.
2538
function _setupOwner(address _newOwner) internal {
26-
address _prevOwner = owner;
27-
owner = _newOwner;
39+
address _prevOwner = _owner;
40+
_owner = _newOwner;
2841

2942
emit OwnerUpdated(_prevOwner, _newOwner);
3043
}

docs/Multiwrap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ function owner() external view returns (address)
624624

625625

626626

627-
627+
*Returns the owner of the contract.*
628628

629629

630630
#### Returns

docs/Ownable.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function owner() external view returns (address)
1818

1919

2020

21-
*Owner of the contract (purpose: OpenSea compatibility)*
21+
*Returns the owner of the contract.*
2222

2323

2424
#### Returns

docs/Pack.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ function owner() external view returns (address)
661661

662662

663663

664-
664+
*Returns the owner of the contract.*
665665

666666

667667
#### Returns

docs/SignatureDrop.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ function owner() external view returns (address)
722722

723723

724724

725-
725+
*Returns the owner of the contract.*
726726

727727

728728
#### Returns

docs/ThirdwebContract.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function owner() external view returns (address)
1818

1919

2020

21-
21+
*Returns the owner of the contract.*
2222

2323

2424
#### Returns

0 commit comments

Comments
 (0)