-
Notifications
You must be signed in to change notification settings - Fork 0
/
Maxi_Lottery_Ethereum.sol
67 lines (50 loc) · 1.66 KB
/
Maxi_Lottery_Ethereum.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
61
62
63
64
65
66
67
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "./mlEthereum.sol";
contract MaxiLotteryETH {
bool lotteryClosed;
mlEthereum mlETH;
mapping(uint256 => address) public winners;
uint256 idLottery;
address payable[] public players;
address payable owner;
constructor(mlEthereum _mlETH) {
mlETH = _mlETH;
owner = payable(msg.sender);
}
function toggleLottery() external onlyOwner {
lotteryClosed = !lotteryClosed;
}
function pickWinner() external onlyOwner {
require(lotteryClosed, "Maxi Lottery ETH is open!");
uint256 winner = uint256(
keccak256(
abi.encodePacked(block.timestamp, block.difficulty, msg.sender)
)
) % players.length;
players[winner].transfer((address(this).balance / 100) * 90);
owner.transfer((address(this).balance / 100) * 10);
mlETH.mint(players[winner], 10 * 10**18);
winners[idLottery] = players[winner];
idLottery++;
players = new address payable[](0);
}
function play() external payable {
require(!lotteryClosed, "Maxi Lottery ETH is closed!");
require(
msg.value == 0.01 ether,
"Not enough funds provided! (Require: 0.01 ETH)"
);
players.push(payable(msg.sender));
}
function getBalance() external view returns (uint256) {
return address(this).balance;
}
function getWinner(uint256 _idLottery) external view returns (address) {
return winners[_idLottery];
}
modifier onlyOwner() {
require(msg.sender == owner, "Not the Owner");
_;
}
}