Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Oracle response failure with code " - need to set Content-Type header to application/json #52

Open
robliou opened this issue Oct 15, 2023 · 1 comment

Comments

@robliou
Copy link

robliou commented Oct 15, 2023

Hi!

I'm trying to call the NEO Oracle using the sample smart contract below:

using Neo.SmartContract.Framework.Services;
using Neo.SmartContract.Framework.Attributes;
using Neo.SmartContract.Framework.Native;
using System;

namespace Neo.SmartContract.Examples
{
    [ManifestExtra("Author", "Neo")]
    [ManifestExtra("Email", "[email protected]")]
    [ManifestExtra("Description", "This is an oracle example")]
    public class OracleDemo : Framework.SmartContract
    {
        public static void doRequest()
        {
            string url = "https://raw.githubusercontent.com/neo-project/examples/master/csharp/Oracle/example.json"; // the content is  { "value": "hello world" }
            string filter = "$.value";  // JSONPath format https://github.com/atifaziz/JSONPath
            string callback = "callback"; // callback method
            object userdata = "userdata"; // arbitrary type
            long gasForResponse = Oracle.MinimumResponseFee;`

            Oracle.Request(url, filter, callback, userdata, gasForResponse);
        }

        public static void callback(string url, string userdata, OracleResponseCode code, string result)
        {
            if (Runtime.CallingScriptHash != Oracle.Hash) throw new Exception("Unauthorized!");
            if (code != OracleResponseCode.Success) throw new Exception("Oracle response failure with code " + (byte)code);

            object ret = StdLib.JsonDeserialize(result); // [ "hello world" ]
            object[] arr = (object[])ret;
            string value = (string)arr[0];

            Runtime.Log("userdata: " + userdata);
            Runtime.Log("response value: " + value);
        }
    }
}

However, I'm getting a message that the Oracle is failing: "Oracle response failure with code "

Per asking people on Discord, the key issue is that the Oracle website isn't setting Content-Type header to application/json. Instead its setting it to text/plain; charset=utf-8. Per the blockchain explorer, transaction had an exception VMState == FAULT error is ContentTypeNotSupported.

However, I cannot make this change from my end, it needs to be done from the website.

Can someone here please confirm that this is the root cause of the error, and if so, provide a work-around or fix the problem directly on the Oracle website? For reference, my smart contract is deployed on TestNet here, if you'd like to test it directly:

https://dora-dev.coz.io/transaction/neo3/testnet/0xc94e32026d03e2b5408bd28cd7b9e9022a3b08fe9337d94a366563870c02dd5a

Thanks,

@shargon
Copy link
Member

shargon commented Oct 16, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants