Added RichErrors to Ownable
This commit is contained in:
committed by
Amir Bandeali
parent
55246c5d87
commit
a0602c8863
28
contracts/utils/contracts/src/MixinOwnableRichErrors.sol
Normal file
28
contracts/utils/contracts/src/MixinOwnableRichErrors.sol
Normal file
@@ -0,0 +1,28 @@
|
||||
pragma solidity ^0.5.9;
|
||||
|
||||
import "./RichErrors.sol";
|
||||
|
||||
|
||||
contract MixinOwnableRichErrors is
|
||||
RichErrors
|
||||
{
|
||||
// bytes4(keccak256("OnlyOwnerError(address,address)"))
|
||||
bytes4 internal constant ONLY_OWNER_SELECTOR =
|
||||
0x1de45ad1;
|
||||
|
||||
// solhint-disable func-name-mixedcase
|
||||
function OnlyOwnerError(
|
||||
address sender,
|
||||
address owner
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
ONLY_OWNER_SELECTOR,
|
||||
sender,
|
||||
owner
|
||||
);
|
||||
}
|
||||
}
|
@@ -1,9 +1,11 @@
|
||||
pragma solidity ^0.5.9;
|
||||
|
||||
import "./interfaces/IOwnable.sol";
|
||||
import "./MixinOwnableRichErrors.sol";
|
||||
|
||||
|
||||
contract Ownable is
|
||||
MixinOwnableRichErrors,
|
||||
IOwnable
|
||||
{
|
||||
address public owner;
|
||||
@@ -15,10 +17,12 @@ contract Ownable is
|
||||
}
|
||||
|
||||
modifier onlyOwner() {
|
||||
require(
|
||||
msg.sender == owner,
|
||||
"ONLY_CONTRACT_OWNER"
|
||||
);
|
||||
if (msg.sender != owner) {
|
||||
_rrevert(OnlyOwnerError(
|
||||
msg.sender,
|
||||
owner
|
||||
));
|
||||
}
|
||||
_;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user