-
-
Save hrkrshnn/1025ec2b7672b1a1e2e40b2ab9508a75 to your computer and use it in GitHub Desktop.
A contract with a bad design
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Bet { | |
address user; | |
uint bet; | |
bool won; | |
} | |
contract Lottery { | |
address immutable owner = msg.sender; | |
Bet[] bets; | |
// store how much each user | |
uint winnings; | |
function deposit(uint bet) payable external { | |
require(msg.value == 1 ether); | |
bets.push(Bet(msg.sender, bet, false)); | |
} | |
function pickWinner() external { | |
require(owner == msg.sender); | |
uint winning_number = 0; | |
uint winners = 0; | |
// Imagine some magic code for generating randomness | |
// and assigning to the variable winning_number | |
for (uint i = 0; i < bets.length; i++) { | |
if (bets[i].bet == winning_number) { | |
bets[i].won = true; | |
winners++; | |
} | |
} | |
winnings = address(this).balance / winners; | |
} | |
function claim() external { | |
// function that allows people to claim | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment