Logo

Schedule a Query in the Future

Queries in the Future

Execution of queries can be scheduled on a future date. Users can decide to receive the response of their queries both after a certain period of time or on a certain time stamp. bridge_query function accepts an argument as delay parameter from the current time in seconds or a future time stamp on which query will be executed. It should be noted that in both methods the interval should not be more than 90 days. It means that for the case of delay time, this parameter should not be defined more than 3 days or 259,200 seconds and for the case of upcoming time stamp, difference between current time stamp and inserted argument should not be inserted more than 3 days or simply the argument should be less than current time stamp + 259,200. Otherwise user will be received an empty argument.

‚Äč you can see an example for each case in the following:

pragma solidity ^0.5.9;
import "./BridgePublicAPI.sol";
contract BTCprice is BridgePublicAPI {
function send_query() public {
bridge_query(30, "URL", "json(https://www.therocktrading.com/api/ticker/BTCEUR).result.0.last");
}
string public res;
event btcPrice(string _price);
function __callback(bytes32 _myid, string memory _result) public {
require(msg.sender == oracle_cbAddress());
res = _result;
emit btcPrice(_result);
}
}

In above example, the query will be executed exactly after 30 seconds of executing send_query function.

pragma solidity ^0.5.9;
import "./BridgePublicAPI.sol";
contract BTCprice is BridgePublicAPI {
function send_query() public {
bridge_query(now + 30, "URL", "json(https://www.therocktrading.com/api/ticker/BTCEUR).result.0.last");
}
string public res;
event btcPrice(string _price);
function __callback(bytes32 _myid, string memory _result) public {
require(msg.sender == oracle_cbAddress());
res = _result;
emit btcPrice(_result);
}
}

In above example the query will be executed exactly on timestamp of right now + 30 seconds.