poanetwork / ex_abi

The Ethereum ABI Interface
GNU General Public License v3.0
62 stars 43 forks source link

Uning array of complex types #44

Closed ghost closed 4 years ago

ghost commented 4 years ago

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 commented 4 years ago

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

sheehan1102 commented 3 years ago

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

ghost commented 3 years ago

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

sheehan1102 commented 3 years ago

@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 commented 3 years ago

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