Con respecto a la llamada de Oracle en contrato inteligente

Tengo dos funciones que usan la llamada de Oraclize. Tengo que llamar a estas funciones una tras otra o simultáneamente.

Código de muestra para su referencia: -

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);
                 }

      }


}

Requisito:-

Tengo que llamar a distanceRetrieve()la función e inicializar los valores de las variables... Y también tengo que llamar weatherconditionRetrieve()junto con la distanceRetrieve()función o después de la distanceRetrieve()función.

¿ Cómo puedo programar weatherconditionRetrieve()dentro de distanceRetrieve()la función?

Lo he intentado de muchas maneras... pero falla... ¿Se agradece alguna ayuda?

Problema en la consola de Oracle mientras llamé a la función weatherconditionRetrieve() en la devolución de llamada.

 [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
¿Qué ha intentado ya y (lo que es más importante) qué mensajes de error reales recibió al intentar hacer eso?
@MidnightLightning (node:5950) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: VM Exception while processing transaction: invalid JUMP at 505464134dc923a80189acad5d1e28864d8b1cf2f51db9ff44cf51e1d3362ad1/0a1946378cf38b36cd7a74a159c6aa99a235a7fd:9702
@MidnightLightning Aquí está el error... Muestra un salto no válido... ¿Cómo puedo hacer una función con una llamada de oraclize dentro de otra función con una llamada de oraclize?... He intentado diferentes formas, pero todo regresa con un salto no válido. ..
He llamado a la función weatherconditionRetrieve() dentro de la función distanceRetrieve() en tres lugares.... 1) antes de Oraclizecall en distanceReteieve() 2) después de Oraclizecall en distanceReteieve() .... Todas estas llamadas se mencionan en el código como comentarios. ..Por favor consulte... Y ayúdeme a corregir estos problemas.... @MidnightLightning
También intenté llamar dentro de la devolución de llamada... También vuelve con un problema... También he agregado ese problema...

Respuestas (1)

Parece que no estás cubriendo la tarifa de Oraclize. Añade fondos a tu contrato e inténtalo de nuevo, recuerda que solo la primera consulta es gratuita.

Agregué fondos en mi contrato y funcionó simultáneamente.