diff --git a/apps/ethereum_jsonrpc/config/geth.exs b/apps/ethereum_jsonrpc/config/geth.exs index ec8528869b..ea0548c5ad 100644 --- a/apps/ethereum_jsonrpc/config/geth.exs +++ b/apps/ethereum_jsonrpc/config/geth.exs @@ -1,6 +1,5 @@ use Mix.Config config :ethereum_jsonrpc, - trace_url: "https://mainnet.infura.io/mew", url: "https://mainnet.infura.io/mew", variant: EthereumJSONRPC.Geth diff --git a/apps/ethereum_jsonrpc/config/parity.exs b/apps/ethereum_jsonrpc/config/parity.exs index b82c7a1603..5e1fb4ed89 100644 --- a/apps/ethereum_jsonrpc/config/parity.exs +++ b/apps/ethereum_jsonrpc/config/parity.exs @@ -1,6 +1,9 @@ use Mix.Config config :ethereum_jsonrpc, - trace_url: "https://sokol-trace.poa.network", url: "https://sokol.poa.network", + method_to_url: [ + eth_getBalance: "https://sokol-trace.poa.network", + trace_replayTransaction: "https://sokol-trace.poa.network" + ], variant: EthereumJSONRPC.Parity diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex index c7aaa8763a..3d78eda07c 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex @@ -89,6 +89,27 @@ defmodule EthereumJSONRPC do Application.fetch_env!(:ethereum_jsonrpc, key) end + @doc """ + Fetches the configured url for the specific `method` or the fallback `url` + + Configuration for a specific `method` can be set in `method_to_url` `config` + + config :ethereum_jsonrpc, + method_to_url: [ + eth_getBalance: "method_to_url" + ] + + The fallback 'url' MUST we set if not all methods have a url set. + + config :ethereum_jsonrpc, + url: + """ + def method_to_url(method) when is_atom(method) do + :ethereum_jsonrpc + |> Application.get_env(:method_to_url, []) + |> Keyword.get_lazy(method, fn -> config(:url) end) + end + @doc """ Fetches balance for each address `hash` at the `block_number` """ @@ -108,7 +129,7 @@ defmodule EthereumJSONRPC do with {:ok, responses} <- id_to_params |> get_balance_requests() - |> json_rpc(config(:trace_url)) do + |> json_rpc(method_to_url(:eth_getBalance)) do get_balance_responses_to_addresses_params(responses, id_to_params) end end @@ -121,7 +142,7 @@ defmodule EthereumJSONRPC do def fetch_blocks_by_hash(block_hashes) do block_hashes |> get_block_by_hash_requests() - |> json_rpc(config(:url)) + |> json_rpc(method_to_url(:eth_getBlockByHash)) |> handle_get_blocks() |> case do {:ok, _next, results} -> {:ok, results} @@ -135,7 +156,7 @@ defmodule EthereumJSONRPC do def fetch_blocks_by_range(_first.._last = range) do range |> get_block_by_number_requests() - |> json_rpc(config(:url)) + |> json_rpc(method_to_url(:eth_getBlockByNumber)) |> handle_get_blocks() end @@ -158,7 +179,7 @@ defmodule EthereumJSONRPC do def fetch_block_number_by_tag(tag) when tag in ~w(earliest latest pending) do tag |> get_block_by_tag_request() - |> json_rpc(config(:url)) + |> json_rpc(method_to_url(:eth_getBlockByNumber)) |> handle_get_block_by_tag() end diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex index 70659b797f..e70227fa07 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, id_to_params: 1, json_rpc: 2, request: 1] + import EthereumJSONRPC, only: [id_to_params: 1, method_to_url: 1, json_rpc: 2, request: 1] alias EthereumJSONRPC.Parity.Traces alias EthereumJSONRPC.{Transaction, Transactions} @@ -19,7 +19,7 @@ defmodule EthereumJSONRPC.Parity do with {:ok, responses} <- id_to_params |> trace_replay_transaction_requests() - |> json_rpc(config(:trace_url)) do + |> json_rpc(method_to_url(:trace_replayTransaction)) do trace_replay_transaction_responses_to_internal_transactions_params(responses, id_to_params) end end @@ -35,7 +35,7 @@ defmodule EthereumJSONRPC.Parity do with {:ok, transactions} <- %{id: 1, method: "parity_pendingTransactions", params: []} |> request() - |> json_rpc(config(:url)) do + |> json_rpc(method_to_url(:parity_pendingTransactions)) do transactions_params = transactions |> Transactions.to_elixir() diff --git a/coveralls.json b/coveralls.json index 186c305327..4341e638c9 100644 --- a/coveralls.json +++ b/coveralls.json @@ -1,7 +1,7 @@ { "coverage_options": { "treat_no_relevant_lines_as_covered": true, - "minimum_coverage": 94.4 + "minimum_coverage": 94.5 }, "terminal_options": { "file_column_width": 120