diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a20041854..710715d49e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## Current - ### Features +- [#2182](https://github.com/poanetwork/blockscout/pull/2182) - add market history cache - [#2109](https://github.com/poanetwork/blockscout/pull/2109) - use bigger updates instead of `Multi` transactions in BlocksTransactionsMismatch - [#2075](https://github.com/poanetwork/blockscout/pull/2075) - add blocks cache - [#2151](https://github.com/poanetwork/blockscout/pull/2151) - hide dropdown menu then other networks list is empty @@ -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 9446aad1f7..bb386940b1 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 1c5ba68229..9309884d5c 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/controllers/chain/market_history_chart_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/chain/market_history_chart_controller.ex index 4a498b8430..a89728949c 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/chain/market_history_chart_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/chain/market_history_chart_controller.ex @@ -8,18 +8,20 @@ defmodule BlockScoutWeb.Chain.MarketHistoryChartController do with true <- ajax?(conn) do exchange_rate = Market.get_exchange_rate(Explorer.coin()) || Token.null() + recent_market_history = Market.fetch_recent_history() + market_history_data = - 30 - |> Market.fetch_recent_history() - |> case do - [today | the_rest] -> [%{today | closing_price: exchange_rate.usd_value} | the_rest] - data -> data + case recent_market_history do + [today | the_rest] -> + encode_market_history_data([%{today | closing_price: exchange_rate.usd_value} | the_rest]) + + data -> + encode_market_history_data(data) end - |> encode_market_history_data() json(conn, %{ history_data: market_history_data, - supply_data: available_supply(Chain.supply_for_days(30), exchange_rate) + supply_data: available_supply(Chain.supply_for_days(), exchange_rate) }) else _ -> unprocessable_entity(conn) diff --git a/apps/block_scout_web/lib/block_scout_web/notifier.ex b/apps/block_scout_web/lib/block_scout_web/notifier.ex index 21a104848e..a5bc99e242 100644 --- a/apps/block_scout_web/lib/block_scout_web/notifier.ex +++ b/apps/block_scout_web/lib/block_scout_web/notifier.ex @@ -37,7 +37,7 @@ defmodule BlockScoutWeb.Notifier do exchange_rate = Market.get_exchange_rate(Explorer.coin()) || Token.null() market_history_data = - case Market.fetch_recent_history(30) do + case Market.fetch_recent_history() do [today | the_rest] -> [%{today | closing_price: exchange_rate.usd_value} | the_rest] data -> data 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 786c77cdff..308114a402 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 0000000000..f85620681a --- /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 73a92c7cfc..f2a4e9441e 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) + ) %>