Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions eth_client/lib/eth_client/abi.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ defmodule EthClient.ABI do
def get(abi_path), do: get_local(abi_path)

def to_selector(function_def) do
selector = ABI.FunctionSelector.decode(function_def["name"])

selector
ABI.FunctionSelector.decode(function_def["name"])
|> Map.put(:method_id, function_def["selector"])
|> Map.put(:state_mutability, function_def["stateMutability"])
end
Expand Down
12 changes: 7 additions & 5 deletions eth_client/lib/eth_client/contract.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,21 @@ defmodule EthClient.Contract do
|> Macro.underscore()
|> String.to_atom()

acc = Map.put(acc, selector_atom, Code.eval_quoted(function) |> elem(0))
{term, _bind} = Code.eval_quoted(function)
acc = Map.put(acc, selector_atom, term)

parse_abi(tail, acc)
end

defp parse_abi([%{type: function, method_id: selector} = method_map | tail], acc) do
defp parse_abi([%{type: _function, method_id: selector} = method_map | tail], acc) do
function = build_function_by_hash(method_map)

selector_atom =
selector
|> String.to_atom()

acc = Map.put(acc, selector_atom, Code.eval_quoted(function) |> elem(0))
{term, _bind} = Code.eval_quoted(function)
acc = Map.put(acc, selector_atom, term)

parse_abi(tail, acc)
end
Expand All @@ -63,7 +65,7 @@ defmodule EthClient.Contract do
parse_abi(tail, acc)
end

defp build_function_by_hash(%{method_id: selector, state_mutability: mutability} = method)
defp build_function_by_hash(%{method_id: _selector, state_mutability: mutability} = method)
when mutability in ["pure", "view"] do
args =
method.types
Expand All @@ -79,7 +81,7 @@ defmodule EthClient.Contract do
end
end

defp build_function_by_hash(%{method_id: selector} = method) do
defp build_function_by_hash(%{method_id: _selector} = method) do
args =
method
|> Map.get(:types)
Expand Down