Fix contract funnction method detection

pull/3237/head
Victor Baranov 4 years ago
parent a2a3248907
commit fd5b83096c
  1. 11
      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)

Loading…
Cancel
Save