I am learning to use Oraclize to connect it to random.org to generate random numbers.
Here's my test contract code:
pragma solidity ^0.4.25;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
import "github.com/willitscale/solidity-util/lib/Strings.sol";
import "github.com/willitscale/solidity-util/lib/Integers.sol";
import "github.com/willitscale/solidity-util/lib/Addresses.sol";
contract Oraclize is usingOraclize {
using Strings for string;
using Integers for uint;
using Addresses for address;
string public randomNumbers;
uint[] public randomNumbersArray;
event newOraclizeQuery(string description);
event randomNumbersGenerated(string randomNumbers);
constructor() public {
update();
}
function __callback(bytes32, string result) public {
if (msg.sender != oraclize_cbAddress()) revert();
randomNumbers = result;
string[] storage split = result.split(" ");
for (uint i = 0; i < split.length; i++) {
randomNumbersArray.push(parseInt(split[i]));
}
emit randomNumbersGenerated(randomNumbers);
}
function update() public payable {
emit newOraclizeQuery("Loading new set of random numbers, standing by for the answer...");
oraclize_query('URL', '...');
}
}
I've tested the above on http://remix.ethereum.org via Rinkeyby testnet. I deployed the contract and then called the update()
function and then checked on both of the public fields and they were empty / 0:
What am I doing wrong here?
When I take out the random number splitting by space part of the code, the callback then start working.
Any ideas?