esaulpaugh / headlong

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

`TupleType.subTupleType` not unwrapping tuple of a single tuple #31

Closed devictr closed 2 years ago

devictr commented 2 years ago

Hi,

I've noticed that this function, when called with on a Tuple that looks like this ((address,int256)) and this manifest: [true], will still return ((address,int256)) even though I would expect to get (address,int256). I'd be happy to help fix this issue, if it is actually an issue 🙂

esaulpaugh commented 2 years ago

subtupleType with a manifest of all true values should return a TupleType equal to the input TupleType. An all-true manifest is similar to using str.substring(0, str.length()).

It was originally designed for separating indexed and non-indexed event parameters and isn't intended to treat TupleType elements differently compared to other elements.

I will see about adding some javadoc to it.

I may just rename the method if I can think of one more descriptive.

esaulpaugh commented 2 years ago

In addition to adding documentation, I have decided to rename TupleType::subTupleType to select and TupleType::subTupleTypeNegative to exclude.

devictr commented 2 years ago

Ah good to know! Thank you

esaulpaugh commented 2 years ago

I just added type inference to TupleType::get. Subtuples should now be accessible like this:

TupleType outer = TupleType.parse("((address,int256))"); TupleType inner = outer.get(0); assertEquals(TupleType.parse("(address,int)"), inner);

devictr commented 2 years ago

Even better! Thanks