ETH Price: $2,452.87 (+2.01%)

Transaction Decoder

Block:
9697271 at Mar-18-2020 06:38:49 PM +UTC
Transaction Fee:
0.00110753 ETH $2.72
Gas Used:
110,753 Gas / 10 Gwei

Emitted Events:

3 Oraclize.0xb76d0edd90c6a07aa3ff7a222d7f5933e29c6acc660c059c97837f05c4ca1a84( 0xb76d0edd90c6a07aa3ff7a222d7f5933e29c6acc660c059c97837f05c4ca1a84, 000000000000000000000000e567ffa8c83c588b378a14f5e4ef955285888ee4, f03c849d0657acf773dd992077e8ca397eeafc292473493c206129c55f11694f, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000100, 0000000000000000000000000000000000000000000000000000000000000140, 000000000000000000000000000000000000000000000000000000000007a120, 0000000000000000000000000000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000000, 000000000000000000000000000000000000000000000000000000000000000c, 576f6c6672616d416c7068610000000000000000000000000000000000000000, 0000000000000000000000000000000000000000000000000000000000000020, 72616e646f6d206e756d626572206265747765656e203020616e642031303030 )

Account State Difference:

  Address   Before After State Difference Code
0x3dBDc81a...e395fDcf6 2.98736179493459155 Eth2.99760275879001323 Eth0.01024096385542168
0x42D69871...3AA5Ac59a
0.755489714224878478 Eth
Nonce: 35
0.754382184224878478 Eth
Nonce: 36
0.00110753
(AntPool 2)
725.343579502779386295 Eth725.344687032779386295 Eth0.00110753
0xe567ffa8...285888Ee4 0.19855421686746992 Eth0.18831325301204824 Eth0.01024096385542168

Execution Trace

