Last active
July 29, 2020 11:37
-
-
Save chriseth/a183d858bb4184197d2d0dc4a7023faa to your computer and use it in GitHub Desktop.
Oracle
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
struct Query | |
{ | |
uint id; | |
function(uint, bytes memory) external callback; | |
} | |
contract Oracle | |
{ | |
event Queried(bytes,function(uint, bytes memory) external); | |
Query[] public queries; | |
uint public price; | |
address immutable owner = msg.sender; | |
modifier onlyowner { require(msg.sender == owner); _; } | |
function query(bytes calldata q, function(uint, bytes memory) external callback) public payable returns (uint id) { | |
require(msg.value == price); | |
id = queries.length; | |
queries.push(Query(id, callback)); | |
emit Queried(q, callback); | |
} | |
function resolve(uint id, bytes calldata response) onlyowner public { | |
Query memory q = queries[id]; | |
delete queries[id]; | |
q.callback(id, response); | |
} | |
function withdraw() onlyowner public { | |
msg.sender.transfer(address(this).balance); | |
} | |
function setPrice(uint _price) onlyowner public { | |
price = _price; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment