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.
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.
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.
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.
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?
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