-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRACEFORETH.sol
55 lines (42 loc) · 1.55 KB
/
RACEFORETH.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
pragma solidity 0.4.21;
// How fast can you get to 100 points and win the prize?
// First person to deposit 0.1 eth (100 finney) wins the entire prize!
// 1 finney = 1 point
contract RACEFORETH {
// 100 points to win!
uint256 public SCORE_TO_WIN = 100 finney;
uint256 public PRIZE;
// 100 points = 0.1 ether
// Speed limit: 0.05 eth to prevent insta-win
// Prevents people from going too fast!
uint256 public speed_limit = 50 finney;
// Keep track of everyone's score
mapping (address => uint256) racerScore;
mapping (address => uint256) racerSpeedLimit;
uint256 latestTimestamp;
address owner;
function RACEFORETH () public payable {
PRIZE = msg.value;
owner = msg.sender;
}
function race() public payable {
if (racerSpeedLimit[msg.sender] == 0) { racerSpeedLimit[msg.sender] = speed_limit; }
require(msg.value <= racerSpeedLimit[msg.sender] && msg.value > 1 wei);
racerScore[msg.sender] += msg.value;
racerSpeedLimit[msg.sender] = (racerSpeedLimit[msg.sender] / 2);
latestTimestamp = now;
// YOU WON
if (racerScore[msg.sender] >= SCORE_TO_WIN) {
msg.sender.transfer(PRIZE);
}
}
function () public payable {
race();
}
// Pull the prize if no one has raced in 3 days :(
function endRace() public {
require(msg.sender == owner);
require(now > latestTimestamp + 3 days);
msg.sender.transfer(this.balance);
}
}