Skip to content

Instantly share code, notes, and snippets.

@eusthace811
Last active November 6, 2018 03:48
Show Gist options
  • Save eusthace811/9196f12d666e8feef777a66a379b2e32 to your computer and use it in GitHub Desktop.
Save eusthace811/9196f12d666e8feef777a66a379b2e32 to your computer and use it in GitHub Desktop.
Retrieve a list of casino games from an API using oraclise. Deployed at: 0xeb5828a8c5ca41e9519af53a02681aff9cd900e4 (https://ropsten.etherscan.io/address/0xeb5828a8c5ca41e9519af53a02681aff9cd900e4)
pragma solidity ^0.4.25;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol";
contract Games is usingOraclize, Ownable {
string private list;
mapping (bytes32 => bool) private pendingQueries;
event LogConstructorInitiated(string nextStep);
event LogGamesUpdated(string indexed games);
event LogNewOraclizeQuery(string description);
constructor() public {
emit LogConstructorInitiated("Constructor was initiated. Call 'updateGames()' to send the Oraclize Query.");
}
function __callback(bytes32 myid, string result) public {
if (msg.sender != oraclize_cbAddress()) revert();
require (pendingQueries[myid] == true);
list = result;
LogGamesUpdated(list);
delete pendingQueries[myid]; // This effectively marks the query id as processed.
}
function updateGames() public payable onlyOwner {
if (oraclize_getPrice("URL") > this.balance) {
LogNewOraclizeQuery("Oraclize query was NOT sent, please add some ETH to cover for the query fee");
} else {
LogNewOraclizeQuery("Oraclize query was sent, standing by for the answer...");
bytes32 queryId = oraclize_query("URL", "json(https://variusworldtech.github.io/Technical-Test/casino.json).game_list");
pendingQueries[queryId] = true;
}
}
function getGames() public view returns (string) {
return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment