|
|
@ -28,10 +28,11 @@ defmodule EthereumJSONRPC.Contract do |
|
|
|
|
|
|
|
|
|
|
|
@spec execute_contract_functions([call()], [map()], EthereumJSONRPC.json_rpc_named_arguments()) :: [call_result()] |
|
|
|
@spec execute_contract_functions([call()], [map()], EthereumJSONRPC.json_rpc_named_arguments()) :: [call_result()] |
|
|
|
def execute_contract_functions(requests, abi, json_rpc_named_arguments) do |
|
|
|
def execute_contract_functions(requests, abi, json_rpc_named_arguments) do |
|
|
|
functions = |
|
|
|
parsed_abi = |
|
|
|
abi |
|
|
|
abi |
|
|
|
|> ABI.parse_specification() |
|
|
|
|> ABI.parse_specification() |
|
|
|
|> Enum.into(%{}, &{&1.function, &1}) |
|
|
|
|
|
|
|
|
|
|
|
functions = Enum.into(parsed_abi, %{}, &{&1.function, &1}) |
|
|
|
|
|
|
|
|
|
|
|
requests_with_index = Enum.with_index(requests) |
|
|
|
requests_with_index = Enum.with_index(requests) |
|
|
|
|
|
|
|
|
|
|
@ -52,13 +53,15 @@ defmodule EthereumJSONRPC.Contract do |
|
|
|
|> Enum.into(%{}, &{&1.id, &1}) |
|
|
|
|> Enum.into(%{}, &{&1.id, &1}) |
|
|
|
|
|
|
|
|
|
|
|
Enum.map(requests_with_index, fn {%{function_name: function_name}, index} -> |
|
|
|
Enum.map(requests_with_index, fn {%{function_name: function_name}, index} -> |
|
|
|
|
|
|
|
selectors = Enum.filter(parsed_abi, fn p_abi -> p_abi.function == function_name end) |
|
|
|
|
|
|
|
|
|
|
|
indexed_responses[index] |
|
|
|
indexed_responses[index] |
|
|
|
|> case do |
|
|
|
|> case do |
|
|
|
nil -> |
|
|
|
nil -> |
|
|
|
{:error, "No result"} |
|
|
|
{:error, "No result"} |
|
|
|
|
|
|
|
|
|
|
|
response -> |
|
|
|
response -> |
|
|
|
{^index, result} = Encoder.decode_result(response, functions[function_name]) |
|
|
|
{^index, result} = Encoder.decode_result(response, selectors) |
|
|
|
result |
|
|
|
result |
|
|
|
end |
|
|
|
end |
|
|
|
end) |
|
|
|
end) |
|
|
|