Created
February 15, 2019 04:45
-
-
Save gorgos/1462161398ed4718e77d0ae63352f71b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mapping (address => uint256) gameWeiValues; | |
mapping (address => uint256) blockHashesToBeUsed; | |
function playGame() public { | |
if (!blockHashesToBeUsed[msg.sender]) { | |
// first run, determine block hash to be used | |
blockHashesToBeUsed[msg.sender] = block.number + 2; // use 2 or more | |
gameWeiValues[msg.sender] = msg.value; | |
return; | |
} | |
uint256 randomNumber = uint256(blockhash(blockHashesToBeUsed[msg.sender])); | |
blockHashesToBeUsed[msg.sender] = 0; | |
gameWeiValues[msg.sender] = 0; | |
if (randomNumber != 0 || randomNumber % 2 == 0) { | |
uint256 winningAmount = gameWeiValues[msg.sender] * 2; | |
msg.sender.transfer(winningAmount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment