-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOwnable.sol
54 lines (47 loc) · 1.44 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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Ownable
* @dev Set & change owner. A modification of the sample contract on Remix.
*/
contract Ownable {
/**
* @dev Storage variable to keep track of the contract owner.
*/
address private owner;
/**
* @dev Event for EVM logging. Emitted during owner change or contract creation.
*/
event OwnerSet(address indexed oldOwner, address indexed newOwner);
/**
* @dev Modifier to check if the function caller is owner
*/
modifier requireOwner() {
// If the first argument of 'require' evaluates to 'false', execution terminates and all
// changes to the state and to Ether balances are reverted.
require(msg.sender == owner, "Caller is not owner");
_;
}
/**
* @dev Constructor. Sets the contract deployer as owner.
*/
constructor() {
owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor
emit OwnerSet(address(0), owner);
}
/**
* @dev Change owner
* @param newOwner address of new owner
*/
function changeOwner(address newOwner) public requireOwner {
emit OwnerSet(owner, newOwner);
owner = newOwner;
}
/**
* @dev Return owner address
* @return address of owner
*/
function getOwner() public view returns (address) {
return owner;
}
}