esaulpaugh / headlong

High-performance Contract ABI and RLP for Ethereum
Apache License 2.0
76 stars 20 forks source link

Problem with decoding returns when supplying array #38

Closed tomasz90 closed 2 years ago

tomasz90 commented 2 years ago

Hi, I would like to decode function return. I am testing this returning single element array of structs. Tried using: public Tuple decodeReturn(ByteBuffer buf) { return outputTypes.decode(buf); } but I am receiving error that unsigned val exceeds bit limit: 160 > 31. Going through stacktrace I am landing in UnitType<J> which as description says is not suitable for arrays... Is there a way that I can decode output of my function? Thanks!

esaulpaugh commented 2 years ago

There must be a mismatch between your function's specified return type and the data you're trying to decode. It looks like the function is expecting to find an offset (31 bits) where the data is specifying an address value (160 bits).

Try using the return type as the input type for another function and use that function to encode values. Then see if that encoding looks similar to what you're trying to decode.

tomasz90 commented 2 years ago

Thanks, for hints I just figured it out. First I had problem with preparing proper inputs/outputs as array of structs - so I tried to use Function.fromJson() then extract inputs/outputs. I don't know why but I get this ((address,string,string)) as array of structs. When I applied it as outputs this leaded me to above problem. As you mentioned in the second issue that I reported this should be ((address,string,string)[]). Now it works fine, thanks :)

esaulpaugh commented 2 years ago

Glad to hear it.