Skip to content

Commit ab95c72

Browse files
FIX: commitMoves function logic fixed
1 parent 01b1670 commit ab95c72

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

src/gameSessionfactoryContract.sol

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,20 @@ contract rockPaperScissorGame{
5858
hasStarted = true;
5959
}
6060
function commitMoves(string memory _move) external {
61+
require(player1.addr == msg.sender || player2.addr == msg.sender);
6162
require(validMove(_move), "Invalid Move");
6263

63-
if(msg.sender == player1.addr){
6464

65-
if( !(player1.hasCommitted) ) revert AlreadyCommitted();
66-
player1.committedMove = _move;
67-
player1.hasCommitted = true;
68-
69-
}else if(msg.sender == player2.addr){
70-
71-
if( !(player2.hasCommitted) ) revert AlreadyCommitted();
72-
player2.committedMove = _move;
73-
player2.hasCommitted = true;
74-
75-
} else{
76-
77-
78-
}
65+
if (msg.sender == player1.addr) {
66+
require(!player1.hasCommitted, "Already committed");
67+
player1.committedMove = _move;
68+
player1.hasCommitted = true;
69+
} else {
70+
require(!player2.hasCommitted, "Already committed");
71+
player2.committedMove = _move;
72+
player2.hasCommitted = true;
73+
}
74+
7975

8076
emit moveCommitted();
8177

0 commit comments

Comments
 (0)