-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ownable.sol
73 lines (64 loc) · 2.08 KB
/
Ownable.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/**
* @notice Contract is a inheritable smart contract that will add a
* New modifier called onlyOwner available in the smart contract inherting it
*
* onlyOwner makes a function only callable from the Token owner
*
*/
contract Ownable {
// _owner is the owner of the Token
address private _owner;
/**
* Event OwnershipTransferred is used to log that a ownership change of the token has occured
*/
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* Modifier
* We create our own function modifier called onlyOwner, it will Require the current owner to be
* the same as msg.sender
*/
modifier onlyOwner() {
require(_owner == msg.sender, "Ownable: only owner can call this function");
// This _; is not a TYPO, It is important for the compiler;
_;
}
constructor() {
_owner = msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
/**
* @notice owner() returns the currently assigned owner of the Token
*
*/
function owner() public view returns(address) {
return _owner;
}
/**
* @notice renounceOwnership will set the owner to zero address
* This will make the contract owner less, It will make ALL functions with
* onlyOwner no longer callable.
* There is no way of restoring the owner
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @notice transferOwnership will assign the {newOwner} as owner
*
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @notice _transferOwnership will assign the {newOwner} as owner
*
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}