Skip to content

Commit

Permalink
reformat CoinToss.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Sep 17, 2024
1 parent 13a7274 commit 8e05274
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions solidity/src/CoinToss.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,12 @@ contract CoinToss is CadenceRandomConsumer {
return coinTosses[user] != 0;
}

/**
* @dev Checks if a value is non-zero.
*/
function isNonZero(uint256 value) public pure returns (bool) {
return value > 0;
}

/**
* @dev Allows a user to flip a coin by sending FLOW to the contract. This is the commit step in the commit-reveal scheme.
*/
function flipCoin() public payable {
require(isNonZero(msg.value), "Must send FLOW to place flip a coin");
require(!isNonZero(coinTosses[msg.sender]), "Must close previous coin flip before placing a new one");
require(_isNonZero(msg.value), "Must send FLOW to place flip a coin");
require(!_isNonZero(coinTosses[msg.sender]), "Must close previous coin flip before placing a new one");

// request randomness
uint256 requestId = _requestRandomness();
Expand Down Expand Up @@ -80,4 +73,11 @@ contract CoinToss is CadenceRandomConsumer {

emit CoinRevealed(msg.sender, requestId, coinFace, prize);
}

/**
* @dev Checks if a value is non-zero.
*/
function _isNonZero(uint256 value) internal pure returns (bool) {
return value > 0;
}
}

0 comments on commit 8e05274

Please sign in to comment.