Skip to content
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

How to create function that returns array? #37

Closed
tomasz90 opened this issue Mar 29, 2022 · 2 comments
Closed

How to create function that returns array? #37

tomasz90 opened this issue Mar 29, 2022 · 2 comments

Comments

@tomasz90
Copy link

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?

@tomasz90
Copy link
Author

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

@esaulpaugh
Copy link
Owner

esaulpaugh commented Mar 29, 2022

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);

@esaulpaugh esaulpaugh pinned this issue Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants