-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_Storage.sol
45 lines (33 loc) · 844 Bytes
/
1_Storage.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Storage
* @dev Store & retrieve value in a variable
*/
contract Storage {
uint256 consecutiveWins;
uint256 lastHash;
uint256 FACTOR = 57896044618658097711785492504343953926634992332820282019728792003956564819968;
bool public OP;
uint256 public coinFlip;
constructor() public {
consecutiveWins = 0;
}
function flip(uint256 _number) public returns (bool) {
uint256 blockValue = uint256(_number - 1);
if (lastHash == blockValue) {
revert();
}
lastHash = blockValue;
coinFlip = blockValue/FACTOR;
bool side = coinFlip == 1 ? true : false;
OP = side;
if (side == OP) {
consecutiveWins++;
return true;
} else {
consecutiveWins = 0;
return false;
}
}
}