diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex index 182bd3d5e0..b16b16cb55 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/geth.ex @@ -27,15 +27,7 @@ defmodule EthereumJSONRPC.Geth do def fetch_internal_transactions(transactions_params, json_rpc_named_arguments) when is_list(transactions_params) do id_to_params = id_to_params(transactions_params) - debug_trace_transaction_timeout = - Application.get_env(:ethereum_jsonrpc, __MODULE__)[:debug_trace_transaction_timeout] - - parsed_timeout = CommonHelper.parse_duration(debug_trace_transaction_timeout) - - json_rpc_named_arguments_corrected_timeout = - json_rpc_named_arguments - |> put_in([:transport_options, :http_options, :timeout], parsed_timeout) - |> put_in([:transport_options, :http_options, :recv_timeout], parsed_timeout) + json_rpc_named_arguments_corrected_timeout = correct_timeouts(json_rpc_named_arguments) with {:ok, responses} <- id_to_params @@ -49,6 +41,21 @@ defmodule EthereumJSONRPC.Geth do end end + defp correct_timeouts(json_rpc_named_arguments) do + debug_trace_transaction_timeout = + Application.get_env(:ethereum_jsonrpc, __MODULE__)[:debug_trace_transaction_timeout] + + case CommonHelper.parse_duration(debug_trace_transaction_timeout) do + {:error, :invalid_format} -> + json_rpc_named_arguments + + parsed_timeout -> + json_rpc_named_arguments + |> put_in([:transport_options, :http_options, :timeout], parsed_timeout) + |> put_in([:transport_options, :http_options, :recv_timeout], parsed_timeout) + end + end + @doc """ Fetches the first trace from the trace URL. """ diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/common_helper.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/common_helper.ex index 65f8a092e3..154edb78bd 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/common_helper.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/utility/common_helper.ex @@ -3,17 +3,17 @@ defmodule EthereumJSONRPC.Utility.CommonHelper do Common helper functions """ - # converts duration like "5s", "2m" to milliseconds - @duration_regex ~r/^(\d+)([smh]{1})$/ + # converts duration like "5s", "2m", "1h5m" to milliseconds + @duration_regex ~r/(\d+)([smhSMH]?)/ def parse_duration(duration) do - case Regex.run(@duration_regex, duration) do - [_, number, granularity] -> - number - |> String.to_integer() - |> convert_to_ms(granularity) - - _ -> + case Regex.scan(@duration_regex, duration) do + [] -> {:error, :invalid_format} + + parts -> + Enum.reduce(parts, 0, fn [_, number, granularity], acc -> + acc + convert_to_ms(String.to_integer(number), String.downcase(granularity)) + end) end end