Use EthereumJSONRPC.request in EthereumJSONRPC.Parity

pull/255/head
Luke Imhoff 7 years ago
parent 1c65a217e6
commit 394df24ea2
  1. 22
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex
  2. 13
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex

@ -206,6 +206,19 @@ defmodule EthereumJSONRPC do
hexadecimal_to_integer(quantity) hexadecimal_to_integer(quantity)
end 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 """ @doc """
Converts `t:timestamp/0` to `t:DateTime.t/0` 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}) get_block_by_number_request(%{id: tag, tag: tag, transactions: :hashes})
end 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 defp get_block_by_number_params(options) do
[get_block_by_number_subject(options), get_block_transactions(options)] [get_block_by_number_subject(options), get_block_transactions(options)]
end end

@ -3,7 +3,7 @@ defmodule EthereumJSONRPC.Parity do
Ethereum JSONRPC methods that are only supported by [Parity](https://wiki.parity.io/). 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 alias EthereumJSONRPC.Parity.Traces
@ -34,7 +34,7 @@ defmodule EthereumJSONRPC.Parity do
def fetch_internal_transactions(transaction_hashes) when is_list(transaction_hashes) do def fetch_internal_transactions(transaction_hashes) when is_list(transaction_hashes) do
with {:ok, responses} <- with {:ok, responses} <-
transaction_hashes 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 |> json_rpc(config(:trace_url)) do
internal_transactions_params = internal_transactions_params =
responses responses
@ -58,12 +58,7 @@ defmodule EthereumJSONRPC.Parity do
Enum.flat_map(responses, &response_to_trace/1) Enum.flat_map(responses, &response_to_trace/1)
end end
defp transaction_hash_to_internal_transaction_json(transaction_hash) do defp transaction_hash_to_internal_transaction_request(transaction_hash) do
%{ request(%{id: transaction_hash, method: "trace_replayTransaction", params: [transaction_hash, ["trace"]]})
"id" => transaction_hash,
"jsonrpc" => "2.0",
"method" => "trace_replayTransaction",
"params" => [transaction_hash, ["trace"]]
}
end end
end end

Loading…
Cancel
Save