-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLottery.sol
More file actions
42 lines (34 loc) · 950 Bytes
/
Lottery.sol
File metadata and controls
42 lines (34 loc) · 950 Bytes
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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Lottery{
address public manager;
address[] public players;
constructor()
{
manager = msg.sender;
}
function enter() public payable
{
require(msg.value > .01 ether,"Low cache");
players.push(msg.sender);
}
function random() private view returns (uint)
{
return uint(keccak256(abi.encodePacked(block.difficulty,block.timestamp,players)));
}
function pickWinner() public payable restricted
{
uint index = random() % players.length;
payable(players[index]).transfer(address(this).balance);
players = new address[](0);
}
function getPlayers() public view returns ( address[] memory)
{
return players;
}
modifier restricted()
{
require(msg.sender == manager,"You are not a manager");
_;
}
}