# `ABI.FunctionSelector`

Module to help parse the ABI function signatures, e.g.
`my_function(uint64, string[])`.

# `t`

```elixir
@type t() :: %ABI.FunctionSelector{
  function: String.t() | nil,
  input_names: [String.t()],
  inputs_indexed: [boolean()],
  method_id: binary() | nil,
  return_names: [String.t()],
  returns: [type()],
  state_mutability: :pure | :view | :non_payable | :payable | nil,
  type: :event | :function | :constructor | :error,
  types: [type()]
}
```

Struct to represent a function and its input and output types.

* `:function` - Name of the function
* `:types` - Function's input types
* `:returns` - Function's return types
* `:return_names` - Names of the return values (output names)
* `:method_id` - First four bytes of the hashed function signature or full 32 byte hash for events
* `:input_names` - Names of the input values (argument names)
* `:type` - The type of the selector. Events are part of the ABI, but are not considered functions
* `:inputs_index` - A list of true/false values denoting if each input is indexed. Only populated for events.

# `type`

```elixir
@type type() ::
  {:uint, integer()}
  | :bool
  | :string
  | :address
  | :function
  | {:array, type()}
  | {:array, type(), non_neg_integer()}
  | {:tuple, [type()]}
  | :bytes
  | {:bytes, non_neg_integer()}
  | {:ufixed, non_neg_integer(), non_neg_integer()}
  | {:fixed, non_neg_integer(), non_neg_integer()}
  | {:int, integer()}
```

# `decode`

Decodes a function selector to a struct.

## Examples

    iex> ABI.FunctionSelector.decode("bark(uint256,bool)")
    %ABI.FunctionSelector{
      function: "bark",
      types: [
        {:uint, 256},
        :bool
      ],
      returns: []
    }

    iex> ABI.FunctionSelector.decode("growl(uint,address,string[])")
    %ABI.FunctionSelector{
      function: "growl",
      types: [
        {:uint, 256},
        :address,
        {:array, :string}
      ],
      returns: []
    }

    iex> ABI.FunctionSelector.decode("rollover()")
    %ABI.FunctionSelector{
      function: "rollover",
      types: [],
      returns: []
    }

    iex> ABI.FunctionSelector.decode("do_playDead3()")
    %ABI.FunctionSelector{
      function: "do_playDead3",
      types: [],
      returns: []
    }

    iex> ABI.FunctionSelector.decode("pet(address[])")
    %ABI.FunctionSelector{
      function: "pet",
      types: [
        {:array, :address}
      ],
      returns: []
    }

    iex> ABI.FunctionSelector.decode("paw(string[2])")
    %ABI.FunctionSelector{
      function: "paw",
      types: [
        {:array, :string, 2}
      ],
      returns: []
    }

    iex> ABI.FunctionSelector.decode("scram(uint256[])")
    %ABI.FunctionSelector{
      function: "scram",
      types: [
        {:array, {:uint, 256}}
      ],
      returns: []
    }

    iex> ABI.FunctionSelector.decode("shake((string))")
    %ABI.FunctionSelector{
      function: "shake",
      types: [
        {:tuple, [:string]}
      ],
      returns: []
    }

# `decode_raw`

Decodes the given type-string as a simple array of types.

## Examples

    iex> ABI.FunctionSelector.decode_raw("string,uint256")
    [:string, {:uint, 256}]

    iex> ABI.FunctionSelector.decode_raw("")
    []

# `decode_type`

Decodes the given type-string as a single type.

## Examples

    iex> ABI.FunctionSelector.decode_type("uint256")
    {:uint, 256}

    iex> ABI.FunctionSelector.decode_type("(bool,address)")
    {:tuple, [:bool, :address]}

    iex> ABI.FunctionSelector.decode_type("address[][3]")
    {:array, {:array, :address}, 3}

# `encode`

Encodes a function call signature.

## Examples

    iex> ABI.FunctionSelector.encode(%ABI.FunctionSelector{
    ...>   function: "bark",
    ...>   types: [
    ...>     {:uint, 256},
    ...>     :bool,
    ...>     {:array, :string},
    ...>     {:array, :string, 3},
    ...>     {:tuple, [{:uint, 256}, :bool]}
    ...>   ]
    ...> })
    "bark(uint256,bool,string[],string[3],(uint256,bool))"

# `encode_type`

Encodes the given single type as a type-string.

## Examples

    iex> ABI.FunctionSelector.encode_type({:uint, 256})
    "uint256"

    iex> ABI.FunctionSelector.encode_type({:tuple, [:bool, :address]})
    "(bool,address)"

    iex> ABI.FunctionSelector.encode_type({:array, {:array, :address}, 3})
    "address[][3]"

# `parse_specification_type`

# `simple_types?`

```elixir
@spec simple_types?([map()], map()) :: boolean()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
