Skip to content

Instantly share code, notes, and snippets.

@SergioDemianLerner
Created October 29, 2020 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SergioDemianLerner/79e3d9bd4a739fe96999e92c356b68b6 to your computer and use it in GitHub Desktop.
Save SergioDemianLerner/79e3d9bd4a739fe96999e92c356b68b6 to your computer and use it in GitHub Desktop.
CryptoRandomBlockhash
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