1

I have two functions which uses Oraclize call.I have to call these functions one after other / or simultaneously.

Sample code for your reference :-

pragma solidity ^0.4.0;

import "./usingOraclize.sol";

contract WeatherApiCall is usingOraclize {


      // oraclize callback types:
      enum oraclizeState { ForWeatherCondition, ForDistance }

      //Events
      event LOG_OraclizeCallbackForDistance(
                string result,
                bytes proof
      );

      event LOG_OraclizeCallbackForWeatherCondition(
                string result,
                bytes proof
      );

       // the oraclize callback structure: we use several oraclize calls.
       // all oraclize calls will result in a common callback to __callback(...).
       // to keep track of the different querys we have to introduce this struct.
      struct oraclizeCallback {
                // for which purpose did we call? {ForWeatherCondition | ForDistance}
                  oraclizeState oState;
      }
      // Lookup policy State from queryIds
      mapping (bytes32 => oraclizeCallback) public oraclizeCallbacks;

      address  public user;
      string public places1;
      string public from1;
      string public to1;
      uint public persons1;
      string public datetime1;          

      // constructor
      function WeatherApiCall() {
              OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475);
              oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS);
              user=msg.sender;
      }
      //Function for distance retrieval
      function distanceRetrieve(string places,string from,string to,uint persons,string datetime) payable returns(bool sufficient) {

            places1=places;
            from1=from;
            to1=to;
            persons1=persons;
            datetime1=datetime;


          //   weatherconditionRetrieve(to1,datetime1);
            bytes32 queryId = oraclize_query(10,"URL",strConcat("json(http://www.distance24.org/route.json?stops='", places1 ,"').distance"));
          //  weatherconditionRetrieve(to1,datetime1);
            oraclizeCallbacks[queryId] = oraclizeCallback(oraclizeState.ForDistance);
           // weatherconditionRetrieve(to1,datetime1);
            return true;
      }

      function weatherconditionRetrieve(string to,string datetime) payable returns(bool sufficient) {



               bytes32 queryId =  oraclize_query(30,"URL", strConcat("json(http://api.openweathermap.org/data/2.5/forecast?q='", to ,"'&mode=json&APPID=d2e8279188c8649c17540f798c9cc972).list[?(@.dt_txt='", datetime, "')].weather[0].description"));
               oraclizeCallbacks[queryId] = oraclizeCallback(oraclizeState.ForWeatherCondition);
               return true;
      }
      //Function callback
      function __callback(bytes32 myid, string result,bytes proof) {

                 if (msg.sender != oraclize_cbAddress()) throw;
                 oraclizeCallback memory o = oraclizeCallbacks[myid];
                 if (o.oState == oraclizeState.ForDistance) {
                               LOG_OraclizeCallbackForDistance(result,proof);
                             //  weatherconditionRetrieve(to1,datetime1);
               }
                 else if(o.oState == oraclizeState.ForWeatherCondition) {
                               LOG_OraclizeCallbackForWeatherCondition(result,proof);
                 }

      }


}

Requirement :-

I have to call distanceRetrieve() function and initialize values to variables...And also, I have to call weatherconditionRetrieve() along with the distanceRetrieve() function or after the distanceRetrieve() function.

How can I schedule weatherconditionRetrieve() within distanceRetrieve() function ??

I have tried in many ways...but it fails....Any help is appreciated?

Issue in Oraclize console while I called the weatherconditionRetrieve() function in callback..

 [2017-06-02T05:51:34.829Z] INFO sending __callback tx...
 {"contract_myid":"0x525545b08922b850ea8a708b38753a2555ab3c71e9b24559953a4b25f0ae6173","contract_address":"0x904e6ce8e6ceb3c88da5256a0265d723798ed0a3"}
 [2017-06-02T05:51:36.159Z] ERROR callback tx error, contract myid: 0x525545b08922b850ea8a708b38753a2555ab3c71e9b24559953a4b25f0ae6173
    {"message":"VM Exception while processing transaction: invalid JUMP  at  1a5420ab3442aabc0faea0c7124658f9bb10f45fbecdc1461be909a62f6503b9/904e6ce8e6ceb 3c88da5256a0265d723798ed0a3:9414","stack":"Error: VM Exception while    processing transaction: invalid JUMP at  1a5420ab3442aabc0faea0c7124658f9bb10f45fbecdc1461be909a62f6503b9/904e6ce8e6ceb 3c88da5256a0265d723798ed0a3:9414\n    at Object.InvalidResponse (/home /toshiba/ethereum-bridge-master/node_modules/web3/lib/web3/errors.js:35:16)\n    at /home/toshiba/ethereum-bridge-master /node_modules/web3/lib/web3/requestmanager.js:86:36\n    at  XMLHttpRequest.request.onreadystatechange (/home/toshiba/ethereum-bridge-master/node_modules/web3/lib/web3/httpprovider.js:118:13)\n    at XMLHttpRequestEventTarget.dispatchEvent (/home/toshiba/ethereum-bridge-master/node_modules/xhr2/lib/xhr2.js:64:18)\n    at XMLHttpRequest._setReadyState (/home/toshiba/ethereum-bridge-master/node_modules/xhr2/lib/xhr2.js:354:12)\n    at XMLHttpRequest._onHttpResponseEnd (/home/toshiba/ethereum-bridge-master/node_modules/xhr2/lib/xhr2.js:509:12)\n    at IncomingMessage.<anonymous> (/home/toshiba/ethereum-bridge-master/node_modules/xhr2/lib/xhr2.js:469:24)\n    at emitNone (events.js:91:20)\n    at IncomingMessage.emit (events.js:185:7)\n    at endReadableNT (_stream_readable.js:974:12)\n    at _combinedTickCallback (internal/process/next_tick.js:74:11)\n    at process._tickCallback (internal/process/next_tick.js:98:9)"}
 [2017-06-02T05:51:36.229Z] ERROR transaction hash not found, callback tx database not updated
  • What have you tried already, and (more importantly) what actual error messages did you get trying to do that? – MidnightLightning Jun 1 '17 at 11:45
  • @MidnightLightning (node:5950) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: VM Exception while processing transaction: invalid JUMP at 505464134dc923a80189acad5d1e28864d8b1cf2f51db9ff44cf51e1d3362ad1/0a1946378cf38b36cd7a74a159c6aa99a235a7fd:9702 – Crissi Mariam Robert Jun 2 '17 at 4:19
  • @MidnightLightning Here's the error...It shows invalid jump...How can I make one function with oraclize call inside another function with oraclize call??....I have tried different ways but all of it returns with invalid jump... – Crissi Mariam Robert Jun 2 '17 at 4:21
  • I have called the weatherconditionRetrieve() function inside distanceRetrieve() function in three places....1)before Oraclizecall in distanceReteieve() 2) after Oraclizecall in distanceReteieve() ....All these calls are mentioned in code as comments...Please do refer...And help me to rectify these issues.... @MidnightLightning – Crissi Mariam Robert Jun 2 '17 at 4:24
  • I have also tried to call within callback...It also returns with issue....I have added that issue too.. – Crissi Mariam Robert Jun 2 '17 at 5:52
0

It seems that you are not covering the Oraclize fee. Please add some funds to your contract and try again, remember that only the first query is free.

  • I added funds in my contract and it worked simultaneously.. – Crissi Mariam Robert Jun 5 '17 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.