diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a2004185435..b4e62d4751a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ - [#2173](https://github.com/poanetwork/blockscout/pull/2173) - handle correctly empty transactions - [#2174](https://github.com/poanetwork/blockscout/pull/2174) - fix reward channel joining - [#2186](https://github.com/poanetwork/blockscout/pull/2186) - fix net version test +- [#2167](https://github.com/poanetwork/blockscout/pull/2168) - feat: document eth rpc api mimicking endpoints ### Chore - [#2127](https://github.com/poanetwork/blockscout/pull/2127) - use previouse chromedriver version diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/eth_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/eth_controller.ex index 9446aad1f79f..bb386940b1b7 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/eth_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/eth_controller.ex @@ -29,6 +29,8 @@ defmodule BlockScoutWeb.API.RPC.EthController do 3 => "fourth" } + def methods, do: @methods + def eth_request(%{body_params: %{"_json" => requests}} = conn, _) when is_list(requests) do responses = responses(requests) @@ -106,7 +108,11 @@ defmodule BlockScoutWeb.API.RPC.EthController do end defp render_log(log) do - topics = Enum.reject([log.first_topic, log.second_topic, log.third_topic, log.fourth_topic], &is_nil/1) + topics = + Enum.reject( + [log.first_topic, log.second_topic, log.third_topic, log.fourth_topic], + &is_nil/1 + ) %{ "address" => to_string(log.address_hash), @@ -245,7 +251,8 @@ defmodule BlockScoutWeb.API.RPC.EthController do defp to_block_numbers(from_block, to_block, max_block_number, pending_block_number) do actual_pending_block_number = pending_block_number || max_block_number - with {:ok, from} <- to_block_number(from_block, max_block_number, actual_pending_block_number), + with {:ok, from} <- + to_block_number(from_block, max_block_number, actual_pending_block_number), {:ok, to} <- to_block_number(to_block, max_block_number, actual_pending_block_number) do {:ok, from, to} end diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api_docs_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api_docs_controller.ex index 1c5ba68229c1..9309884d5ca5 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api_docs_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api_docs_controller.ex @@ -1,6 +1,7 @@ defmodule BlockScoutWeb.APIDocsController do use BlockScoutWeb, :controller + alias BlockScoutWeb.API.RPC.EthController alias BlockScoutWeb.Etherscan def index(conn, _params) do @@ -8,4 +9,10 @@ defmodule BlockScoutWeb.APIDocsController do |> assign(:documentation, Etherscan.get_documentation()) |> render("index.html") end + + def eth_rpc(conn, _params) do + conn + |> assign(:documentation, EthController.methods()) + |> render("eth_rpc.html") + end end diff --git a/apps/block_scout_web/lib/block_scout_web/router.ex b/apps/block_scout_web/lib/block_scout_web/router.ex index 786c77cdffb5..308114a40233 100644 --- a/apps/block_scout_web/lib/block_scout_web/router.ex +++ b/apps/block_scout_web/lib/block_scout_web/router.ex @@ -247,6 +247,7 @@ defmodule BlockScoutWeb.Router do get("/chain_blocks", ChainController, :chain_blocks, as: :chain_blocks) get("/api_docs", APIDocsController, :index) + get("/eth_rpc_api_docs", APIDocsController, :eth_rpc) get("/:page", PageNotFoundController, :index) end diff --git a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex new file mode 100644 index 000000000000..f85620681a9a --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex @@ -0,0 +1,34 @@ +
+
+
+

<%= gettext("ETH RPC API Documentation") %>

+

[ <%= gettext "Base URL:" %> <%= @conn.host %>/api/eth_rpc ]

+

+ <%= gettext "This API is provided to support some rpc methods in the exact format specified for ethereum nodes, which can be found " %> + + <%= gettext "here." %> + <%= gettext "This is useful to allow sending requests to blockscout without having to change anything about the request." %> + <%= gettext "However, in general, the" %> <%= link( + gettext("custom RPC"), + to: api_docs_path(@conn, :index) + ) %> <%= gettext " is recommended." %> + <%= gettext "Anything not in this list is not supported. Click on the method to be taken to the documentation for that method, and check the notes section for any potential differences." %> +

+
+
+
+
+ + + + + + <%= for {method, info} <- Map.to_list(@documentation) do %> + + + + + <% end %> +
Supported MethodNotes
<%= method %> <%= Map.get(info, :notes, "N/A") %>
+
+
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex index 73a92c7cfc5a..f2a4e9441e52 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex @@ -74,6 +74,11 @@ class: "dropdown-item #{tab_status("api_docs", @conn.request_path)}", to: api_docs_path(@conn, :index) ) %> + <%= link( + gettext("Eth RPC"), + class: "dropdown-item #{tab_status("api_docs", @conn.request_path)}", + to: api_docs_path(@conn, :eth_rpc) + ) %>