Skip to content

Commit 0e729b8

Browse files
committed
Added some docs to the contract
1 parent 2e055a7 commit 0e729b8

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

contracts/Lottery.sol

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@ pragma solidity ^0.8.12;
33

44
import "@openzeppelin/contracts/utils/Strings.sol";
55

6+
/**
7+
* @title Lottery game
8+
* @author Francisco Ramos
9+
* @notice Simple web3 game based on Udemy course
10+
* https://www.udemy.com/course/ethereum-and-solidity-the-complete-developers-guide/
11+
*/
612
contract Lottery {
13+
// Stores the owner of the contract
714
address public owner;
15+
16+
// keeps track of the people who enter the game
817
address payable[] public players;
918

1019
// We use it to emit some details about the pickWinner transaction
@@ -14,38 +23,61 @@ contract Lottery {
1423
address winner
1524
);
1625

26+
/**
27+
* @dev Stores the address of the person deploying the contract
28+
*/
1729
constructor() {
18-
// Address of the person deploying the contract
1930
owner = msg.sender;
2031
}
2132

22-
// Enforces a minimun amount of ether to be sent to a function
33+
/**
34+
* @dev Enforces a minimun amount of ether to be sent to a function
35+
* @param value The minimum amount to send
36+
*/
2337
modifier minimum(uint value) {
2438
string memory requiredMsg = string.concat("The minimum value required is ", Strings.toString(value));
2539
require(msg.value >= value, requiredMsg);
2640
_;
2741
}
2842

29-
// Makes sure the owner is the only one who can call a function
43+
/**
44+
* @dev Makes sure the owner is the only one who can call a function
45+
*/
3046
modifier restricted() {
3147
require(msg.sender == owner, "Only the owner of this contract can call the function");
3248
_;
3349
}
3450

51+
/**
52+
* @dev Will be called by the player who enters de game sending ether
53+
* and makes sure he/she is sending a minumun of 0.01 ether
54+
*/
3555
function enter() public payable minimum(.01 ether) {
3656
players.push(payable(msg.sender));
3757
}
3858

59+
/**
60+
* @dev Generates a pseudo random number
61+
* https://medium.com/0xcode/hashing-functions-in-solidity-using-keccak256-70779ea55bb0
62+
* https://docs.soliditylang.org/en/v0.8.17/abi-spec.html
63+
* @return index of the player within our list
64+
*/
3965
function random() private view returns (uint) {
40-
// See https://medium.com/0xcode/hashing-functions-in-solidity-using-keccak256-70779ea55bb0
41-
// See https://docs.soliditylang.org/en/v0.8.17/abi-spec.html
4266
return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, players)));
4367
}
4468

69+
/**
70+
* @dev Gets the list of players currently in the game
71+
* @return players
72+
*/
4573
function getPlayers() public view returns (address payable[] memory) {
4674
return players;
4775
}
4876

77+
/**
78+
* @dev Called by the manager, it picks a winner
79+
* emitting WinnerPicked event
80+
*/
4981
function pickWinner() public restricted {
5082
// Compute the (pseudo)random index of the winner
5183
uint index = random() % players.length;

0 commit comments

Comments
 (0)