/
Ownable.sol
56 lines (44 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
55
56
pragma solidity ^0.4.22;
//Math operations with safety checks that throw on error
library SafeMath {
//multiply
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
//divide
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
//subtract
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
//addition
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract Ownable {
address public contractOwner;
event TransferredOwnership(address indexed _previousOwner, address indexed _newOwner);
constructor() public {
contractOwner = msg.sender;
}
modifier ownerOnly() {
require(msg.sender == contractOwner);
_;
}
function transferOwnership(address _newOwner) public ownerOnly {
require(_newOwner != address(0));
contractOwner = _newOwner;
emit TransferredOwnership(contractOwner, _newOwner);
}
}