blockchain - 我可以从一个 URL 中获取两个变量吗
问题描述
`pragma solidity ^0.4.22;
import "github.com/provable-things/ethereum-api/provableAPI_0.4.25.sol";
contract ExampleContract is usingProvable {
string public ETHUSD;
event LogConstructorInitiated(string nextStep);
event LogPriceUpdated(string price);
event LogNewProvableQuery(string description);
function ExampleContract() payable {
LogConstructorInitiated("Constructor was initiated. Call 'updatePrice()' to send the Provable Query.");
}
function __callback(bytes32 myid, string result) {
if (msg.sender != provable_cbAddress()) revert();
ETHUSD = result;
LogPriceUpdated(result);
}
function updatePrice() payable {
if (provable_getPrice("URL") > this.balance) {
LogNewProvableQuery("Provable query was NOT sent, please add some ETH to cover for the query fee");
} else {
LogNewProvableQuery("Provable query was sent, standing by for the answer..");
provable_query("URL", "json(https://api.pro.coinbase.com/products/ETH-USD/ticker).price");
}
}`
这是代码,我的问题是:
在代码的最后一行,我有一个 provable_query,它包含 URL,URL 数据是 [{"trade_id":103437884,"price":"2674.1","size":"0.12890079","time":"2021- 04-28T11:19:29.475452Z","bid":"2673.78","ask":"2674.03","volume":"360649.21208837"} 所以最后我想将价格获取到区块链中。
“但我的问题是,如果这个 Url 包含 2 个不同的价格,例如 1 个美元价格和其他欧元价格,例如:{“trade_id”:103437884,“price1”:“2674.1”,“price2”:“2222”,size” :"0.12890079","time":"2021-04-28T11:19:29.475452Z","bid":"2673.78","ask":"2674.03","volume":"360649.21208837"}
所以现在我的问题是如何从上述 URL 获取价格 1 和价格 2,如果是,我如何从单个 URL 获取 2 个价格”。
提前致谢
解决方案
推荐阅读
- javascript - 在 dom 中加载 div 后在 div 上附加一个按钮
- xml - xs:boolean "false" 带空格
- linux-kernel - BUG:无法处理示例内核模块的内核分页请求
- android - 后台应用 + startService()
- c++ - 用于获取多个容器引用的可变参数模板
- javascript - 在 NodeJS 上连续获取数据的最佳方式(或订阅)
- java - 如何从缓冲区阅读器的第一行读取
- javascript - 在依赖项 requirejs 获取未捕获错误之前加载应用程序:不匹配的匿名定义()
- java - 如何使用 yielder 库将呈现的 C# 代码(用于按长度分割字符串,相对于空间)适应 Java?
- sparql - SPARQL 文字有类型吗?