|
|
@ -32,14 +32,21 @@ defmodule EthereumJSONRPC.Contract do |
|
|
|
abi |
|
|
|
abi |
|
|
|
|> ABI.parse_specification() |
|
|
|
|> 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) |
|
|
|
requests_with_index = Enum.with_index(requests) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[{%{function_name: function_name}, _}] = requests_with_index |
|
|
|
|
|
|
|
|
|
|
|
indexed_responses = |
|
|
|
indexed_responses = |
|
|
|
requests_with_index |
|
|
|
requests_with_index |
|
|
|
|> Enum.map(fn {%{contract_address: contract_address, function_name: function_name, args: args} = request, 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) |
|
|
|
|> Encoder.encode_function_call(args) |
|
|
|
|> eth_call_request(contract_address, index, Map.get(request, :block_number), Map.get(request, :from)) |
|
|
|
|> eth_call_request(contract_address, index, Map.get(request, :block_number), Map.get(request, :from)) |
|
|
|
end) |
|
|
|
end) |
|
|
|