forked from paperinblock/LoFun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmartLotto.sol
60 lines (51 loc) · 1.58 KB
/
SmartLotto.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
60
pragma solidity ^0.4.13;
contract SmartLotto{
address public owner = msg.sender;
uint public N = 5;
uint public n;
address[] public sender;
uint[] public recvEther;
uint public totalEther;
uint[] blockTimeStamp;
uint256[] blockNumber;
address[] public winners;
uint public prize;
uint[] public prizes;
function ()public payable{
uint eth;
eth = msg.value;
if(eth < 0.001 ether) revert();
sender.push(msg.sender);
recvEther.push(msg.value);
blockTimeStamp.push(block.timestamp);
//blockHash.push(block.blockhash(block.number));
totalEther += eth;
n++;
if((n % N) == 0){
uint seed = block.timestamp; //uint(blockHash[blockHash.length - 1]);
uint winner = (seed % N) + n - N;
winners.push(sender[winner]);
prize = this.balance/10*8;
prizes.push(prize);
sender[winner].transfer(prize);
owner.transfer(this.balance);
//selfdestruct(owner);
}
}
function getLastSender() public constant returns(address[]){
return sender;
}
function getRecvEther() public constant returns(uint[]){
return recvEther;
}
function getBlockTimeStamp() public constant returns(uint[]){
return blockTimeStamp;
}
function getBalance() public constant returns(uint){
return this.balance;
}
function close() public{
if (owner != msg.sender) revert();
selfdestruct(owner);
}
}