Skip to content
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

Merged
merged 3 commits into from
Jul 1, 2024
Merged

lottery contract, tests and demo script #17

merged 3 commits into from
Jul 1, 2024

Conversation

kitounliu
Copy link
Collaborator

No description provided.

Copy link
Contributor

@souradeep-das souradeep-das left a 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");
Copy link
Contributor

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?

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);
Copy link
Contributor

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) {
Copy link
Contributor

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

Copy link
Collaborator Author

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.

Copy link
Contributor

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");
Copy link
Contributor

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?

@kitounliu kitounliu merged commit 0caefef into main Jul 1, 2024
1 check passed
@kitounliu kitounliu deleted the lottery branch July 30, 2024 16:10
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants