-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathInheritance.sol
59 lines (45 loc) · 1.29 KB
/
Inheritance.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
pragma solidity ^0.5.8;
contract SafeMath {
function add(int a, int b) internal pure returns (int) {
int c = a + b;
require(c >= a, "Addition: Interger overflow");
return c;
}
function subtract(int a, int b) internal pure returns (int) {
require(a >= b, "Subtract: Interger underflow");
int c = a - b;
return c;
}
function multiply(int a, int b) internal pure returns (int) {
if (a == 0 || b == 0) {
return 0;
}
int c = a * b;
require(c / a == b, "Multiplication: Interger overflow");
return c;
}
}
contract Owned {
address contractOwner;
constructor() public {
contractOwner = msg.sender;
}
modifier onlyOwner() {
require(contractOwner == msg.sender, "Only Contract Owner is authorized");
_;
}
function changeOwner(address newOwner) public onlyOwner {
contractOwner = newOwner;
}
}
contract IntergerState is Owned, SafeMath {
int256 x;
uint private lastStateChange;
function stateVar() public onlyOwner returns(int) {
x = add(x, int(now % 256));
x = multiply(x, int(now - lastStateChange));
x = subtract(x, int(block.gaslimit));
lastStateChange = now;
return x;
}
}