poanetwork / ex_abi

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

Type parsing error #161

Closed sl1depengwyn closed 7 months ago

sl1depengwyn commented 8 months ago
    ** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not a textual representation of an integer

        (erts 13.2.2.5) :erlang.binary_to_integer("2[")
        (ex_abi 0.6.4) lib/abi/function_selector.ex:339: ABI.FunctionSelector.parse_specification_type/1
        (elixir 1.14.5) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
        (ex_abi 0.6.4) lib/abi/function_selector.ex:189: ABI.FunctionSelector.parse_specification_item/1
        (elixir 1.14.5) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
        (ex_abi 0.6.4) lib/abi.ex:228: ABI.parse_specification/2

Contract and ABI example:

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.8.2 <0.9.0;

contract StorageB {
    function retrieve(uint256 a) public virtual returns (uint256) {
        return 1 + (a * 23) / 10;
    }

    struct s {
        uint256 a;
        uint256 b;
    }

    function test() public pure returns (bytes20[] memory) {
        // Initialize a two-dimensional dynamic array in memory
        bytes20[][] memory array = new bytes20[][](2); // Create 2 rows

        array[0] = new bytes20[](2); // Create 2 columns for the first row
        array[1] = new bytes20[](3); // Create 3 columns for the second row

        // Assign values to the array elements
        array[0][0] = bytes20(0x1111111111111111111111111111111111111111);
        array[0][1] = bytes20(0x2222222222222222222222222222222222222222);

        array[1][0] = bytes20(0x3333333333333333333333333333333333333333);
        array[1][1] = bytes20(0x4444444444444444444444444444444444444444);
        array[1][2] = bytes20(0x5555555555555555555555555555555555555555);

        return array[0];
    }

    struct MyTuple {
        uint256 element1;
        bool element2;
    }

    function createTupleArray() public pure returns (MyTuple[2][] memory) {
        // Initialize a two-dimensional dynamic array in memory
        MyTuple[2][] memory tupleArray = new MyTuple[2][](2); // 2 rows

        tupleArray[0] = [MyTuple(123, true), MyTuple(456, false)]; // 2 columns for the first row
        tupleArray[1] = [MyTuple(101112, false), MyTuple(131415, true)]; // 2 columns for the second row

        return tupleArray;
    }
}
[
    {
        "inputs": [
            {
                "internalType": "uint256",
                "name": "a",
                "type": "uint256"
            }
        ],
        "name": "retrieve",
        "outputs": [
            {
                "internalType": "uint256",
                "name": "",
                "type": "uint256"
            }
        ],
        "stateMutability": "nonpayable",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "createTupleArray",
        "outputs": [
            {
                "components": [
                    {
                        "internalType": "uint256",
                        "name": "element1",
                        "type": "uint256"
                    },
                    {
                        "internalType": "bool",
                        "name": "element2",
                        "type": "bool"
                    }
                ],
                "internalType": "struct StorageB.MyTuple[2][]",
                "name": "",
                "type": "tuple[2][]"
            }
        ],
        "stateMutability": "pure",
        "type": "function"
    },
    {
        "inputs": [],
        "name": "test",
        "outputs": [
            {
                "internalType": "bytes20[]",
                "name": "",
                "type": "bytes20[]"
            }
        ],
        "stateMutability": "pure",
        "type": "function"
    }
]