-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHellhole.sol
More file actions
59 lines (50 loc) · 1.73 KB
/
Hellhole.sol
File metadata and controls
59 lines (50 loc) · 1.73 KB
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.4.19;
/*
Relatively straightforward implementation of the original scheme specified here:
https://www.reddit.com/r/Buttcoin/comments/7sws4d/ladies_and_gentlemen_i_have_an_innovative_idea/
*/
contract Hellhole {
uint constant minimum_click_amount = 1 finney;
uint constant last_n_payouts = 100;
uint constant click_time_extension = 24 hours;
struct Click {
address sender;
uint amount;
bool paid;
}
LastNBid[last_n_payouts] public payouts;
uint public next_payout_pointer = 0;
uint public end_time;
uint public pot = 0;
function Hellhole() public payable {
end_time = now + click_time_extension;
//Summon Moloch with a sacrifice of money
pot += msg.value;
}
function click() public payable {
require(now <= end_time);
require(msg.value >= minimum_click_amount);
end_time = now + click_time_extension;
pot += msg.value;
payouts[next_payout_pointer] = LastNBid({
sender: msg.sender,
amount: msg.value,
paid: false
});
next_payout_pointer = (next_payout_pointer + 1) % last_n_payouts;
}
function withdraw() public {
require(now > end_time);
uint lastSendersTotal = 0;
uint senderAmount = 0;
for(uint8 i = 0; i < last_n_payouts; i++){
lastSendersTotal += payouts[i].amount;
if(!payouts[i].paid && payouts[i].sender == msg.sender){
senderAmount += payouts[i].amount;
payouts[i].paid = true;
}
}
uint winnings = (pot * senderAmount) / lastSendersTotal;
msg.sender.transfer(winnings);
}
}