esaulpaugh / headlong

High-performance Contract ABI and RLP for Ethereum

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to create function that returns array?

tomasz90 opened this issue · comments

I've got problem with creation function that returns struct array.
My function looks like: getPoolsInfo(address[]) then the output is array of structs. Struct has fields: address, string, string
I tried to create function like this:

val f = Function("getPoolsInfo(address[])", "(address,string,string)[]")

But ide is screaming that it cannot cast arraytype to tupletype.
Can you tell me how to construct this function properly?

FYI and anyone that might look for this:
((address,string,string))

Inputs and outputs must be specified by a TupleType, as all Functions accept a Tuple of arguments and return a Tuple of return values. What you're looking for is a singleton return type, a tuple with one element. Try:

Function("getPoolsInfo(address[])", "((address,string,string)[])")

For singleton return types, there is a shortcut method as well which unwraps the return Tuple for you and infers the type of the one element:

Tuple[] zeroth = f.decodeSingletonReturn(bytes);