diff --git a/lib/abi/event.ex b/lib/abi/event.ex index 8c28356..807d8c7 100644 --- a/lib/abi/event.ex +++ b/lib/abi/event.ex @@ -91,7 +91,7 @@ defmodule ABI.Event do defp indexed_arg_values([{_, type, _} | rest_args], [topic | rest_topics], acc) do value = - if ABI.FunctionSelector.is_dynamic?(type) do + if ABI.FunctionSelector.dynamic?(type) do {bytes, _} = ABI.TypeDecoder.decode_bytes(topic, 32, :left) # This is explained in the docstring. The caller will almost certainly diff --git a/lib/abi/function_selector.ex b/lib/abi/function_selector.ex index 4c87e5c..65789ba 100644 --- a/lib/abi/function_selector.ex +++ b/lib/abi/function_selector.ex @@ -449,13 +449,13 @@ defmodule ABI.FunctionSelector do defp get_type(els), do: raise("Unsupported type: #{inspect(els)}") @doc false - @spec is_dynamic?(ABI.FunctionSelector.type()) :: boolean - def is_dynamic?(:bytes), do: true - def is_dynamic?(:string), do: true - def is_dynamic?({:array, _type}), do: true - def is_dynamic?({:array, type, len}) when len > 0, do: is_dynamic?(type) - def is_dynamic?({:tuple, types}), do: Enum.any?(types, &is_dynamic?/1) - def is_dynamic?(_), do: false + @spec dynamic?(ABI.FunctionSelector.type()) :: boolean + def dynamic?(:bytes), do: true + def dynamic?(:string), do: true + def dynamic?({:array, _type}), do: true + def dynamic?({:array, type, len}) when len > 0, do: dynamic?(type) + def dynamic?({:tuple, types}), do: Enum.any?(types, &dynamic?/1) + def dynamic?(_), do: false @doc false def from_params(params) when is_map(params) do diff --git a/lib/abi/type_decoder.ex b/lib/abi/type_decoder.ex index 4fb2d8b..edbcaae 100644 --- a/lib/abi/type_decoder.ex +++ b/lib/abi/type_decoder.ex @@ -184,7 +184,7 @@ defmodule ABI.TypeDecoder do {reversed_result, binary_rest} = Enum.reduce(types, {[], binary_data}, fn type, {acc, binary} -> {value, rest} = - if FunctionSelector.is_dynamic?(type) do + if FunctionSelector.dynamic?(type) do decode_type(type, binary, binary_data) else decode_type(type, binary) @@ -262,7 +262,7 @@ defmodule ABI.TypeDecoder do defp decode_type({:tuple, types}, data) do {reversed_result, _, binary} = Enum.reduce(types, {[], [], data}, fn type, {acc, dynamic, binary} -> - if FunctionSelector.is_dynamic?(type) do + if FunctionSelector.dynamic?(type) do {val, binary} = decode_type(type, binary, data) {[val | acc], [type | dynamic], binary} else @@ -323,7 +323,7 @@ defmodule ABI.TypeDecoder do {reversed_result, _, _binary} = Enum.reduce(types, {[], [], tuple_data}, fn type, {acc, dynamic, binary} -> - if FunctionSelector.is_dynamic?(type) do + if FunctionSelector.dynamic?(type) do {val, binary} = decode_type(type, binary, tuple_data) {[val | acc], [type | dynamic], binary} else diff --git a/lib/abi/type_encoder.ex b/lib/abi/type_encoder.ex index bbf2041..a105e7c 100644 --- a/lib/abi/type_encoder.ex +++ b/lib/abi/type_encoder.ex @@ -193,7 +193,7 @@ defmodule ABI.TypeEncoder do types = List.duplicate(type, size) result = do_encode(data, types, mode) - if FunctionSelector.is_dynamic?(type) do + if FunctionSelector.dynamic?(type) do data_bytes_size = byte_size(result) {[{:dynamic, data_bytes_size} | static_acc], [result | dynamic_acc]} @@ -227,7 +227,7 @@ defmodule ABI.TypeEncoder do when is_list(list_parameters) do result = do_encode(list_parameters, types, :standard) - if FunctionSelector.is_dynamic?(type) do + if FunctionSelector.dynamic?(type) do data_bytes_size = byte_size(result) {[{:dynamic, data_bytes_size} | static_acc], [result | dynamic_acc]}