-
Notifications
You must be signed in to change notification settings - Fork 0
/
lottery.sol
34 lines (27 loc) · 1.01 KB
/
lottery.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
pragma solidity ^0.4.17;
contract Lottery {
address public manager;
address[] public players;
function Lottery() public {
manager = msg.sender;
}
function enter() public payable {
require(msg.value > .0001 ether);
players.push(msg.sender);
}
function random() private view returns (uint) {
return uint(keccak256(block.difficulty, now, players));
}
function pickWinner() public restricted {
uint index = random() % players.length;
players[index].transfer(this.balance);
players = new address[](0);
}
modifier restricted() {
require(msg.sender == manager);
_;
}
function getPlayers() public view returns (address[]) {
return players;
}
}