-
Notifications
You must be signed in to change notification settings - Fork 1
/
lottery.sol
57 lines (33 loc) · 1.06 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Lottery{
address public manager;
address payable[] public participants;
constructor(){
manager=msg.sender;
}
receive() external payable
{
require(msg.value==1 ether);
// return address(this).balance;
participants.push(payable(msg.sender));
}
function balance() public view returns(uint) {
require(msg.sender==manager);
return address(this).balance;
}
function randMod() public view returns(uint)
{
// increase nonce
return uint(keccak256(abi.encodePacked(block.timestamp,msg.sender,participants.length)));
}
function winner() public {
require(msg.sender==manager);
require(participants.length>=3);
uint i=randMod();
address payable king;
uint index= i%participants.length;
king=participants[index];
king.transfer(balance());
}
}