0

My aim is to pass some string to the data source and then process there and get back the result. Below given code works in solidity

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

But when i try to fetch some value from blockchain and use it, if fails

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

everything compiles properly. Even truffle migrate --reset works fine. I feel that the fetching from blockchain takes some time and oraclize_query() is called before the fetch.

Below there is mentioned the error.

    [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
}

Please help to solve this.

lokesh kumar
  • 961
  • 1
  • 10
  • 18
  • Your Oraclize query works as expected (I'm assuming here that third parameter you're passing in is a `uint` and is the gas limit for the call). Since Oraclize will be returning the correct data from your API call, what is the "fetch" that is failing? – gskapka May 28 '19 at 09:22
  • @gskapka i have added the log. I am trying to pass a string. – lokesh kumar May 28 '19 at 12:46
  • @gskapka My aim is to pass some string to the data source and then process there and get back the result. – lokesh kumar May 28 '19 at 13:08
  • Have updated the main answer. – gskapka May 28 '19 at 14:49

1 Answers1

1

Thank you for adding the error logs.

Actual answer:

If you're adding POST data as a string but that's in a valid JSON format, it will be parsed as such. In order to preserve it as a string, you need to add a newline char or whitespace so the beginning of the string:

"\n<post-data-here"

Original answer re the parsing-error which proved not to be the main issue in the end...

You're hitting a parsing error in the ethereum-bridge due to it trying but failing to parse the returned json from your query.

However at the time of writing, your local tunnel is returning a 404 error rather than the data it originally returned.

Then, as the ethereum-bridgeattempts to parse thejsonto pluck the value from thea` key, per your query:

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

...it can't because there is not json and so no a field and so you get a parsing error.

To fix it, ensure your local tunnel is working and that the data returned is in correct json format, and that there is an a key present for the parser to work with.

gskapka
  • 178
  • 1
  • 8
  • No that's not the issues. Json format returned is fine. That was link to the localtunnel which was not returning as I had turned off my laptop. – lokesh kumar May 28 '19 at 13:13
  • However My aim is to pass some string to the data source and then process there and get back the result. Please help with that – lokesh kumar May 28 '19 at 13:14
  • You can post data just fine, to then format that data and return from it whatever it is you need would be a job for your API. The oraclize URL datasource simply queries the URL you give and it and returns to you whatever that URL returns. – gskapka May 28 '19 at 14:14
  • that's what i am trying to do, by putting 'st' in the oraclize_query() ,but it fails to post the data, where as when I put some string, It is received on the server side. – lokesh kumar May 28 '19 at 14:18
  • Using the test-query page you can see a working post request using the URL datasource here: http://app.oraclize.it/home/test_query#VVJMKFBPU1Qp:anNvbihodHRwczovL2FwaS5wb3N0Y29kZXMuaW8vcG9zdGNvZGVzKS5zdGF0dXM=:eyJwb3N0Y29kZXMiIDogWyJPWDQ5IDVOVSIsICJNMzIgMEpHIiwgIk5FMzAgMURQIl19 Does your post request work and return the correctly formatted data if you try it with something like curl? – gskapka May 28 '19 at 14:33
  • yes , it works fine. My server is fine, it's just i have to keep changing the URL. – lokesh kumar May 28 '19 at 14:34
  • I tried changing the gas limit , but it failed stating that the contract has hit a require statement in its constructor. – lokesh kumar May 28 '19 at 14:37
  • i used this query to update gas limit ------- oraclize_query("URL", "json(https://happy-goose-69.localtunnel.me/).a", 900000); – lokesh kumar May 28 '19 at 14:37
  • That will fail unless you fund your contract because the first query is only free if you use the default gas limit and gas prices. – gskapka May 28 '19 at 14:38