Go-Ethereum
關於智能合約中的 Oraclize 呼叫
我有兩個使用 Oraclize 呼叫的函式。我必須一個接一個地/或同時呼叫這些函式。
供您參考的範常式式碼:-
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); } } }
要求 :-
我必須呼叫
distanceRetrieve()
函式並將值初始化為變數……而且,我必須weatherconditionRetrieve()
與distanceRetrieve()
函式一起呼叫或在distanceRetrieve()
函式之後呼叫。如何
weatherconditionRetrieve()
在distanceRetrieve()
功能內安排?我已經嘗試了很多方法……但它失敗了……任何幫助表示讚賞?
當我在回調中呼叫 weatherconditionRetrieve() 函式時,Oraclize 控制台中出現問題。
[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
您似乎沒有支付 Oraclize 費用。請為您的合約添加一些資金並重試,請記住只有第一次查詢是免費的。