0

我的目标是将一些字符串传递给数据源,然后在那里处理并取回结果。下面给出的代码可以可靠地工作

oraclize_query("URL", "json(https://clever-ape-38.localtunnel.me).a","sfdg");

但是当我尝试从区块链中获取一些价值并使用它时,如果失败

string memory st = arr[msg.sender];
oraclize_query("URL", "json(https://clever-ape-38.localtunnel.me).a",st); 

一切都正确编译。甚至 truffle migrate --reset 也可以正常工作。我觉得从区块链获取需要一些时间,并且在获取之前调用了 oraclize_query()。

下面提到了错误。

    [2019-05-28T08:54:50.206Z] INFO new HTTP query created, id: 72e3a263387ed365d97bc97a64c601380a5b4e8bbd1b3740bcc2af1e2bc97b19
[2019-05-28T08:54:50.215Z] INFO checking HTTP query 72e3a263387ed365d97bc97a64c601380a5b4e8bbd1b3740bcc2af1e2bc97b19 status in 0 seconds
[2019-05-28T08:54:50.215Z] INFO checking HTTP query 72e3a263387ed365d97bc97a64c601380a5b4e8bbd1b3740bcc2af1e2bc97b19 status every 5 seconds...
[2019-05-28T08:54:56.634Z] INFO 72e3a263387ed365d97bc97a64c601380a5b4e8bbd1b3740bcc2af1e2bc97b19 HTTP query result: 
    {
    "result": {
        "_timestamp": 1559033691,
        "id": "72e3a263387ed365d97bc97a64c601380a5b4e8bbd1b3740bcc2af1e2bc97b19",
        "daterange": [
            1559033689,
            1559035489
        ],
        "_lock": false,
        "id2": "72fdf59adf3ecc92244e3b173ce1657252ab5eb877c3569a393599d34dd2c848",
        "actions": [],
        "interval": 3600,
        "checks": [
            {
                "errors": [
                    "TypeError",
                    "parsing_helper.wrong_path"
                ],
                "success": true,
                "timestamp": 1559033691,
                "results": [
                    ""
                ],
                "proofs": [
                    null
                ],
                "match": true
            }
        ],
        "version": 3,
        "_timestamp_creation": 1559033689,
        "context": {
            "protocol": "eth",
            "relative_timestamp": 1559033687,
            "type": "blockchain",
            "name": "eth_AB65E563DB"
        },
        "active": false,
        "hidden": false,
        "payload": {
            "conditions": [
                {
                    "query": [
                        "json(https://purple-squid-54.localtunnel.me).a",
                        "28189689"
                    ],
                    "proof_type": 0,
                    "check_op": "tautology",
                    "datasource": "URL",
                    "value": null
                }
            ]
        }
    },
    "success": true
}
[2019-05-28T08:54:56.637Z] ERROR HTTP query error
    [
    "TypeError",
    "parsing_helper.wrong_path"
]
[2019-05-28T08:54:56.639Z] INFO sending __callback tx...
    {
    "contract_myid": "0x72fdf59adf3ecc92244e3b173ce1657252ab5eb877c3569a393599d34dd2c848",
    "contract_address": "0x481a276d14a6a74e1ec1f74b64c2af226ba7033c"
}
[2019-05-28T08:55:01.853Z] INFO contract 0x481a276d14a6a74e1ec1f74b64c2af226ba7033c __callback tx sent, transaction hash: 0xfada229b6f9860e0717b3a098dd93aaef280852dbf75109c830b555c488e6c81
    {
    "myid": "0x72fdf59adf3ecc92244e3b173ce1657252ab5eb877c3569a393599d34dd2c848",
    "result": "",
    "proof": null,
    "proof_type": "0x00",
    "contract_address": "0x481a276d14a6a74e1ec1f74b64c2af226ba7033c",
    "gas_limit": 200000,
    "gas_price": null
}

请帮助解决这个问题。

4

1 回答 1

1

感谢您添加错误日志。

实际答案:

如果您将 POST 数据添加为一个字符串,但它是有效的 JSON 格式,它将被解析为这样。为了将其保存为字符串,您需要添加换行符或空格,以便字符串的开头:

"\n<post-data-here"

原始答案重新parsing-error证明最终不是主要问题...

ethereum-bridge由于它尝试但未能解析json从查询返回的结果,因此您遇到了解析错误。

但是,在撰写本文时,您的本地隧道正在返回一个404错误,而不是它最初返回的数据。

然后,作为 ethereum-bridge attempts to parse thejson a`to pluck the value from the键,根据您的查询:

json(https://purple-squid-54.localtunnel.me).a

...它不能,因为没有json,所以没有a字段,所以你得到一个解析错误。

要修复它,请确保您的本地隧道正在工作并且返回的数据json格式正确,并且a存在可供解析器使用的密钥。

于 2019-05-28T13:09:02.160 回答