status-teller-network/contracts/common/Ownable.sol

83 lines
2.4 KiB
Solidity

pragma solidity >=0.5.0 <0.6.0;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor () internal {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @dev is sender the owner of the contract?
* @return true if `msg.sender` is the owner of the contract.
*/
function isOwner() public view returns (bool) {
return msg.sender == _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Only the contract's owner can invoke this function");
_;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* Renouncing to ownership will leave the contract without an owner.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
*/
function renounceOwnership() external onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) external onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Get the contract's owner
* @return the address of the owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0), "New owner cannot be address(0)");
emit OwnershipTransferred(_owner, _newOwner);
_owner = _newOwner;
}
/**
* @dev Sets an owner address
* @param _newOwner new owner address
*/
function _setOwner(address _newOwner) internal {
_owner = _newOwner;
}
}