-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lottery contract, tests and demo script #17
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, great work!
} | ||
|
||
function enter() public payable { | ||
require(contractPhase == Status.Open, "Not open yet"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just checking - do you want to have one entry per wallet condition here?
contracts/lottery.sol
Outdated
shuffle(); // Shuffle the players array | ||
// The winner is the first player in the shuffled array | ||
// The permutation is randomly generated so we can also take more winners if needed | ||
players[0].transfer(address(this).balance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while this isn't affected, it's a good practice to use call.value() instead of transfer(), so lets update that!
https://consensys.github.io/smart-contract-best-practices/development-recommendations/general/external-calls/#dont-use-transfer-or-send
} | ||
|
||
|
||
function getPlayers() public view returns (address payable[] memory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method isn't necessary - lets lean on calling players() instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
players() can only be called on each element. It is not convenient for reading the whole list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the ideal way is for the script to do the heavy lifting - and reducing the contract size hence. But since this is a demo feel free to use your preference.
} | ||
|
||
function pickWinner() public onlyOwner { | ||
require(players.length > 0, "No players"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets add in a require(contractPhase == open) to avoid the option to re-call this method again?
No description provided.