-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add array support for tuples #90
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. Thanks for doing all this work! I'll have to take a closer look at the multi-dimensional array issue and see if I can figure out what's going on. I'll do that before I merge this in.
👍 much cleaner than my attempt 😁 still some things missing with arrays (both normal and multidimensional) though. it works fine when the object is a tuple, but not when it is a base type. https://solidity.readthedocs.io/en/develop/abi-spec.html#use-of-dynamic-types has some examples
but it seems the |
@tristan I think the confusion is that, in the example you cite, all of the arguments to the function are encoded as a single tuple type. If you want to see a head-tail encoding, you need to do something like this:
The important line above is line 3. The other ones after that are just to format the result nicely to match the documentation you cited. |
hmm, my first example definitely works fine, my bad there I think i was confusing my output from but i still can't figure out things for the 2nd multidimensional case. if you take the 2nd example from the spec (yours uses the first): using your code above, wrapping it in a tuple, i end up with this:
which is not the same as what is in the example in the spec. what i'm actually trying to do is use
which from parity (
and calling perhaps i'm missing something usage wise here? |
@tristan Actually, you aren't missing anything. I just checked the spec and this is a bug in our ABI library which has been there for a while. It appears that lists are supposed to be encoded exactly as if they were tuples. Honestly, I'm not sure why dynamic list elements are supposed to be encoded with an offset since I think they could also be encoded in-place without any ambiguity. Oh well -- I didn't write the spec! :/ Thanks for pointing this out! |
Actually, dynamic array elements must be encoded that way to facilitate constant-time indexing. |
What was wrong?
eth-abi does not support encoding or decoding arrays of tuples
e.g. the example contract at http://solidity.readthedocs.io/en/latest/abi-spec.html#handling-tuple-types has method signature of:
function f(S memory s, T memory t, uint a) public { }
whose type string is represented as
(uint256,uint256[],(uint256,uint256)[]),(uint256,uint256),uint256
calling the function requires passing the data:
How was it fixed?
I updated the grammar code to support optional arrays on tuples, and modified the tuple encoder/decoder to support processing arrays.
Missing
still potentially missing is support for multidimensional arrays. e.g. the following tests should also pass, but even the simple case
int[][]
doesn't. it seems this might require a bit more architectural work, which might be better for someone more familiar with the code to handle.Cute Animal Picture