Skip to content

Instantly share code, notes, and snippets.

@jleeh
Created June 7, 2018 12:51
Show Gist options
  • Save jleeh/52c0d39972091413cb502b3ba19deb97 to your computer and use it in GitHub Desktop.
Save jleeh/52c0d39972091413cb502b3ba19deb97 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.23;
import "../Chainlinked.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
contract SpecAndRunRequester is Chainlinked, Ownable {
event RequestFulfilled(
bytes32 indexed requestId,
bytes32 indexed price
);
mapping(bytes32 => bytes32) requests;
mapping(bytes32 => bytes32) prices;
constructor(address _link, address _oracle) Ownable() public {
setLinkToken(_link);
setOracle(_oracle);
}
function requestPrice(string _base, string _quote) public {
string[] memory tasks = new string[](4);
tasks[0] = "assetprice";
tasks[1] = "copy";
tasks[2] = "ethuint256";
tasks[3] = "ethtx";
ChainlinkLib.Spec memory spec = newSpec(tasks, this, "fulfill(bytes32,bytes32)");
spec.add("base", _base);
spec.add("quote", _quote);
string[] memory path = new string[](1);
path[0] = "price";
spec.addStringArray("copyPath", path);
requests[chainlinkRequest(spec, LINK(1))] = keccak256(_base, _quote);
}
function cancelRequest(bytes32 _requestId) public onlyOwner {
cancelChainlinkRequest(_requestId);
}
function fulfill(bytes32 _requestId, bytes32 _price)
public
checkChainlinkFulfillment(_requestId)
{
emit RequestFulfilled(_requestId, _price);
prices[requests[_requestId]] = _price;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment