Skip to content

Instantly share code, notes, and snippets.

@RomarQ
Created March 1, 2023 07:22
Show Gist options
  • Save RomarQ/b6c8ae97c33b35b13386e763f8db92b3 to your computer and use it in GitHub Desktop.
Save RomarQ/b6c8ae97c33b35b13386e763f8db92b3 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.18+commit.87f61d96.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: None
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 willing 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