我已经开始扎实地学习编码,并使用官方的Oraclize指南编写了下面的合同。
我应该如何配置我的代码以实现这个结果?
pragma solidity ^0.4.18;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
contract WolframAlpha is usingOraclize {
string public temperature;
mapping(bytes32=>bool) validIds;
event LogNewOraclizeQuery(string description);
event newTemperatureMeasure(string temperature);
function WolframAlpha() {
update();
}
function __callback(bytes32 myid, string result) {
require(validIds[myid] ==true);
require(msg.sender == oraclize_cbAddress());
temperature = result;
newTemperatureMeasure(temperature);
delete validIds[myid];
// do something with the temperature measure..
}
function update() payable {
if(oraclize_getPrice("WolframAlpha") > this.balance){
LogNewOraclizeQuery("Oraclize query was NOT sent, please add some ETH to cover for the query fee");
}
else{
LogNewOraclizeQuery("Oraclize query was sent, standing by for the answer..");
bytes32 queryId = oraclize_query(60,"WolframAlpha","Temperature in London");
validIds[queryId] =true;
}
}
} 仅供参考
发布于 2018-03-09 05:33:37
您可以按以下方式安排查询的执行。
来自Oraclize的文档:-
查询的执行可以在以后的日期安排。函数oraclize_query以秒为单位接受当前时间的延迟或将来的时间戳作为第一个参数。
// Relative time: get the result from the given URL 60 seconds from now
oraclize_query(60, "URL","json(https://api.kraken.com/0/public/Ticker?pair=ETHXBT).result.XETHXXBT.c.0")
// Absolute time: get the result from the given datasource at the specified UTC timestamp in the future
oraclize_query(scheduled_arrivaltime+3*3600,"WolframAlpha", strConcat("flight ", flight_number, " landed"));从您的问题中,您必须为特定的timeperiods.For调用update函数--您必须使用JS来调度调用。在每次调用时,它都会发出LogNewOraclizeQuery.You可以对事件进行监视的事件,以通知最新的更新。
var num=contractInstance.Result({},{fromBlock: 0, toBlock: 'latest' });
num.watch(function(error,result){
});https://ethereum.stackexchange.com/questions/42174
复制相似问题