[abi-coders] Request for the decodeTypeApplication method

Hi, we need to decode a LogData receipt with struct components recursively. I can see there’s a decodeLog method, but I’d like to expose the decodeTypeApplication method. I’ve added a PR with it: feature: Add decodeTypeApplication by DZakh · Pull Request #2309 · FuelLabs/fuels-ts · GitHub. I’m looking forward to your feedback. The name of the function can be adjusted; I used the naming from the ABI docs.

Also, I found it weird that some decode functions return a tuple with an internal offset, so if it’s not intentional, I’ve created another PR with a fix fix: Don't return offset from public decode functions by DZakh · Pull Request #2308 · FuelLabs/fuels-ts · GitHub

1 Like

Thanks for the PR @DZakh_envio.dev, I will notify the ts-sdk team to have a look at it and provide the required feedback.

2 Likes

Hey @DZakh_envio.dev, thankyou for your contributions!

Please can you give a bit more information on the use case? Because if this is from a contract call, you can pick off the logs like so. Or if did want to call decodeLog directly, you just pass the logId as the second parameter. You can find this in the ABI, the logId will have an associated type (i.e. the struct you are logging) that will be used to decode the bytes accordingly.

Re your second points, usually logs are picked off calls like in the above documentation. So we pass the offsets around as the coding classes can use them to traverses bytecode. Are you instantiating coders directly? However some more info on your use-case, or maybe exemplary code/repo will help me in my understanding.

1 Like

I want to decode LogData’s data from receipt I received from HyperFuel client. The decodeLog works, but if the loggedType is a struct, it’ll keep fields data not decoded. So if there’s an ability to decode by type application we’ll be able to decode all nested fields of the log data.

1 Like

Also, we have a requirement to prefix field names with restricted names. So, building (codegen) our own decoder is the way to go for us anyway, and a low-level method to decode data by type application will definitely help with this.

1 Like

Would you mind recreating this somewhere as that sounds like a bug.

And does the ABICoder.decode() not work for your use case? It takes the ABI, the ABI argument and bytes. My concern with adding it to the Interface is that you could pass any bytes and argument unrelated to the Interface that it is meant to represent. Sounds like you want more generally a manually decoding utility, of which I think the AbiCoder should suffice?

1 Like

Thanks, the ABICoder.decode is what I wanted. But I’ve looked at the StructCoder code, and as you said, it should also decode all the fields. I’ll investigate why it doesn’t

1 Like

Keep me updated on that one, I’d be happy to take a look if you can reproduce it in a minimal repo.

1 Like

It was my bad. decodeLog works correctly. I mistook the b256 hashes as unconverted data.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.