ABI parsing tuple type

This commit is contained in:
Victor Baranov 2020-05-06 14:44:42 +03:00
parent fcc3955f3c
commit 08e24c2232
4 changed files with 122 additions and 1 deletions

View File

@ -174,6 +174,10 @@ defmodule ABI do
...> |> ABI.parse_specification(include_events?: true)
...> |> Enum.filter(&(&1.type == :event))
[%ABI.FunctionSelector{type: :event, function: "WantsPets", input_names: ["_from_human", "_number", "_belly"], inputs_indexed: [true, false, true], method_id: <<235, 155, 60, 76>>, types: [:string, {:uint, 256}, :bool]}]
iex> File.read!("priv/example1.abi.json")
...> |> Jason.decode!
...> |> ABI.parse_specification(include_events?: true)
"""
def parse_specification(doc, opts \\ []) do
if opts[:include_events?] do

116
priv/example1.abi.json Normal file
View File

@ -0,0 +1,116 @@
[
{
"constant": true,
"inputs": [
{"internalType": "uint160", "name": "exitId", "type": "uint160"}
],
"name": "inFlightExits",
"outputs": [
{
"components": [
{"internalType": "bool", "name": "isCanonical", "type": "bool"},
{
"internalType": "uint64",
"name": "exitStartTimestamp",
"type": "uint64"
},
{
"internalType": "uint256",
"name": "exitMap",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "position",
"type": "uint256"
},
{
"components": [
{
"internalType": "bytes32",
"name": "outputId",
"type": "bytes32"
},
{
"internalType": "address payable",
"name": "exitTarget",
"type": "address"
},
{
"internalType": "address",
"name": "token",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "piggybackBondSize",
"type": "uint256"
}
],
"internalType": "struct PaymentExitDataModel.WithdrawData[4]",
"name": "inputs",
"type": "tuple[4]"
},
{
"components": [
{
"internalType": "bytes32",
"name": "outputId",
"type": "bytes32"
},
{
"internalType": "address payable",
"name": "exitTarget",
"type": "address"
},
{
"internalType": "address",
"name": "token",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "piggybackBondSize",
"type": "uint256"
}
],
"internalType": "struct PaymentExitDataModel.WithdrawData[4]",
"name": "outputs",
"type": "tuple[4]"
},
{
"internalType": "address payable",
"name": "bondOwner",
"type": "address"
},
{
"internalType": "uint256",
"name": "bondSize",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "oldestCompetitorPosition",
"type": "uint256"
}
],
"internalType": "struct PaymentExitDataModel.InFlightExit",
"name": "",
"type": "tuple"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]

View File

@ -3,7 +3,7 @@ Definitions.
INT = [0-9]+
LETTERS = [a-zA-Z_]+
WHITESPACE = [\s\t\n\r]
TYPES = uint|int|address|bool|fixed|uint|ufixed|bytes|function|string
TYPES = uint|int|address|bool|fixed|uint|ufixed|bytes|function|string|tuple
Rules.

View File

@ -61,6 +61,7 @@ plain_type(string) -> string;
plain_type(bytes) -> bytes;
plain_type(int) -> juxt_type(int, 256);
plain_type(uint) -> juxt_type(uint, 256);
plain_type(tuple) -> tuple;
plain_type(fixed) -> double_juxt_type(fixed, x, 128, 19);
plain_type(ufixed) -> double_juxt_type(ufixed, x, 128, 19).