diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex index 24321a9a4d..f0fece3239 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex @@ -206,6 +206,19 @@ defmodule EthereumJSONRPC do hexadecimal_to_integer(quantity) end + @doc """ + A request payload for a JSONRPC. + """ + @spec request(%{id: term, method: String.t(), params: list()}) :: %{String.t() => term} + def request(%{id: id, method: method, params: params}) do + %{ + "id" => id, + "jsonrpc" => "2.0", + "method" => method, + "params" => params + } + end + @doc """ Converts `t:timestamp/0` to `t:DateTime.t/0` """ @@ -254,15 +267,6 @@ defmodule EthereumJSONRPC do get_block_by_number_request(%{id: tag, tag: tag, transactions: :hashes}) end - defp request(%{id: id, method: method, params: params}) do - %{ - "id" => id, - "jsonrpc" => "2.0", - "method" => method, - "params" => params - } - end - defp get_block_by_number_params(options) do [get_block_by_number_subject(options), get_block_transactions(options)] end diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex index 7bebac6ba6..8ac626809a 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex @@ -3,7 +3,7 @@ defmodule EthereumJSONRPC.Parity do Ethereum JSONRPC methods that are only supported by [Parity](https://wiki.parity.io/). """ - import EthereumJSONRPC, only: [config: 1, json_rpc: 2] + import EthereumJSONRPC, only: [config: 1, json_rpc: 2, request: 1] alias EthereumJSONRPC.Parity.Traces @@ -34,7 +34,7 @@ defmodule EthereumJSONRPC.Parity do def fetch_internal_transactions(transaction_hashes) when is_list(transaction_hashes) do with {:ok, responses} <- transaction_hashes - |> Enum.map(&transaction_hash_to_internal_transaction_json/1) + |> Enum.map(&transaction_hash_to_internal_transaction_request/1) |> json_rpc(config(:trace_url)) do internal_transactions_params = responses @@ -58,12 +58,7 @@ defmodule EthereumJSONRPC.Parity do Enum.flat_map(responses, &response_to_trace/1) end - defp transaction_hash_to_internal_transaction_json(transaction_hash) do - %{ - "id" => transaction_hash, - "jsonrpc" => "2.0", - "method" => "trace_replayTransaction", - "params" => [transaction_hash, ["trace"]] - } + defp transaction_hash_to_internal_transaction_request(transaction_hash) do + request(%{id: transaction_hash, method: "trace_replayTransaction", params: [transaction_hash, ["trace"]]}) end end