-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLottery-Contract.sol
More file actions
48 lines (37 loc) · 1.07 KB
/
Copy pathLottery-Contract.sol
File metadata and controls
48 lines (37 loc) · 1.07 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
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Lottery Contract
* @author Franklin Ohaegbulam (@Frankiefab100)
*/
contract Lottery {
uint MAX_PLAYERS = 10;
address manager;
address winner;
address[] players;
constructor(){
manager = msg.sender;
}
function retrieveWinner() public view returns (address){
return winner;
}
function retrievePlayers() public view returns (address[] memory){
return players;
}
function result() public payable{
require(msg.value >= 0.05 ether);
require(players.length < MAX_PLAYERS);
players.push(msg.sender);
if (players.length == 10){
selectWinner();
}
}
function selectWinner() private {
uint index = random() % players.length;
winner = players[index];
payable(players[index]).transfer(address(this).balance);
}
function random() private view returns (uint) {
return uint (keccak256(abi.encodePacked(block.number, block.timestamp, players)));
}
}