SnakesAndLadders.play( amount=10000000000000000 )
  • OraclizeAddrResolver.CALL( )
  • Oraclize.2ef3accc( )
  • ETH 0.01024096385542168 Oraclize.c51be90f( )
    File 1 of 3: SnakesAndLadders
    {"provableAPI_0.4.25.sol":{"content":"// \u003cprovableAPI\u003e\n// Release targetted at solc 0.4.25 to silence compiler warning/error messages, compatible down to 0.4.22\n\n/*\nCopyright (c) 2015-2016 Oraclize SRL\nCopyright (c) 2016-2019 Oraclize LTD\nCopyright (c) 2019 Provable Things Limited\n\n\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\n\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\n\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n*/\n\npragma solidity \u003e= 0.4.22 \u003c 0.5;// Incompatible compiler version... please select one stated within pragma solidity or use different provableAPI version\n\ncontract ProvableI {\n    address public cbAddress;\n    function query(uint _timestamp, string _datasource, string _arg) external payable returns (bytes32 _id);\n    function query_withGasLimit(uint _timestamp, string _datasource, string _arg, uint _gaslimit) external payable returns (bytes32 _id);\n    function query2(uint _timestamp, string _datasource, string _arg1, string _arg2) public payable returns (bytes32 _id);\n    function query2_withGasLimit(uint _timestamp, string _datasource, string _arg1, string _arg2, uint _gaslimit) external payable returns (bytes32 _id);\n    function queryN(uint _timestamp, string _datasource, bytes _argN) public payable returns (bytes32 _id);\n    function queryN_withGasLimit(uint _timestamp, string _datasource, bytes _argN, uint _gaslimit) external payable returns (bytes32 _id);\n    function getPrice(string _datasource) public returns (uint _dsprice);\n    function getPrice(string _datasource, uint gaslimit) public returns (uint _dsprice);\n    function setProofType(byte _proofType) external;\n    function setCustomGasPrice(uint _gasPrice) external;\n    function randomDS_getSessionPubKeyHash() external constant returns(bytes32);\n}\n\ncontract OracleAddrResolverI {\n    function getAddress() public returns (address _addr);\n}\n\n/*\nBegin solidity-cborutils\n\nhttps://github.com/smartcontractkit/solidity-cborutils\n\nMIT License\n\nCopyright (c) 2018 SmartContract ChainLink, Ltd.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n */\n\nlibrary Buffer {\n    struct buffer {\n        bytes buf;\n        uint capacity;\n    }\n\n    function init(buffer memory buf, uint _capacity) internal pure {\n        uint capacity = _capacity;\n        if(capacity % 32 != 0) capacity += 32 - (capacity % 32);\n        // Allocate space for the buffer data\n        buf.capacity = capacity;\n        assembly {\n            let ptr := mload(0x40)\n            mstore(buf, ptr)\n            mstore(ptr, 0)\n            mstore(0x40, add(ptr, capacity))\n        }\n    }\n\n    function resize(buffer memory buf, uint capacity) private pure {\n        bytes memory oldbuf = buf.buf;\n        init(buf, capacity);\n        append(buf, oldbuf);\n    }\n\n    function max(uint a, uint b) private pure returns(uint) {\n        if(a \u003e b) {\n            return a;\n        }\n        return b;\n    }\n\n    /**\n     * @dev Appends a byte array to the end of the buffer. Resizes if doing so\n     *      would exceed the capacity of the buffer.\n     * @param buf The buffer to append to.\n     * @param data The data to append.\n     * @return The original buffer.\n     */\n    function append(buffer memory buf, bytes data) internal pure returns(buffer memory) {\n        if(data.length + buf.buf.length \u003e buf.capacity) {\n            resize(buf, max(buf.capacity, data.length) * 2);\n        }\n\n        uint dest;\n        uint src;\n        uint len = data.length;\n        assembly {\n        // Memory address of the buffer data\n            let bufptr := mload(buf)\n        // Length of existing buffer data\n            let buflen := mload(bufptr)\n        // Start address = buffer address + buffer length + sizeof(buffer length)\n            dest := add(add(bufptr, buflen), 32)\n        // Update buffer length\n            mstore(bufptr, add(buflen, mload(data)))\n            src := add(data, 32)\n        }\n\n        // Copy word-length chunks while possible\n        for(; len \u003e= 32; len -= 32) {\n            assembly {\n                mstore(dest, mload(src))\n            }\n            dest += 32;\n            src += 32;\n        }\n\n        // Copy remaining bytes\n        uint mask = 256 ** (32 - len) - 1;\n        assembly {\n            let srcpart := and(mload(src), not(mask))\n            let destpart := and(mload(dest), mask)\n            mstore(dest, or(destpart, srcpart))\n        }\n\n        return buf;\n    }\n\n    /**\n     * @dev Appends a byte to the end of the buffer. Resizes if doing so would\n     * exceed the capacity of the buffer.\n     * @param buf The buffer to append to.\n     * @param data The data to append.\n     * @return The original buffer.\n     */\n    function append(buffer memory buf, uint8 data) internal pure {\n        if(buf.buf.length + 1 \u003e buf.capacity) {\n            resize(buf, buf.capacity * 2);\n        }\n\n        assembly {\n        // Memory address of the buffer data\n            let bufptr := mload(buf)\n        // Length of existing buffer data\n            let buflen := mload(bufptr)\n        // Address = buffer address + buffer length + sizeof(buffer length)\n            let dest := add(add(bufptr, buflen), 32)\n            mstore8(dest, data)\n        // Update buffer length\n            mstore(bufptr, add(buflen, 1))\n        }\n    }\n\n    /**\n     * @dev Appends a byte to the end of the buffer. Resizes if doing so would\n     * exceed the capacity of the buffer.\n     * @param buf The buffer to append to.\n     * @param data The data to append.\n     * @return The original buffer.\n     */\n    function appendInt(buffer memory buf, uint data, uint len) internal pure returns(buffer memory) {\n        if(len + buf.buf.length \u003e buf.capacity) {\n            resize(buf, max(buf.capacity, len) * 2);\n        }\n\n        uint mask = 256 ** len - 1;\n        assembly {\n        // Memory address of the buffer data\n            let bufptr := mload(buf)\n        // Length of existing buffer data\n            let buflen := mload(bufptr)\n        // Address = buffer address + buffer length + sizeof(buffer length) + len\n            let dest := add(add(bufptr, buflen), len)\n            mstore(dest, or(and(mload(dest), not(mask)), data))\n        // Update buffer length\n            mstore(bufptr, add(buflen, len))\n        }\n        return buf;\n    }\n}\n\nlibrary CBOR {\n    using Buffer for Buffer.buffer;\n\n    uint8 private constant MAJOR_TYPE_INT = 0;\n    uint8 private constant MAJOR_TYPE_NEGATIVE_INT = 1;\n    uint8 private constant MAJOR_TYPE_BYTES = 2;\n    uint8 private constant MAJOR_TYPE_STRING = 3;\n    uint8 private constant MAJOR_TYPE_ARRAY = 4;\n    uint8 private constant MAJOR_TYPE_MAP = 5;\n    uint8 private constant MAJOR_TYPE_CONTENT_FREE = 7;\n\n    function encodeType(Buffer.buffer memory buf, uint8 major, uint value) private pure {\n        if(value \u003c= 23) {\n            buf.append(uint8((major \u003c\u003c 5) | value));\n        } else if(value \u003c= 0xFF) {\n            buf.append(uint8((major \u003c\u003c 5) | 24));\n            buf.appendInt(value, 1);\n        } else if(value \u003c= 0xFFFF) {\n            buf.append(uint8((major \u003c\u003c 5) | 25));\n            buf.appendInt(value, 2);\n        } else if(value \u003c= 0xFFFFFFFF) {\n            buf.append(uint8((major \u003c\u003c 5) | 26));\n            buf.appendInt(value, 4);\n        } else if(value \u003c= 0xFFFFFFFFFFFFFFFF) {\n            buf.append(uint8((major \u003c\u003c 5) | 27));\n            buf.appendInt(value, 8);\n        }\n    }\n\n    function encodeIndefiniteLengthType(Buffer.buffer memory buf, uint8 major) private pure {\n        buf.append(uint8((major \u003c\u003c 5) | 31));\n    }\n\n    function encodeUInt(Buffer.buffer memory buf, uint value) internal pure {\n        encodeType(buf, MAJOR_TYPE_INT, value);\n    }\n\n    function encodeInt(Buffer.buffer memory buf, int value) internal pure {\n        if(value \u003e= 0) {\n            encodeType(buf, MAJOR_TYPE_INT, uint(value));\n        } else {\n            encodeType(buf, MAJOR_TYPE_NEGATIVE_INT, uint(-1 - value));\n        }\n    }\n\n    function encodeBytes(Buffer.buffer memory buf, bytes value) internal pure {\n        encodeType(buf, MAJOR_TYPE_BYTES, value.length);\n        buf.append(value);\n    }\n\n    function encodeString(Buffer.buffer memory buf, string value) internal pure {\n        encodeType(buf, MAJOR_TYPE_STRING, bytes(value).length);\n        buf.append(bytes(value));\n    }\n\n    function startArray(Buffer.buffer memory buf) internal pure {\n        encodeIndefiniteLengthType(buf, MAJOR_TYPE_ARRAY);\n    }\n\n    function startMap(Buffer.buffer memory buf) internal pure {\n        encodeIndefiniteLengthType(buf, MAJOR_TYPE_MAP);\n    }\n\n    function endSequence(Buffer.buffer memory buf) internal pure {\n        encodeIndefiniteLengthType(buf, MAJOR_TYPE_CONTENT_FREE);\n    }\n}\n\n/*\nEnd solidity-cborutils\n */\n\ncontract usingProvable {\n    uint constant day = 60*60*24;\n    uint constant week = 60*60*24*7;\n    uint constant month = 60*60*24*30;\n    byte constant proofType_NONE = 0x00;\n    byte constant proofType_TLSNotary = 0x10;\n    byte constant proofType_Ledger = 0x30;\n    byte constant proofType_Android = 0x40;\n    byte constant proofType_Native = 0xF0;\n    byte constant proofStorage_IPFS = 0x01;\n    uint8 constant networkID_auto = 0;\n    uint8 constant networkID_mainnet = 1;\n    uint8 constant networkID_testnet = 2;\n    uint8 constant networkID_morden = 2;\n    uint8 constant networkID_consensys = 161;\n\n    OracleAddrResolverI OAR;\n\n    ProvableI provable;\n    modifier provableAPI {\n        if((address(OAR)==0)||(getCodeSize(address(OAR))==0))\n            provable_setNetwork(networkID_auto);\n\n        if(address(provable) != OAR.getAddress())\n            provable = ProvableI(OAR.getAddress());\n\n        _;\n    }\n    modifier coupon(string code){\n        provable = ProvableI(OAR.getAddress());\n        _;\n    }\n\n    function provable_setNetwork(uint8 networkID) internal returns(bool){\n        return provable_setNetwork();\n        networkID; // silence the warning and remain backwards compatible\n    }\n    function provable_setNetwork() internal returns(bool){\n        if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)\u003e0){ //mainnet\n            OAR = OracleAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed);\n            provable_setNetworkName(\"eth_mainnet\");\n            return true;\n        }\n        if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)\u003e0){ //ropsten testnet\n            OAR = OracleAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1);\n            provable_setNetworkName(\"eth_ropsten3\");\n            return true;\n        }\n        if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)\u003e0){ //kovan testnet\n            OAR = OracleAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e);\n            provable_setNetworkName(\"eth_kovan\");\n            return true;\n        }\n        if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)\u003e0){ //rinkeby testnet\n            OAR = OracleAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48);\n            provable_setNetworkName(\"eth_rinkeby\");\n            return true;\n        }\n        if (getCodeSize(0xa2998EFD205FB9D4B4963aFb70778D6354ad3A41)\u003e0){ //goerli testnet\n            OAR = OracleAddrResolverI(0xa2998EFD205FB9D4B4963aFb70778D6354ad3A41);\n            provable_setNetworkName(\"eth_goerli\");\n            return true;\n        }\n        if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)\u003e0){ //ethereum-bridge\n            OAR = OracleAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475);\n            return true;\n        }\n        if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)\u003e0){ //ether.camp ide\n            OAR = OracleAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF);\n            return true;\n        }\n        if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)\u003e0){ //browser-solidity\n            OAR = OracleAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA);\n            return true;\n        }\n        return false;\n    }\n    /**\n     * @dev The following `__callback` functions are just placeholders ideally\n     *      meant to be defined in child contract when proofs are used.\n     *      The function bodies simply silence compiler warnings.\n     */\n    function __callback(bytes32 myid, string result) public {\n        __callback(myid, result, new bytes(0));\n    }\n\n    function __callback(bytes32 myid, string result, bytes proof) public {\n        return;\n        myid; result; proof;\n        provable_randomDS_args[bytes32(0)] = bytes32(0);\n    }\n\n    function provable_getPrice(string datasource) provableAPI internal returns (uint){\n        return provable.getPrice(datasource);\n    }\n\n    function provable_getPrice(string datasource, uint gaslimit) provableAPI internal returns (uint){\n        return provable.getPrice(datasource, gaslimit);\n    }\n\n    function provable_query(string datasource, string arg) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource);\n        if (price \u003e 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price\n        return provable.query.value(price)(0, datasource, arg);\n    }\n    function provable_query(uint timestamp, string datasource, string arg) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource);\n        if (price \u003e 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price\n        return provable.query.value(price)(timestamp, datasource, arg);\n    }\n    function provable_query(uint timestamp, string datasource, string arg, uint gaslimit) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource, gaslimit);\n        if (price \u003e 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price\n        return provable.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit);\n    }\n    function provable_query(string datasource, string arg, uint gaslimit) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource, gaslimit);\n        if (price \u003e 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price\n        return provable.query_withGasLimit.value(price)(0, datasource, arg, gaslimit);\n    }\n    function provable_query(string datasource, string arg1, string arg2) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource);\n        if (price \u003e 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price\n        return provable.query2.value(price)(0, datasource, arg1, arg2);\n    }\n    function provable_query(uint timestamp, string datasource, string arg1, string arg2) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource);\n        if (price \u003e 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price\n        return provable.query2.value(price)(timestamp, datasource, arg1, arg2);\n    }\n    function provable_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource, gaslimit);\n        if (price \u003e 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price\n        return provable.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit);\n    }\n    function provable_query(string datasource, string arg1, string arg2, uint gaslimit) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource, gaslimit);\n        if (price \u003e 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price\n        return provable.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit);\n    }\n    function provable_query(string datasource, string[] argN) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource);\n        if (price \u003e 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price\n        bytes memory args = stra2cbor(argN);\n        return provable.queryN.value(price)(0, datasource, args);\n    }\n    function provable_query(uint timestamp, string datasource, string[] argN) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource);\n        if (price \u003e 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price\n        bytes memory args = stra2cbor(argN);\n        return provable.queryN.value(price)(timestamp, datasource, args);\n    }\n    function provable_query(uint timestamp, string datasource, string[] argN, uint gaslimit) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource, gaslimit);\n        if (price \u003e 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price\n        bytes memory args = stra2cbor(argN);\n        return provable.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit);\n    }\n    function provable_query(string datasource, string[] argN, uint gaslimit) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource, gaslimit);\n        if (price \u003e 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price\n        bytes memory args = stra2cbor(argN);\n        return provable.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit);\n    }\n    function provable_query(string datasource, string[1] args) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](1);\n        dynargs[0] = args[0];\n        return provable_query(datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, string[1] args) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](1);\n        dynargs[0] = args[0];\n        return provable_query(timestamp, datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, string[1] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](1);\n        dynargs[0] = args[0];\n        return provable_query(timestamp, datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, string[1] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](1);\n        dynargs[0] = args[0];\n        return provable_query(datasource, dynargs, gaslimit);\n    }\n\n    function provable_query(string datasource, string[2] args) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](2);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        return provable_query(datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, string[2] args) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](2);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        return provable_query(timestamp, datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, string[2] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](2);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        return provable_query(timestamp, datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, string[2] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](2);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        return provable_query(datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, string[3] args) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](3);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        return provable_query(datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, string[3] args) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](3);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        return provable_query(timestamp, datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, string[3] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](3);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        return provable_query(timestamp, datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, string[3] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](3);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        return provable_query(datasource, dynargs, gaslimit);\n    }\n\n    function provable_query(string datasource, string[4] args) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](4);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        return provable_query(datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, string[4] args) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](4);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        return provable_query(timestamp, datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, string[4] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](4);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        return provable_query(timestamp, datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, string[4] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](4);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        return provable_query(datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, string[5] args) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](5);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        dynargs[4] = args[4];\n        return provable_query(datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, string[5] args) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](5);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        dynargs[4] = args[4];\n        return provable_query(timestamp, datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, string[5] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](5);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        dynargs[4] = args[4];\n        return provable_query(timestamp, datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, string[5] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        string[] memory dynargs = new string[](5);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        dynargs[4] = args[4];\n        return provable_query(datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, bytes[] argN) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource);\n        if (price \u003e 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price\n        bytes memory args = ba2cbor(argN);\n        return provable.queryN.value(price)(0, datasource, args);\n    }\n    function provable_query(uint timestamp, string datasource, bytes[] argN) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource);\n        if (price \u003e 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price\n        bytes memory args = ba2cbor(argN);\n        return provable.queryN.value(price)(timestamp, datasource, args);\n    }\n    function provable_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource, gaslimit);\n        if (price \u003e 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price\n        bytes memory args = ba2cbor(argN);\n        return provable.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit);\n    }\n    function provable_query(string datasource, bytes[] argN, uint gaslimit) provableAPI internal returns (bytes32 id){\n        uint price = provable.getPrice(datasource, gaslimit);\n        if (price \u003e 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price\n        bytes memory args = ba2cbor(argN);\n        return provable.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit);\n    }\n    function provable_query(string datasource, bytes[1] args) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](1);\n        dynargs[0] = args[0];\n        return provable_query(datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, bytes[1] args) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](1);\n        dynargs[0] = args[0];\n        return provable_query(timestamp, datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](1);\n        dynargs[0] = args[0];\n        return provable_query(timestamp, datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, bytes[1] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](1);\n        dynargs[0] = args[0];\n        return provable_query(datasource, dynargs, gaslimit);\n    }\n\n    function provable_query(string datasource, bytes[2] args) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](2);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        return provable_query(datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, bytes[2] args) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](2);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        return provable_query(timestamp, datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](2);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        return provable_query(timestamp, datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, bytes[2] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](2);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        return provable_query(datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, bytes[3] args) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](3);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        return provable_query(datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, bytes[3] args) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](3);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        return provable_query(timestamp, datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](3);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        return provable_query(timestamp, datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, bytes[3] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](3);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        return provable_query(datasource, dynargs, gaslimit);\n    }\n\n    function provable_query(string datasource, bytes[4] args) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](4);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        return provable_query(datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, bytes[4] args) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](4);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        return provable_query(timestamp, datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](4);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        return provable_query(timestamp, datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, bytes[4] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](4);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        return provable_query(datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, bytes[5] args) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](5);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        dynargs[4] = args[4];\n        return provable_query(datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, bytes[5] args) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](5);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        dynargs[4] = args[4];\n        return provable_query(timestamp, datasource, dynargs);\n    }\n    function provable_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](5);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        dynargs[4] = args[4];\n        return provable_query(timestamp, datasource, dynargs, gaslimit);\n    }\n    function provable_query(string datasource, bytes[5] args, uint gaslimit) provableAPI internal returns (bytes32 id) {\n        bytes[] memory dynargs = new bytes[](5);\n        dynargs[0] = args[0];\n        dynargs[1] = args[1];\n        dynargs[2] = args[2];\n        dynargs[3] = args[3];\n        dynargs[4] = args[4];\n        return provable_query(datasource, dynargs, gaslimit);\n    }\n\n    function provable_cbAddress() provableAPI internal returns (address){\n        return provable.cbAddress();\n    }\n    function provable_setProof(byte proofP) provableAPI internal {\n        return provable.setProofType(proofP);\n    }\n    function provable_setCustomGasPrice(uint gasPrice) provableAPI internal {\n        return provable.setCustomGasPrice(gasPrice);\n    }\n\n    function provable_randomDS_getSessionPubKeyHash() provableAPI internal returns (bytes32){\n        return provable.randomDS_getSessionPubKeyHash();\n    }\n\n    function getCodeSize(address _addr) view internal returns(uint _size) {\n        assembly {\n            _size := extcodesize(_addr)\n        }\n    }\n\n    function parseAddr(string _a) internal pure returns (address){\n        bytes memory tmp = bytes(_a);\n        uint160 iaddr = 0;\n        uint160 b1;\n        uint160 b2;\n        for (uint i=2; i\u003c2+2*20; i+=2){\n            iaddr *= 256;\n            b1 = uint160(tmp[i]);\n            b2 = uint160(tmp[i+1]);\n            if ((b1 \u003e= 97)\u0026\u0026(b1 \u003c= 102)) b1 -= 87;\n            else if ((b1 \u003e= 65)\u0026\u0026(b1 \u003c= 70)) b1 -= 55;\n            else if ((b1 \u003e= 48)\u0026\u0026(b1 \u003c= 57)) b1 -= 48;\n            if ((b2 \u003e= 97)\u0026\u0026(b2 \u003c= 102)) b2 -= 87;\n            else if ((b2 \u003e= 65)\u0026\u0026(b2 \u003c= 70)) b2 -= 55;\n            else if ((b2 \u003e= 48)\u0026\u0026(b2 \u003c= 57)) b2 -= 48;\n            iaddr += (b1*16+b2);\n        }\n        return address(iaddr);\n    }\n\n    function strCompare(string _a, string _b) internal pure returns (int) {\n        bytes memory a = bytes(_a);\n        bytes memory b = bytes(_b);\n        uint minLength = a.length;\n        if (b.length \u003c minLength) minLength = b.length;\n        for (uint i = 0; i \u003c minLength; i ++)\n            if (a[i] \u003c b[i])\n                return -1;\n            else if (a[i] \u003e b[i])\n                return 1;\n        if (a.length \u003c b.length)\n            return -1;\n        else if (a.length \u003e b.length)\n            return 1;\n        else\n            return 0;\n    }\n\n    function indexOf(string _haystack, string _needle) internal pure returns (int) {\n        bytes memory h = bytes(_haystack);\n        bytes memory n = bytes(_needle);\n        if(h.length \u003c 1 || n.length \u003c 1 || (n.length \u003e h.length))\n            return -1;\n        else if(h.length \u003e (2**128 -1))\n            return -1;\n        else\n        {\n            uint subindex = 0;\n            for (uint i = 0; i \u003c h.length; i ++)\n            {\n                if (h[i] == n[0])\n                {\n                    subindex = 1;\n                    while(subindex \u003c n.length \u0026\u0026 (i + subindex) \u003c h.length \u0026\u0026 h[i + subindex] == n[subindex])\n                    {\n                        subindex++;\n                    }\n                    if(subindex == n.length)\n                        return int(i);\n                }\n            }\n            return -1;\n        }\n    }\n\n    function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) {\n        bytes memory _ba = bytes(_a);\n        bytes memory _bb = bytes(_b);\n        bytes memory _bc = bytes(_c);\n        bytes memory _bd = bytes(_d);\n        bytes memory _be = bytes(_e);\n        string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length);\n        bytes memory babcde = bytes(abcde);\n        uint k = 0;\n        for (uint i = 0; i \u003c _ba.length; i++) babcde[k++] = _ba[i];\n        for (i = 0; i \u003c _bb.length; i++) babcde[k++] = _bb[i];\n        for (i = 0; i \u003c _bc.length; i++) babcde[k++] = _bc[i];\n        for (i = 0; i \u003c _bd.length; i++) babcde[k++] = _bd[i];\n        for (i = 0; i \u003c _be.length; i++) babcde[k++] = _be[i];\n        return string(babcde);\n    }\n\n    function strConcat(string _a, string _b, string _c, string _d) internal pure returns (string) {\n        return strConcat(_a, _b, _c, _d, \"\");\n    }\n\n    function strConcat(string _a, string _b, string _c) internal pure returns (string) {\n        return strConcat(_a, _b, _c, \"\", \"\");\n    }\n\n    function strConcat(string _a, string _b) internal pure returns (string) {\n        return strConcat(_a, _b, \"\", \"\", \"\");\n    }\n\n    // parseInt\n    function parseInt(string _a) internal pure returns (uint) {\n        return parseInt(_a, 0);\n    }\n\n    // parseInt(parseFloat*10^_b)\n    function parseInt(string _a, uint _b) internal pure returns (uint) {\n        bytes memory bresult = bytes(_a);\n        uint mint = 0;\n        bool decimals = false;\n        for (uint i=0; i\u003cbresult.length; i++){\n            if ((bresult[i] \u003e= 48)\u0026\u0026(bresult[i] \u003c= 57)){\n                if (decimals){\n                    if (_b == 0) break;\n                    else _b--;\n                }\n                mint *= 10;\n                mint += uint(bresult[i]) - 48;\n            } else if (bresult[i] == 46) decimals = true;\n        }\n        if (_b \u003e 0) mint *= 10**_b;\n        return mint;\n    }\n\n    function uint2str(uint i) internal pure returns (string){\n        if (i == 0) return \"0\";\n        uint j = i;\n        uint len;\n        while (j != 0){\n            len++;\n            j /= 10;\n        }\n        bytes memory bstr = new bytes(len);\n        uint k = len - 1;\n        while (i != 0){\n            bstr[k--] = byte(48 + i % 10);\n            i /= 10;\n        }\n        return string(bstr);\n    }\n\n    using CBOR for Buffer.buffer;\n    function stra2cbor(string[] arr) internal pure returns (bytes) {\n        safeMemoryCleaner();\n        Buffer.buffer memory buf;\n        Buffer.init(buf, 1024);\n        buf.startArray();\n        for (uint i = 0; i \u003c arr.length; i++) {\n            buf.encodeString(arr[i]);\n        }\n        buf.endSequence();\n        return buf.buf;\n    }\n\n    function ba2cbor(bytes[] arr) internal pure returns (bytes) {\n        safeMemoryCleaner();\n        Buffer.buffer memory buf;\n        Buffer.init(buf, 1024);\n        buf.startArray();\n        for (uint i = 0; i \u003c arr.length; i++) {\n            buf.encodeBytes(arr[i]);\n        }\n        buf.endSequence();\n        return buf.buf;\n    }\n\n    string provable_network_name;\n    function provable_setNetworkName(string _network_name) internal {\n        provable_network_name = _network_name;\n    }\n\n    function provable_getNetworkName() internal view returns (string) {\n        return provable_network_name;\n    }\n\n    function provable_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){\n        require((_nbytes \u003e 0) \u0026\u0026 (_nbytes \u003c= 32));\n        // Convert from seconds to ledger timer ticks\n        _delay *= 10;\n        bytes memory nbytes = new bytes(1);\n        nbytes[0] = byte(_nbytes);\n        bytes memory unonce = new bytes(32);\n        bytes memory sessionKeyHash = new bytes(32);\n        bytes32 sessionKeyHash_bytes32 = provable_randomDS_getSessionPubKeyHash();\n        assembly {\n            mstore(unonce, 0x20)\n        // the following variables can be relaxed\n        // check relaxed random contract under ethereum-examples repo\n        // for an idea on how to override and replace comit hash vars\n            mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp)))\n            mstore(sessionKeyHash, 0x20)\n            mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32)\n        }\n        bytes memory delay = new bytes(32);\n        assembly {\n            mstore(add(delay, 0x20), _delay)\n        }\n\n        bytes memory delay_bytes8 = new bytes(8);\n        copyBytes(delay, 24, 8, delay_bytes8, 0);\n\n        bytes[4] memory args = [unonce, nbytes, sessionKeyHash, delay];\n        bytes32 queryId = provable_query(\"random\", args, _customGasLimit);\n\n        bytes memory delay_bytes8_left = new bytes(8);\n\n        assembly {\n            let x := mload(add(delay_bytes8, 0x20))\n            mstore8(add(delay_bytes8_left, 0x27), div(x, 0x100000000000000000000000000000000000000000000000000000000000000))\n            mstore8(add(delay_bytes8_left, 0x26), div(x, 0x1000000000000000000000000000000000000000000000000000000000000))\n            mstore8(add(delay_bytes8_left, 0x25), div(x, 0x10000000000000000000000000000000000000000000000000000000000))\n            mstore8(add(delay_bytes8_left, 0x24), div(x, 0x100000000000000000000000000000000000000000000000000000000))\n            mstore8(add(delay_bytes8_left, 0x23), div(x, 0x1000000000000000000000000000000000000000000000000000000))\n            mstore8(add(delay_bytes8_left, 0x22), div(x, 0x10000000000000000000000000000000000000000000000000000))\n            mstore8(add(delay_bytes8_left, 0x21), div(x, 0x100000000000000000000000000000000000000000000000000))\n            mstore8(add(delay_bytes8_left, 0x20), div(x, 0x1000000000000000000000000000000000000000000000000))\n\n        }\n\n        provable_randomDS_setCommitment(queryId, keccak256(abi.encodePacked(delay_bytes8_left, args[1], sha256(args[0]), args[2])));\n        return queryId;\n    }\n\n    function provable_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal {\n        provable_randomDS_args[queryId] = commitment;\n    }\n\n    mapping(bytes32=\u003ebytes32) provable_randomDS_args;\n    mapping(bytes32=\u003ebool) provable_randomDS_sessionKeysHashVerified;\n\n    function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){\n        bool sigok;\n        address signer;\n\n        bytes32 sigr;\n        bytes32 sigs;\n\n        bytes memory sigr_ = new bytes(32);\n        uint offset = 4+(uint(dersig[3]) - 0x20);\n        sigr_ = copyBytes(dersig, offset, 32, sigr_, 0);\n        bytes memory sigs_ = new bytes(32);\n        offset += 32 + 2;\n        sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0);\n\n        assembly {\n            sigr := mload(add(sigr_, 32))\n            sigs := mload(add(sigs_, 32))\n        }\n\n\n        (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs);\n        if (address(keccak256(pubkey)) == signer) return true;\n        else {\n            (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs);\n            return (address(keccak256(pubkey)) == signer);\n        }\n    }\n\n    function provable_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) {\n        bool sigok;\n\n        // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH)\n        bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2);\n        copyBytes(proof, sig2offset, sig2.length, sig2, 0);\n\n        bytes memory appkey1_pubkey = new bytes(64);\n        copyBytes(proof, 3+1, 64, appkey1_pubkey, 0);\n\n        bytes memory tosign2 = new bytes(1+65+32);\n        tosign2[0] = byte(1); //role\n        copyBytes(proof, sig2offset-65, 65, tosign2, 1);\n        bytes memory CODEHASH = hex\"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c\";\n        copyBytes(CODEHASH, 0, 32, tosign2, 1+65);\n        sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey);\n\n        if (sigok == false) return false;\n\n\n        // Step 7: verify the APPKEY1 provenance (must be signed by Ledger)\n        bytes memory LEDGERKEY = hex\"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4\";\n\n        bytes memory tosign3 = new bytes(1+65);\n        tosign3[0] = 0xFE;\n        copyBytes(proof, 3, 65, tosign3, 1);\n\n        bytes memory sig3 = new bytes(uint(proof[3+65+1])+2);\n        copyBytes(proof, 3+65, sig3.length, sig3, 0);\n\n        sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY);\n\n        return sigok;\n    }\n\n    modifier provable_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) {\n        // Step 1: the prefix has to match \u0027LP\\x01\u0027 (Ledger Proof version 1)\n        require((_proof[0] == \"L\") \u0026\u0026 (_proof[1] == \"P\") \u0026\u0026 (_proof[2] == 1));\n\n        bool proofVerified = provable_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), provable_getNetworkName());\n        require(proofVerified);\n\n        _;\n    }\n\n    function provable_randomDS_proofVerify__returnCode(bytes32 _queryId, string _result, bytes _proof) internal returns (uint8){\n        // Step 1: the prefix has to match \u0027LP\\x01\u0027 (Ledger Proof version 1)\n        if ((_proof[0] != \"L\")||(_proof[1] != \"P\")||(_proof[2] != 1)) return 1;\n\n        bool proofVerified = provable_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), provable_getNetworkName());\n        if (proofVerified == false) return 2;\n\n        return 0;\n    }\n\n    function matchBytes32Prefix(bytes32 content, bytes prefix, uint n_random_bytes) internal pure returns (bool){\n        bool match_ = true;\n\n        require(prefix.length == n_random_bytes);\n\n        for (uint256 i=0; i\u003c n_random_bytes; i++) {\n            if (content[i] != prefix[i]) match_ = false;\n        }\n\n        return match_;\n    }\n\n    function provable_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){\n\n        // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId)\n        uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32;\n        bytes memory keyhash = new bytes(32);\n        copyBytes(proof, ledgerProofLength, 32, keyhash, 0);\n        if (!(keccak256(keyhash) == keccak256(abi.encodePacked(sha256(abi.encodePacked(context_name, queryId)))))) return false;\n\n        bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2);\n        copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0);\n\n        // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if \u0027result\u0027 is the prefix of sha256(sig1)\n        if (!matchBytes32Prefix(sha256(sig1), result, uint(proof[ledgerProofLength+32+8]))) return false;\n\n        // Step 4: commitment match verification, keccak256(delay, nbytes, unonce, sessionKeyHash) == commitment in storage.\n        // This is to verify that the computed args match with the ones specified in the query.\n        bytes memory commitmentSlice1 = new bytes(8+1+32);\n        copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0);\n\n        bytes memory sessionPubkey = new bytes(64);\n        uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65;\n        copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0);\n\n        bytes32 sessionPubkeyHash = sha256(sessionPubkey);\n        if (provable_randomDS_args[queryId] == keccak256(abi.encodePacked(commitmentSlice1, sessionPubkeyHash))){ //unonce, nbytes and sessionKeyHash match\n            delete provable_randomDS_args[queryId];\n        } else return false;\n\n\n        // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey)\n        bytes memory tosign1 = new bytes(32+8+1+32);\n        copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0);\n        if (!verifySig(sha256(tosign1), sig1, sessionPubkey)) return false;\n\n        // verify if sessionPubkeyHash was verified already, if not.. let\u0027s do it!\n        if (provable_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){\n            provable_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = provable_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset);\n        }\n\n        return provable_randomDS_sessionKeysHashVerified[sessionPubkeyHash];\n    }\n\n    // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license\n    function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal pure returns (bytes) {\n        uint minLength = length + toOffset;\n\n        // Buffer too small\n        require(to.length \u003e= minLength); // Should be a better way?\n\n        // NOTE: the offset 32 is added to skip the `size` field of both bytes variables\n        uint i = 32 + fromOffset;\n        uint j = 32 + toOffset;\n\n        while (i \u003c (32 + fromOffset + length)) {\n            assembly {\n                let tmp := mload(add(from, i))\n                mstore(add(to, j), tmp)\n            }\n            i += 32;\n            j += 32;\n        }\n\n        return to;\n    }\n\n    // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license\n    // Duplicate Solidity\u0027s ecrecover, but catching the CALL return value\n    function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) {\n        // We do our own memory management here. Solidity uses memory offset\n        // 0x40 to store the current end of memory. We write past it (as\n        // writes are memory extensions), but don\u0027t update the offset so\n        // Solidity will reuse it. The memory used here is only needed for\n        // this context.\n\n        // FIXME: inline assembly can\u0027t access return values\n        bool ret;\n        address addr;\n\n        assembly {\n            let size := mload(0x40)\n            mstore(size, hash)\n            mstore(add(size, 32), v)\n            mstore(add(size, 64), r)\n            mstore(add(size, 96), s)\n\n        // NOTE: we can reuse the request memory because we deal with\n        //       the return code\n            ret := call(3000, 1, 0, size, 128, size, 32)\n            addr := mload(size)\n        }\n\n        return (ret, addr);\n    }\n\n    // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license\n    function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) {\n        bytes32 r;\n        bytes32 s;\n        uint8 v;\n\n        if (sig.length != 65)\n            return (false, 0);\n\n        // The signature format is a compact form of:\n        //   {bytes32 r}{bytes32 s}{uint8 v}\n        // Compact means, uint8 is not padded to 32 bytes.\n        assembly {\n            r := mload(add(sig, 32))\n            s := mload(add(sig, 64))\n\n        // Here we are loading the last 32 bytes. We exploit the fact that\n        // \u0027mload\u0027 will pad with zeroes if we overread.\n        // There is no \u0027mload8\u0027 to do this, but that would be nicer.\n            v := byte(0, mload(add(sig, 96)))\n\n        // Alternative solution:\n        // \u0027byte\u0027 is not working due to the Solidity parser, so lets\n        // use the second best option, \u0027and\u0027\n        // v := and(mload(add(sig, 65)), 255)\n        }\n\n        // albeit non-transactional signatures are not specified by the YP, one would expect it\n        // to match the YP range of [27, 28]\n        //\n        // geth uses [0, 1] and some clients have followed. This might change, see:\n        //  https://github.com/ethereum/go-ethereum/issues/2053\n        if (v \u003c 27)\n            v += 27;\n\n        if (v != 27 \u0026\u0026 v != 28)\n            return (false, 0);\n\n        return safer_ecrecover(hash, v, r, s);\n    }\n\n    function safeMemoryCleaner() internal pure {\n        assembly {\n            let fmem := mload(0x40)\n            codecopy(fmem, codesize, sub(msize, fmem))\n        }\n    }\n\n}\n// \u003c/provableAPI\u003e"},"SafeMath.sol":{"content":"pragma solidity \u003e= 0.4.22 \u003c 0.5;\n\n/**\n * @dev Wrappers over Solidity\u0027s arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it\u0027s recommended to use it always.\n */\nlibrary SafeMath {\n    /**\n     * @dev Returns the addition of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity\u0027s `+` operator.\n     *\n     * Requirements:\n     * - Addition cannot overflow.\n     */\n    function add(uint256 a, uint256 b) internal pure returns (uint256) {\n        uint256 c = a + b;\n        require(c \u003e= a, \"SafeMath: addition overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity\u0027s `-` operator.\n     *\n     * Requirements:\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n        require(b \u003c= a, \"SafeMath: subtraction overflow\");\n        uint256 c = a - b;\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity\u0027s `*` operator.\n     *\n     * Requirements:\n     * - Multiplication cannot overflow.\n     */\n    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n        // Gas optimization: this is cheaper than requiring \u0027a\u0027 not being zero, but the\n        // benefit is lost if \u0027b\u0027 is also tested.\n        // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522\n        if (a == 0) {\n            return 0;\n        }\n\n        uint256 c = a * b;\n        require(c / a == b, \"SafeMath: multiplication overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers. Reverts on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\n        // Solidity only automatically asserts when dividing by 0\n        require(b \u003e 0, \"SafeMath: division by zero\");\n        uint256 c = a / b;\n        // assert(a == b * c + a % b); // There is no case in which this doesn\u0027t hold\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * Reverts when dividing by zero.\n     *\n     * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n        require(b != 0, \"SafeMath: modulo by zero\");\n        return a % b;\n    }\n}\n"},"SnakesAndLadders.sol":{"content":"pragma solidity \u003e= 0.4.22 \u003c 0.5;\n\nimport \"./SafeMath.sol\";\nimport \"./provableAPI_0.4.25.sol\";\n\ncontract SnakesAndLadders is usingProvable {\n    using SafeMath for uint;  // uint256\n    using SafeMath for uint8;  // 0-255\n\n    // All balances\n    mapping(address =\u003e uint) public balances;\n    uint public totalBalance;\n\n    // Oracle\n    mapping(bytes32 =\u003e address) idPlayer;\n    mapping(bytes32 =\u003e uint) idAmount;\n\n    // Payout addresses\n    address private payout1;\n    address private payout2;\n\n    // Board composition\n    uint8 constant private tiles = 100;\n    mapping(uint8 =\u003e uint8) private boardElements;\n\n    // Player: is true if it\u0027s the user, otherwise is the AI\n    // Turn: starting from 1\n    // Move: the dice move from 1 to 6\n    event LogGame(address sender, bool result, int balancediff, uint seed);\n    event LogAddPlayerFunds(address sender, uint amount);\n    event LogWithdrawPlayerFunds(address sender, uint amount);\n    event LogAddFunds(address sender, uint amount);\n    event LogPayout(address sender, uint amount);\n\n    constructor(address _payout1, address _payout2) public {\n        // ladders\n        boardElements[4] = 14;\n        boardElements[8] = 32;\n        boardElements[20] = 38;\n        boardElements[28] = 84;\n        boardElements[40] = 59;\n        boardElements[58] = 83;\n        boardElements[72] = 93;\n        // snakes\n        boardElements[15] = 3;\n        boardElements[31] = 9;\n        boardElements[44] = 26;\n        boardElements[62] = 19;\n        boardElements[74] = 70;\n        boardElements[85] = 33;\n        boardElements[91] = 71;\n        boardElements[98] = 80;\n        // payouts\n        payout1 = _payout1;\n        payout2 = _payout2;\n    }\n\n    /**\n     * Avoid sending money directly to the contract\n     */\n    function () external payable {\n        revert(\"Use addPlayerFunds to send money.\");\n    }\n\n    /**\n     * Calls the game\n     */\n    function play(uint amount) public {\n        require(amount \u003e 0, \"You must send something to bet\");\n        require(amount \u003c= balances[msg.sender], \"You don\u0027t have enough balance to play\");\n        require(amount*5 \u003c address(this).balance - totalBalance, \"You cannot bet more than 1/5 of this contract free balance\");\n        require(amount \u003c= 1 ether, \"Maximum bet amount is 1 ether\");\n\n        bytes32 queryId = provable_query(\"WolframAlpha\", \"random number between 0 and 1000\", 500000);\n        idPlayer[queryId] = msg.sender;\n        idAmount[queryId] = amount;\n    }\n\n    /**\n     * Comeback from the oracle.\n     */\n    function __callback(bytes32 id, string result) public {\n        require(idPlayer[id] != address(0), \"Non-expected callback\");\n        require(msg.sender == provable_cbAddress(), \"Callback must be called from provable address\");\n        address playerAddress = idPlayer[id];\n        uint amount = idAmount[id];\n        uint seed = uint(keccak256(abi.encodePacked(block.timestamp, block.difficulty, result)));\n        delete idPlayer[id];\n        delete idAmount[id];\n        playGame(playerAddress, amount, seed);\n    }\n\n    /**\n     * Plays the game\n     */\n    function playGame(address playerAddress, uint amount, uint seed) private {\n        require(amount \u003e 0, \"You must send something to bet\");\n        require(amount \u003c= balances[playerAddress], \"You don\u0027t have enough balance to play\");\n        require(amount*5 \u003c address(this).balance - totalBalance, \"You cannot bet more than 1/5 of this contract free balance\");\n        require(amount \u003c= 1 ether, \"Maximum bet amount is 1 ether\");\n\n        uint turn = 0;\n        // let\u0027s decide who starts\n        bool player = false;  // true if next move is for player, false if for computer\n        uint8 move = randomDice(seed, turn);  // move 0 decides who starts\n        if (move == 1) {\n            player = true;\n        }\n        // make all the moves and emit the results\n        uint8 playerUser = 0;\n        uint8 playerAI = 0;\n        uint8 boardElement;\n        while (playerUser != tiles \u0026\u0026 playerAI != tiles) {\n            turn++;\n            move = randomDice(seed, turn);\n            if (player) {\n                playerUser = playerUser + move;\n                if (playerUser \u003e tiles) {\n                    playerUser = tiles - (playerUser - tiles);\n                }\n                boardElement = boardElements[playerUser];\n                if (boardElement != 0) {\n                    playerUser = boardElement;\n                }\n            } else {\n                playerAI = playerAI + move;\n                if (playerAI \u003e tiles) {\n                    playerAI = tiles - (playerAI - tiles);\n                }\n                boardElement = boardElements[playerAI];\n                if (boardElement != 0) {\n                    playerAI = boardElement;\n                }\n            }\n            // if the player rolls a 6 has an extra turn\n            if (move != 6) {\n                player = !player;\n            }\n        }\n        if (playerUser == tiles) {\n            balances[playerAddress] += amount;\n            totalBalance += amount;\n            emit LogGame(playerAddress, true, int(amount), seed);\n        } else {\n            balances[playerAddress] -= amount;\n            totalBalance -= amount;\n            emit LogGame(playerAddress, false, -int(amount), seed);\n        }\n\n        // in case that there are more than 2 ether in the pool generate payout\n        if (address(this).balance - totalBalance \u003e= 2 ether) {\n            emit LogPayout(playerAddress, 0.4 ether);\n            balances[payout1] += 0.2 ether;\n            balances[payout2] += 0.2 ether;\n            totalBalance += 0.4 ether;\n        }\n    }\n\n    /**\n     * Returns a random number from 1 to 6 based from a uint and turn.\n     */\n    function randomDice(uint randomString, uint turn) public pure returns(uint8) {\n        return uint8(randomString/2**(turn%256))%6 + 1;\n    }\n\n    /**\n     * User adds player funds.\n     */\n    function addPlayerFunds() public payable {\n        require(msg.value \u003e 0, \"You must send something to add into balance\");\n        emit LogAddPlayerFunds(msg.sender, msg.value);\n        balances[msg.sender] += msg.value;\n        totalBalance += msg.value;\n    }\n\n    /**\n     * Withdraw player funds.\n     */\n    function withdrawPlayerFunds() public {\n        uint toWithdraw = balances[msg.sender];\n        require(toWithdraw \u003e 0, \"There is no balance to withdraw\");\n        require(toWithdraw \u003c= totalBalance, \"There are not enough funds in the contract to withdraw\");\n        emit LogWithdrawPlayerFunds(msg.sender, toWithdraw);\n        balances[msg.sender] = 0;\n        totalBalance -= toWithdraw;\n        msg.sender.transfer(toWithdraw);\n    }\n\n    /**\n     * Anyone can send funds but it has to be from this function. This does not count in totalBalance.\n     */\n    function addFunds() public payable {\n        require(msg.value \u003e 0, \"You must send something when calling this function\");\n        emit LogAddFunds(msg.sender, msg.value);\n    }\n\n    /**\n     * Only payout addresses can emit payouts.\n     */\n    function payout(uint amount) public {\n        require(msg.sender == payout1 || msg.sender == payout2, \"You must be one a payout address\");\n        require(amount \u003e 0, \"The balance that you want to withdraw must be more than 0\");\n        require(amount%2 == 0, \"Amount to withdraw must be pair\");\n        // this is made in a way to protect the customer\n        require(address(this).balance - totalBalance \u003e= amount, \"There is not enough free balance to withdraw\");\n        emit LogPayout(msg.sender, amount);\n        uint half = amount/2;\n        balances[payout1] += half;\n        balances[payout2] += half;\n        totalBalance += amount;\n    }\n}\n"}}

    File 2 of 3: Oraclize
    /*
    Copyright (c) 2015-2016 Oraclize SRL
    Copyright (c) 2016-2017 Oraclize LTD
    */
    
    /*
    Oraclize Connector v1.2.0
    */
    
    // 'compressed' alternative, where all modifiers have been changed to FUNCTIONS
    // which is cheaper for deployment, potentially cheaper execution
    
    pragma solidity ^0.4.11;
    
    contract Oraclize {
        mapping (address => uint) reqc;
    
        mapping (address => byte) public cbAddresses;
    
        mapping (address => bool) public offchainPayment;
    
        event Log1(address sender, bytes32 cid, uint timestamp, string datasource, string arg, uint gaslimit, byte proofType, uint gasPrice);
        event Log2(address sender, bytes32 cid, uint timestamp, string datasource, string arg1, string arg2, uint gaslimit, byte proofType, uint gasPrice);
        event LogN(address sender, bytes32 cid, uint timestamp, string datasource, bytes args, uint gaslimit, byte proofType, uint gasPrice);
        event Log1_fnc(address sender, bytes32 cid, uint timestamp, string datasource, string arg, function() external callback, uint gaslimit, byte proofType, uint gasPrice);
        event Log2_fnc(address sender, bytes32 cid, uint timestamp, string datasource, string arg1, string arg2, function() external callback, uint gaslimit, byte proofType, uint gasPrice);
        event LogN_fnc(address sender, bytes32 cid, uint timestamp, string datasource, bytes args, function() external callback, uint gaslimit, byte proofType, uint gasPrice);
    
        event Emit_OffchainPaymentFlag(address indexed idx_sender, address sender, bool indexed idx_flag, bool flag);
    
        address owner;
        address paymentFlagger;
    
        function changeAdmin(address _newAdmin)
        external
        {
            onlyadmin();
            owner = _newAdmin;
        }
    
        function changePaymentFlagger(address _newFlagger)
        external
        {
            onlyadmin();
            paymentFlagger = _newFlagger;
        }
    
        function addCbAddress(address newCbAddress, byte addressType)
        external
        {
            onlyadmin();
            //bytes memory nil = '';
            addCbAddress(newCbAddress, addressType, hex'');
        }
    
        // proof is currently a placeholder for when associated proof for addressType is added
        function addCbAddress(address newCbAddress, byte addressType, bytes proof)
        public
        {
            onlyadmin();
            cbAddresses[newCbAddress] = addressType;
        }
    
        function removeCbAddress(address newCbAddress)
        external
        {
            onlyadmin();
            delete cbAddresses[newCbAddress];
        }
    
        function cbAddress()
        constant
        returns (address _cbAddress)
        {
            if (cbAddresses[tx.origin] != 0)
                _cbAddress = tx.origin;
        }
    
        function addDSource(string dsname, uint multiplier)
        external
        {
            addDSource(dsname, 0x00, multiplier);
        }
    
        function addDSource(string dsname, byte proofType, uint multiplier)
        public
        {
            onlyadmin();
            bytes32 dsname_hash = sha3(dsname, proofType);
            dsources[dsources.length++] = dsname_hash;
            price_multiplier[dsname_hash] = multiplier;
        }
    
        // Utilized by bridge
        function multiAddDSource(bytes32[] dsHash, uint256[] multiplier)
        external
        {
            onlyadmin();
            // dsHash -> sha3(DATASOURCE_NAME, PROOF_TYPE);
            for (uint i=0; i<dsHash.length; i++) {
                dsources[dsources.length++] = dsHash[i];
                price_multiplier[dsHash[i]] = multiplier[i];
            }
        }
    
        function multisetProofType(uint[] _proofType, address[] _addr)
        external
        {
            onlyadmin();
            for (uint i=0; i<_addr.length; i++) addr_proofType[_addr[i]] = byte(_proofType[i]);
        }
    
        function multisetCustomGasPrice(uint[] _gasPrice, address[] _addr)
        external
        {
            onlyadmin();
            for (uint i=0; i<_addr.length; i++) addr_gasPrice[_addr[i]] = _gasPrice[i];
        }
    
        uint gasprice = 20000000000;
    
        function setGasPrice(uint newgasprice)
        external
        {
            onlyadmin();
            gasprice = newgasprice;
        }
    
        function setBasePrice(uint new_baseprice)
        external
        { //0.001 usd in ether
            onlyadmin();
            baseprice = new_baseprice;
            for (uint i=0; i<dsources.length; i++) price[dsources[i]] = new_baseprice*price_multiplier[dsources[i]];
        }
    
        function setBasePrice(uint new_baseprice, bytes proofID)
        external
        { //0.001 usd in ether
            onlyadmin();
            baseprice = new_baseprice;
            for (uint i=0; i<dsources.length; i++) price[dsources[i]] = new_baseprice*price_multiplier[dsources[i]];
        }
    
        function setOffchainPayment(address _addr, bool _flag)
        external
        {
          if (msg.sender != paymentFlagger) throw;
          offchainPayment[_addr] = _flag;
          Emit_OffchainPaymentFlag(_addr, _addr, _flag, _flag);
        }
    
        function withdrawFunds(address _addr)
        external
        {
            onlyadmin();
            _addr.send(this.balance);
        }
    
        // unnecessary?
        //function() {}
    
        function Oraclize() {
            owner = msg.sender;
        }
    
        // Pesudo-modifiers
    
        function onlyadmin()
        private {
            if (msg.sender != owner) throw;
        }
    
        function costs(string datasource, uint gaslimit)
        private
        returns (uint price) {
            price = getPrice(datasource, gaslimit, msg.sender);
    
            if (msg.value >= price){
                uint diff = msg.value - price;
                if (diff > 0) {
                    // added for correct query cost to be returned
                    if(!msg.sender.send(diff)) {
                        throw;
                    }
                }
            } else throw;
        }
    
        mapping (address => byte) addr_proofType;
        mapping (address => uint) addr_gasPrice;
        uint public baseprice;
        mapping (bytes32 => uint) price;
        mapping (bytes32 => uint) price_multiplier;
        bytes32[] dsources;
    
        bytes32[] public randomDS_sessionPubKeysHash;
    
        function randomDS_updateSessionPubKeysHash(bytes32[] _newSessionPubKeysHash)
        external
        {
            onlyadmin();
            randomDS_sessionPubKeysHash.length = 0;
            for (uint i=0; i<_newSessionPubKeysHash.length; i++) randomDS_sessionPubKeysHash.push(_newSessionPubKeysHash[i]);
        }
    
        function randomDS_getSessionPubKeyHash()
        external
        constant
        returns (bytes32) {
            uint i = uint(sha3(reqc[msg.sender]))%randomDS_sessionPubKeysHash.length;
            return randomDS_sessionPubKeysHash[i];
        }
    
        function setProofType(byte _proofType)
        external
        {
            addr_proofType[msg.sender] = _proofType;
        }
    
        function setCustomGasPrice(uint _gasPrice)
        external
        {
            addr_gasPrice[msg.sender] = _gasPrice;
        }
    
        function getPrice(string _datasource)
        public
        returns (uint _dsprice)
        {
            return getPrice(_datasource, msg.sender);
        }
    
        function getPrice(string _datasource, uint _gaslimit)
        public
        returns (uint _dsprice)
        {
            return getPrice(_datasource, _gaslimit, msg.sender);
        }
    
        function getPrice(string _datasource, address _addr)
        private
        returns (uint _dsprice)
        {
            return getPrice(_datasource, 200000, _addr);
        }
    
        function getPrice(string _datasource, uint _gaslimit, address _addr)
        private
        returns (uint _dsprice)
        {
            uint gasprice_ = addr_gasPrice[_addr];
            if (
                    (offchainPayment[_addr])
                ||(
                    (_gaslimit <= 200000)&&
                    (reqc[_addr] == 0)&&
                    (gasprice_ <= gasprice)&&
                    (tx.origin != cbAddress())
                )
            ) return 0;
    
            if (gasprice_ == 0) gasprice_ = gasprice;
            _dsprice = price[sha3(_datasource, addr_proofType[_addr])];
            _dsprice += _gaslimit*gasprice_;
            return _dsprice;
        }
    
        function getCodeSize(address _addr)
        private
        constant
        returns(uint _size)
        {
            assembly {
                _size := extcodesize(_addr)
            }
        }
    
        function query(string _datasource, string _arg)
        payable
        external
        returns (bytes32 _id)
        {
            return query1(0, _datasource, _arg, 200000);
        }
    
        function query1(string _datasource, string _arg)
        payable
        external
        returns (bytes32 _id)
        {
            return query1(0, _datasource, _arg, 200000);
        }
    
        function query2(string _datasource, string _arg1, string _arg2)
        payable
        external
        returns (bytes32 _id)
        {
            return query2(0, _datasource, _arg1, _arg2, 200000);
        }
    
        function queryN(string _datasource, bytes _args)
        payable
        external
        returns (bytes32 _id)
        {
            return queryN(0, _datasource, _args, 200000);
        }
    
        function query(uint _timestamp, string _datasource, string _arg)
        payable
        external
        returns (bytes32 _id)
        {
            return query1(_timestamp, _datasource, _arg, 200000);
        }
    
        function query1(uint _timestamp, string _datasource, string _arg)
        payable
        external
        returns (bytes32 _id)
        {
            return query1(_timestamp, _datasource, _arg, 200000);
        }
    
        function query2(uint _timestamp, string _datasource, string _arg1, string _arg2)
        payable
        external
        returns (bytes32 _id)
        {
            return query2(_timestamp, _datasource, _arg1, _arg2, 200000);
        }
    
        function queryN(uint _timestamp, string _datasource, bytes _args)
        payable
        external
        returns (bytes32 _id)
        {
            return queryN(_timestamp, _datasource, _args, 200000);
        }
    
    /*  Needless?
        function query(uint _timestamp, string _datasource, string _arg, uint _gaslimit)
        payable
        external
        returns (bytes32 _id)
        {
            return query1(_timestamp, _datasource, _arg, _gaslimit);
        }
    */
        function query_withGasLimit(uint _timestamp, string _datasource, string _arg, uint _gaslimit)
        payable
        external
        returns (bytes32 _id)
        {
            return query1(_timestamp, _datasource, _arg, _gaslimit);
        }
    
        function query1_withGasLimit(uint _timestamp, string _datasource, string _arg, uint _gaslimit)
        payable
        external
        returns (bytes32 _id)
        {
            return query1(_timestamp, _datasource, _arg, _gaslimit);
        }
    
        function query2_withGasLimit(uint _timestamp, string _datasource, string _arg1, string _arg2, uint _gaslimit)
        payable
        external
        returns (bytes32 _id)
        {
            return query2(_timestamp, _datasource, _arg1, _arg2, _gaslimit);
        }
    
        function queryN_withGasLimit(uint _timestamp, string _datasource, bytes _args, uint _gaslimit)
        payable
        external
        returns (bytes32 _id)
        {
            return queryN(_timestamp, _datasource, _args, _gaslimit);
        }
    
        function query1(uint _timestamp, string _datasource, string _arg, uint _gaslimit)
        payable
        public
        returns (bytes32 _id)
        {
            costs(_datasource, _gaslimit);
        	if ((_timestamp > now+3600*24*60)||(_gaslimit > block.gaslimit)) throw;
    
            _id = sha3(this, msg.sender, reqc[msg.sender]);
            reqc[msg.sender]++;
            Log1(msg.sender, _id, _timestamp, _datasource, _arg, _gaslimit, addr_proofType[msg.sender], addr_gasPrice[msg.sender]);
            return _id;
        }
    
        function query2(uint _timestamp, string _datasource, string _arg1, string _arg2, uint _gaslimit)
        payable
        public
        returns (bytes32 _id)
        {
            costs(_datasource, _gaslimit);
        	if ((_timestamp > now+3600*24*60)||(_gaslimit > block.gaslimit)) throw;
    
            _id = sha3(this, msg.sender, reqc[msg.sender]);
            reqc[msg.sender]++;
            Log2(msg.sender, _id, _timestamp, _datasource, _arg1, _arg2, _gaslimit, addr_proofType[msg.sender], addr_gasPrice[msg.sender]);
            return _id;
        }
    
        function queryN(uint _timestamp, string _datasource, bytes _args, uint _gaslimit)
        payable
        public
        returns (bytes32 _id)
        {
            costs(_datasource, _gaslimit);
        	if ((_timestamp > now+3600*24*60)||(_gaslimit > block.gaslimit)) throw;
    
            _id = sha3(this, msg.sender, reqc[msg.sender]);
            reqc[msg.sender]++;
            LogN(msg.sender, _id, _timestamp, _datasource, _args, _gaslimit, addr_proofType[msg.sender], addr_gasPrice[msg.sender]);
            return _id;
        }
    
        function query1_fnc(uint _timestamp, string _datasource, string _arg, function() external _fnc, uint _gaslimit)
        payable
        public
        returns (bytes32 _id)
        {
            costs(_datasource, _gaslimit);
            if ((_timestamp > now+3600*24*60)||(_gaslimit > block.gaslimit)||address(_fnc) != msg.sender) throw;
    
            _id = sha3(this, msg.sender, reqc[msg.sender]);
            reqc[msg.sender]++;
            Log1_fnc(msg.sender, _id, _timestamp, _datasource, _arg, _fnc, _gaslimit, addr_proofType[msg.sender], addr_gasPrice[msg.sender]);
            return _id;
        }
    
        function query2_fnc(uint _timestamp, string _datasource, string _arg1, string _arg2, function() external _fnc, uint _gaslimit)
        payable
        public
        returns (bytes32 _id)
        {
            costs(_datasource, _gaslimit);
            if ((_timestamp > now+3600*24*60)||(_gaslimit > block.gaslimit)||address(_fnc) != msg.sender) throw;
    
            _id = sha3(this, msg.sender, reqc[msg.sender]);
            reqc[msg.sender]++;
            Log2_fnc(msg.sender, _id, _timestamp, _datasource, _arg1, _arg2, _fnc,  _gaslimit, addr_proofType[msg.sender], addr_gasPrice[msg.sender]);
            return _id;
        }
    
        function queryN_fnc(uint _timestamp, string _datasource, bytes _args, function() external _fnc, uint _gaslimit)
        payable
        public
        returns (bytes32 _id)
        {
            costs(_datasource, _gaslimit);
            if ((_timestamp > now+3600*24*60)||(_gaslimit > block.gaslimit)||address(_fnc) != msg.sender) throw;
    
            _id = sha3(this, msg.sender, reqc[msg.sender]);
            reqc[msg.sender]++;
            LogN_fnc(msg.sender, _id, _timestamp, _datasource, _args, _fnc, _gaslimit, addr_proofType[msg.sender], addr_gasPrice[msg.sender]);
            return _id;
        }
    }

    File 3 of 3: OraclizeAddrResolver
    /*
      Copyright (c) 2015-2016 Oraclize SRL
      Copyright (c) 2016 Oraclize LTD
    */
    
    contract OraclizeAddrResolver {
    
        address public addr;
    
        address owner;
    
        function OraclizeAddrResolver(){
            owner = msg.sender;
        }
    
        function changeOwner(address newowner){
            if (msg.sender != owner) throw;
            owner = newowner;
        }
    
        function getAddress() returns (address oaddr){
            return addr;
        }
    
        function setAddr(address newaddr){
            if (msg.sender != owner) throw;
            addr = newaddr;
        }
    
    }