A rock-papers-scissors implementation on Solidity for the Security course at Universidad Austral
This link explains essentially the project structure.
- We should be able to create multiple matches simultaneously
- For each match we only have two players
- Each match consists of only on play
- For each match the amount needed to play must be declared (should be paid in WEI)
- To join a match you must pay the same as player 1
- The winning player takes everything. If it's a draw they both take back what they bet
- A match must be cancelable by player 1 (the creating player)
- After a user made its play then the other player has a timeout to make the play
We MUST use OpenZeppelin to get both Ownable and SafeMath
- Solidity basic structures and types
- Solidity Events
- Solidity Maps
- Storage and memory explained
- Ownable and OpenZeppelin
- Only Owner
- Time
- View Functions
- Using fors
- Send vs Transfer
- We don't have to store old matches. As soon as a match finishes we can discard it
- In order to create a game there must not be any other current games with the same bet
- E.g.,: if I bet 1 wei and there are no current games then I create a new game. If another player subscribes a bet but for 2 wei then another match gets created.
- At this stage there is a new game that contains only a bet and the player1
- Player 1 can delete this match as soon as no one subscribes to his game. This would delete the game
- Matches must die after ten minutes (?) of its original creation
- Another player could be added as player 2 of that game, if that player subscribes the same amount of wei.
- Once this happens the game status gets updated, and it cannot longer get deleted by any players.
- An event must be created to notify the first player about the change of state in its game
- We should be able to query the state of our games (maybe)
- A timer starts forcing both players to play within that time.
- Plays are simple: you can either play PAPER, ROCK or SCISSORS.
- After a play we emit an event and another timeout is created, now to two minutes. The other player must play within that time
- Plays cannot be changed
- After each play we must check if the game is over or not
- If the game is over it's a matter of computing the winner
- We must
transfer
the winning player the bet amount
- Create a Factory contract with player 1
- Deactivate the factory with the
updateOpenForGames
function set to false - Try to create a game trying to
register
. It will not allow it - Change to player2 and try to
register
. It will not allow it. - As player2 try to
updateOpenForGames
to true. It will not allow it. - Back to player1, open the factory (
updateOpenForGames
to true)
- As player1
register
a game with just one wei. It will allow it - As player2 try to
cancel
the game created by player one. The game key is the value passed to create it. It will not allow it - As player1 try to
cancel
the game created by yourself. It will allow it - As player1
register
a game with just one wei. It will allow it - As player 2
register
a game one wei. It will create a new game. Look for the game address in the logs and connect to it. Remember to select the factory contract and use thetoAddress
feature, not theDeploy
button.
- As player 3 try to make a
move
in the new Match. It will not allow it. - As player 1 create a new
move
. Moves consist of a string that has first the Move ("r", "p", "s") and then your password. You must encode this move using keccack256 and pass it adding a "0x" at the beginning. Use "rMySecretPassword" as move. - As player 1 try to repeat the move. It will not allow it.
- As player 1 try
revealMove
your move. Reveals consist of the decoded move string and the keccak of it. It will not allow it. - As player 2
move
, following the same steps than the player 1, but move "pMyOtherSecretPassword". - As player 1 try to
revealMove
your move. It will allow it. - As player 2 try to
revealMove
your move. It will allow it. This will output the result. It should be a player 2 win.