Created
October 29, 2020 18:34
-
-
Save SergioDemianLerner/79e3d9bd4a739fe96999e92c356b68b6 to your computer and use it in GitHub Desktop.
CryptoRandomBlockhash
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
pragma solidity >=0.4.0 <0.7.0; | |
contract CryptoRandomBlockhash { | |
bool waitForRandom; | |
uint deadline; | |
function debug_queryLastRskBlockHash() public view returns (bytes32) { | |
return rskHeaderHash(block.number - 1); | |
} | |
function isRandomSeedReady() public view returns (bool) { | |
if (!waitForRandom) | |
return false; | |
require(block.number<deadline+256); | |
// Assure the deadline block has been mined, and it has 60 | |
// confirmations (30 minutes) | |
return block.number>=deadline+60; | |
} | |
function getRandomSeed() public returns (bytes32) { | |
require(isRandomSeedReady()); | |
waitForRandom = false; | |
return rskHeaderHash(deadline); | |
} | |
function startWaitForRandomValue() public { | |
// Wait approximately one hour | |
deadline = block.number+120; | |
waitForRandom = true; | |
} | |
function rskHeaderHash(uint bdeadline) public view returns (bytes32) { | |
bytes32 x =blockhash(bdeadline); | |
return x; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment