Base64 response decode error

Hello everyone,
I am trying the example of hello world here https://github.com/aeternity/tutorials/blob/master/sophia-oracle-introduction.md
I am having a problem getting response decoded.

I have tried several online tools, The request gets decoded by some


But response doesn’t

old oracle with hello as first request(Not capital H as per condition) but second request according to the condition being true

for the second oracle, I get this in the console of fireditor.


Which sets the right values (Check the API URL), I get the right values too https://sdk-testnet.aepps.com/v2/oracles/ok_2AgGaBVWb4XMd16bREAvQNsMQDeBwAy1oY4aNwSXFoyvkqCaUZ/queries

The problem with the second I get inconsistent result on the fireeditor (Which it looks like requesting to the old oracle)

2 Likes

maybe @nikitafuchs.chain can help :slight_smile:

2 Likes

Thanks @keno.chain - Let us first check whether this is a response “code” that @hanssv.chain might know something about?

1 Like

First, for whoever thinks that reporting a decoding problem using a picture, I have a nagging feeling that the decoding isn’t perhaps the biggest issue :slight_smile:

In general the contract byte arrays (the things prefixed by cb_) are Base64 check encoded, i.e. if you don’t care about the built in checksum you drop the last four byte and decode as Base64. And of course all of this is documented: here

3 Likes
([email protected])26> aeser_api_encoder:decode(<<"cb_Xfbg4g==">>). 
{contract_bytearray,<<>>}            

You are right, Decoding is not the biggest issue, It’s the response that it gets, which is the same every time, Please check the last line where I have this assumption and that pretty much makes sense because decoding comes after the value we get.
Pictures was just to give face to this problem.

The problem is that you say nothing about what your problem is. The picture(s) only tells me that you tried to call a function in a contract with some parameters and that the contract call failed.

I don’t know what the contract is, there is no way to tell what the parameters are or even which function you tried to call - thus it is very hard to help.

1 Like

Quick question.
You only saw pictures and didn’t saw the text ?
Please read all the information above, If there is legitimately missing something, I need the help so i am here to give more info.

I see the text perfectly, but do you expect me to type in cb_KxHzJ... by hand to help you with the decoding?

No, Please see api calls

that’s the issue there… the cb_Xsdh… is not the right response according to API response.
and I am sorry. Let me provide that, you are right there.

Interesting… Now API too have wrong value. (The value in the image)

or_Xfbg4g==

Does oracle published data have some sort of auto-destruction thing ? Because now i am getting nothing.

Not sure whether it is the right or the wrong value. That is just the empty value?

Yes, there is a TTL for oracles.

([email protected])37> aeser_api_encoder:decode(<<"ov_FUhlbGxvh01nig==">>).       
{oracle_query,<<21,72,101,108,108,111>>}

I.e. that is not “Hello” but “^UHello” with some interesting control character first, is that on purpose?

2 Likes

Yeah, Nice spotted.
I saw some decoding standard having different values. It should be Hello but that’s at least some progress. with Original Post you will see the third image that online tool, It sure have right response but you see weird characters on left and right side.

The editor does it different way so you can see in original post Image the response of decoding the value is different than what you and me get from different sources.

Well, as I mentioned Xfbg4g== is just the empty value.

Pictures 1 and 4 just shows failed contract calls, there is no way from the pictures to tell whether the problem has anything to do with oracles or not.

1 Like

Here are some quick factors I am keeping in mind for this.

  1. As I said previously Xfbg4g== is empty only for the tool you use.
  2. The Pictures. It shows that problem is not with decoding. It is with the response I get either from the chain (which now shows it is on chain (As per the API response they get)) or in Editor (Even after getting the right response from the new contract I still get same in error logs (probably need to recheck)
  3. The contract code you was asking for, The first link in the Original post refers to this, It just copy-pastes with the fee being 0

I first sure was having doubt with decoding because it return different values (Even for you as you now have tried yourself with ^UHello Which was not my request because of the contract code condition (referred above))

So I kept it open with giving information to focus on two problems(While posting, I noticed it could be more leaned towards the response I get not the decoding). But decoding can only be confirmed once I start getting right response (encoded) on editor.

Could that be a problem with my Ascii codes are different for passing query string and it is getting wrong encoded value at first place?


nice @hanssv.chain, thanks for that info (after your 19th post about TTL)

I am out of replies today. It says i can’t reply for next 20 hours due to being new.
So editing this…

But respond_to_greets just run with a recently added state.

In greet_oracle function

let query : oracle_query(string, string) =
        Oracle.query(state.greeter_oracle, message, 0, RelativeTTL(50), RelativeTTL(50))

and respond_to_greets just read it. One thing I am confused about is how it can able to access variables that are defined in a function scope. In this case how respond_to_greets Know the query and caller_addr when it is declared (initialized) inside greet_oracle. That’s related to common programming rules called scopes. But that’s a different question (Which if you like can answer). Currently. I have tried with one time only theory but it’s not how code says and it did not works.

Oh ok i saw this. nvm with that quesiton :slight_smile: (caller_addr, query) <- state.greets


One thing I would like to add is whenever I call respond_to_greets for the first-ever time after running the greet oracle function. I get false instead of an error value. No Idea why.


That’s the solution. I noticed now that Oracles responds (With custom TTL) to the required request to set the response in the right manner.
The value false I get is based on nothing and calling again that response triggers that error.
Sorry, I thought Oracle.respond only reads the data.

Thank you

In my first response I explained (and linked to the documentation) how the different things are encoded and decoded. There is no interpretation involved in what Xfbg4g== means - i.e. my tool is correct here since the “tool” is in fact the same code that the Aeternity node uses…

But I think that the query is correct, since it is inside a FATE contract it will be encoded for FATE:

([email protected])39> aeb_fate_encoding:deserialize(<<21,72,101,108,108,111>>).
<<"Hello">>

And the last picture in the original post also indicates that it works (except you use a base64 decoder to decode base64 check data) since you get the correct greeting (note it is still FATE encoded so the first character will be weird).

That the contract call fails, could it be because the oracle query is already responded to and you try to call respond_to_greets again?

2 Likes

As for TTL the example has 200 generations for the oracle itself, and 50 generations for the query and the response.

3 Likes