From fd5b83096c29cbcbf4c003556d8f8eef222acd86 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 14 Aug 2020 00:56:35 +0300 Subject: [PATCH] Fix contract funnction method detection --- .../ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex index 0f1cec0cd4..2ca335c076 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex @@ -32,14 +32,21 @@ defmodule EthereumJSONRPC.Contract do abi |> ABI.parse_specification() - functions = Enum.into(parsed_abi, %{}, &{&1.function, &1}) + functions = Enum.into(parsed_abi, %{}, &{&1.method_id, &1}) requests_with_index = Enum.with_index(requests) + [{%{function_name: function_name}, _}] = requests_with_index + indexed_responses = requests_with_index |> Enum.map(fn {%{contract_address: contract_address, function_name: function_name, args: args} = request, index} -> - functions[function_name] + {_, function} = + Enum.find(functions, fn {method_id, func} -> + func.function == function_name && Enum.count(func.input_names) == Enum.count(args) + end) + + function |> Encoder.encode_function_call(args) |> eth_call_request(contract_address, index, Map.get(request, :block_number), Map.get(request, :from)) end)