Created
February 28, 2023 19:57
-
-
Save RomarQ/47a8a65359335bcfefc76327ec345ebd to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.19+commit.7dd6d404.js&optimize=false&runs=200&gist=
This file contains 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.8.0; | |
contract EntropyProvider { | |
bytes entropy; | |
uint last_update; | |
address processor; | |
constructor(address _processor) { | |
processor = _processor; | |
} | |
/** | |
* Receive entropy (random bytes) from an Acurast job. | |
*/ | |
function receive_entropy(bytes memory _entropy) public { | |
// Ensures that only the processor can call this function | |
require(msg.sender == processor, "NOT_ALLOWED"); | |
// Update entropy | |
entropy = _entropy; | |
last_update = block.timestamp; | |
} | |
/** | |
* A view that exposes the entropy to other contracts. | |
*/ | |
function consume_entropy(uint maxAge) public view returns (bytes memory) { | |
// Consumers can specify the maximum entropy age they are whiling to accept | |
require(block.timestamp - last_update <= maxAge, "ENTROPY_TOO_OLD"); | |
return entropy; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment