- Share this text:
Untitled - posted by guest on 24th January 2020 11:59:55 PM
pragma solidity ^0.5.16;
import "https://github.com/provable-things/ethereum-api/blob/master/provableAPI.sol";
contract Adjustable is usingProvable{
uint private gasLimit = 300000;
string constant private DATASOURCE = "URL";
uint private _fee;
constructor () public {
updateGasPrice(4 * 10**9);
}
function updateFee() public {
_fee = provable_getPrice(DATASOURCE, gasLimit);
}
function updateGasPrice(uint input) internal {
provable_setCustomGasPrice(input);
updateFee();
}
function updateGasLimit(uint input) internal {
gasLimit = input;
updateFee();
}
function sendQuery(string memory input) internal returns (bytes32){
return provable_query(DATASOURCE, input, gasLimit);
}
function fee() public view returns (uint){
return _fee;
}
}
contract Pricer is Adjustable{
string private QUERY = "json(https://ethgasstation.info/json/ethgasAPI.json).average";
uint public average;
constructor () public {
}
function __callback(bytes32 myid, string memory input) public {
require(msg.sender == provable_cbAddress());
average = parseInt(input, 8);
updateGasPrice(average);
}
function () external payable {
updateFee();
bytes32 myid = sendQuery(QUERY);
msg.sender.transfer( address(this).balance );
}
}