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

Uning array of complex types #44

Closed
ghost opened this issue Sep 29, 2020 · 5 comments
Closed

Uning array of complex types #44

ghost opened this issue Sep 29, 2020 · 5 comments

Comments

@ghost
Copy link

ghost commented Sep 29, 2020

I am trying to use the ABI with the https://github.com/makerdao/multicall contract.

aggregate(Call[] memory calls)

    struct Call {
        address target;
        bytes callData;
    }

So I am using the encode function with aggregate((address,bytes)[])

I am getting the following error:

        # 1
        {:tuple, [:address, :bytes]}
        # 2
        <<238, 251, 161, 230, 57, 5, 239, 29, 122, 203, 165, 168, 81, 60, 112, 48, 124, 28, 228, 65>>
        # 3
        []
        # 4
        []

I have also tried to do:

      function = %ABI.FunctionSelector{
        function: "aggregate",
        input_names: ["calls"],
        type: :function,
        types: [array: {:tuple, [:address, :bytes]}]
      }
    ABI.encode(function, values)

The issue is the binary isn't passing the Kernel.is_tupple condition.

The second parameter passed to the function is:

[
[address, data]
]
@ghost
Copy link
Author

ghost commented Sep 30, 2020

What I ended up doing is add the array inside an array, indeed the second parameter is an array of arguments.

@ghost ghost closed this as completed Sep 30, 2020
@sheehan1102
Copy link

@steffenix can you show your working solution? I'm having same issue.

@ghost
Copy link
Author

ghost commented Oct 22, 2020

Are you sure you are using the library properly?
The parameters should be an array

@sheehan1102
Copy link

@steffenix I'm assuming I'm not, because it is not working.

Here is example code:

params = Enum.map(assets, fn asset ->
  [asset.address, "balanceOf(address)"]
end)

abi =
  ABI.encode("aggregate((address,bytes)[])", params)

Params are an array.

I receive the same error as you did above, since the first param coming into do_encode_type does not match any function clause.

@ghost
Copy link
Author

ghost commented Oct 22, 2020

Can't help with more code but I would look at the address format check the examples they need to be decoded

This issue was closed.
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

1 participant