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

Support multidimensional tuple arrays #88

Closed
eruizgar91 opened this issue Feb 14, 2022 · 2 comments · Fixed by #89
Closed

Support multidimensional tuple arrays #88

eruizgar91 opened this issue Feb 14, 2022 · 2 comments · Fixed by #89

Comments

@eruizgar91
Copy link

eruizgar91 commented Feb 14, 2022

Currently there are not support for multidimensional tuple arrays, so when an abi contents a type like this tuple[][] is trying to parse it as if having a fixed length https://github.com/poanetwork/ex_abi/blob/master/lib/abi/function_selector.ex#L318 and generating an error.

It's posible to reproduce running this test:

test "parse multidimensional tuple" do
      abi = %{
        "constant" => true,
        "inputs" => [%{"name" => "swaps", "type" => "tuple[][]", "interalType" => "struct ExchangeProxy.Swap[][]", "components" => [
          %{
            "name" => "foo",
            "type" => "uint256"
          },
          %{
            "name" => "bar",
            "type" => "uint256"
          }
        ]}],
        "name" => "batchSwapExactOut",
        "outputs" => [%{"name" => "totalAmountIn", "type" => "uint256"}],
        "payable" => true,
        "stateMutability" => "payable",
        "type" => "function"
      }

      IO.inspect(ABI.parse_specification([abi])) 
    end

The error produced is:

  1) test parse multidimensional tuple (Explorer.SmartContract.ReaderTest)
     apps/explorer/test/explorer/smart_contract/reader_test.exs:385
     ** (ArgumentError) errors were found at the given arguments:
     
       * 1st argument: not a textual representation of an integer
     
     code: IO.inspect(ABI.parse_specification([abi]))
     stacktrace:
       :erlang.binary_to_integer("[")
       (ex_abi 0.5.9) lib/abi/function_selector.ex:318: ABI.FunctionSelector.parse_specification_type/1
       (elixir 1.12.3) lib/enum.ex:1582: Enum."-map/2-lists^map/1-0-"/2
       (ex_abi 0.5.9) lib/abi/function_selector.ex:174: ABI.FunctionSelector.parse_specification_item/1
       (elixir 1.12.3) lib/enum.ex:1582: Enum."-map/2-lists^map/1-0-"/2
       (ex_abi 0.5.9) lib/abi.ex:198: ABI.parse_specification/2
       test/explorer/smart_contract/reader_test.exs:405: (test)
@eruizgar91 eruizgar91 changed the title Support multidimensional arrays Support multidimensional tuple arrays Feb 14, 2022
@ayrat555
Copy link
Collaborator

ayrat555 commented Feb 19, 2022

@eruizgar91 hello can you please check if https://github.com/poanetwork/ex_abi/pull/89/files works for you

@eruizgar91
Copy link
Author

Yes @ayrat555 , it's working fine! Waiting for a new release. Thank you.

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

Successfully merging a pull request may close this issue.

2 participants