I have an Oraclize query like the following:
function __callback(bytes32 myid, string result) onlyOraclize {
// do things
update();
}
function update() payable onlyOwnerOrOraclize {
string memory part1 = "[URL] ['json(https://api.random.org/json-rpc/1/invoke).result.random.data.0', '\\n{\"jsonrpc\":\"2.0\",\"method\":\"generateIntegers\",\"params\":{\"apiKey\":${[decrypt] BAKDeam1gVg++DgtVnOA3WuDkzbAaRgY4xOXmdvSQSteMyI94gNWyWcc0uDpVJtikYyzClR6Kvw5xbEswpJryBwNirC7sKsP23rQovooh1xQxBlId6cNgwb5UBzidOB0dVvl7EntjRxRZmSVBihSjpSEa7TRPjU=},\"n\":1,\"min\":0,\"max\":";
string memory maxRandomNumber = uint2str(3);
string memory part2 = ",\"replacement\":true,\"base\":10${[identity] \"}\"},\"id\":1${[identity] \"}\"}']";
string query = strConcat(part1, maxRandomNumber, part2);
bytes32 rngId = oraclize_query(60, "nested", query);
}
While I have a contract with plenty of Ether in it, the default gas limit for Oraclize calls (200000) isn't enough (unless I comment out update();
in the callback so the query only runs once). Per the docs (https://docs.oraclize.it/#ethereum-quick-start-custom-gas-limit-and-gas-price) setting the gas limit should just be the 4th parameter in the oraclize_query
. But if I try the following (to set gas at 500000):
bytes32 rngId = oraclize_query(60, "nested", query, 500000);
The query doesn't get run at all. Why would this be?
As a sidenote, without a nested query with encrypted API key, and just doing it as follows:
oraclize_query(60, "URL", "json(https://api.random.org/json-rpc/1/invoke).result.random.data.0", '\n{"jsonrpc":"2.0","method":"generateIntegers","params":{"apiKey":"my-api-key","n":1,"min":0,"max":3,"replacement":true,"base":10},"id":1}');
200000 gas is enough for it to run as many times as it needs as long as the contract has Ether in it. But with a nested/encrypted query it needs more gas.