-
Hiya @ricmoo, so I have the ABI of some contract, and the relevant FunctionFragment of the calldata, but the calldata does not contain the full arguments of the function (in the app I'm building, the calldata is filled incrementally as arguments are provided). Is there an easy way to parse the available contiguous calldata given that some of the trailing arguments are missing? For example, say I have I was hoping to use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In general the ABI format is not streamable, you can certainly build something to incrementally decode non-dynamic components, like uint and bool; the easiest thing to do would be to repeatedly call something like But any dynamic components (including the length of that component) are in the encoded data after 32 bytes times the number of parameter, so their values aren’t present at all if you only have the beginning. Each entry that is a dynamic type is a pointer to the location after all the data/pointers. So while parsing any dynamic type you could parse as a uint instead to prevent the throwing. It definitely possible to do limited fashion with lots of caveats, but the format was not really designed to be a streaming format at all. I think SSZ is supposed to be better, but I haven’t looked much into it yet. :) |
Beta Was this translation helpful? Give feedback.
In general the ABI format is not streamable, you can certainly build something to incrementally decode non-dynamic components, like uint and bool; the easiest thing to do would be to repeatedly call something like
AbiCoder.decode(inputs.slice(0, i), data)
inside a try..catch inside a for loop (sorry, not a computer, so it’s hard to type, let me know if you want that expanded into proper code).But any dynamic components (including the length of that component) are in the encoded data after 32 bytes times the number of parameter, so their values aren’t present at all if you only have the beginning. Each entry that is a dynamic type is a pointer to the location after all the data/pointers.
S…