Skip to content

Commit

Permalink
Merge pull request blockscout#2167 from poanetwork/add_compatibility_…
Browse files Browse the repository at this point in the history
…matrix

feat: document eth rpc api mimicking endpoints
  • Loading branch information
vbaranov authored Jun 20, 2019
2 parents bd7ded7 + f6f9302 commit 883ce4e
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
defmodule BlockScoutWeb.APIDocsController do
use BlockScoutWeb, :controller

alias BlockScoutWeb.API.RPC.EthController
alias BlockScoutWeb.Etherscan

def index(conn, _params) do
conn
|> 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
1 change: 1 addition & 0 deletions apps/block_scout_web/lib/block_scout_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<section class="container">
<div class="card">
<div class="card-body">
<h1 class="card-title margin-bottom-sm"><%= gettext("ETH RPC API Documentation") %></h2>
<p class="api-text-monospace" data-endpoint-url="<%= BlockScoutWeb.Endpoint.url() %>/api/eth_rpc">[ <%= gettext "Base URL:" %> <%= @conn.host %>/api/eth_rpc ]</p>
<p class="card-subtitle margin-bottom-0">
<%= gettext "This API is provided to support some rpc methods in the exact format specified for ethereum nodes, which can be found " %>

<a href="https://github.com/ethereum/wiki/wiki/JSON-RPC"><%= gettext "here." %></a>
<%= 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." %>
</p>
</div>
</div>
<div class="card">
<div class="card-body">
<table class="table">
<tr>
<th>Supported Method</th>
<th>Notes</th>
</tr>
<%= for {method, info} <- Map.to_list(@documentation) do %>
<tr>
<td> <a href="https://github.com/ethereum/wiki/wiki/JSON-RPC#<%= method %>"> <%= method %> </a> </td>
<td> <%= Map.get(info, :notes, "N/A") %> </td>
</tr>
<% end %>
</table>
</div>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) %>
</div>
</li>
<li class="nav-item dropdown nav-item-networks">
Expand Down
54 changes: 50 additions & 4 deletions apps/block_scout_web/priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ msgid "Balance"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:5
#: lib/block_scout_web/templates/api_docs/index.html.eex:5
msgid "Base URL:"
msgstr ""
Expand Down Expand Up @@ -665,8 +666,8 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_logs/index.html.eex:14
#: lib/block_scout_web/templates/layout/_topnav.html.eex:111
#: lib/block_scout_web/templates/layout/_topnav.html.eex:128
#: lib/block_scout_web/templates/layout/_topnav.html.eex:116
#: lib/block_scout_web/templates/layout/_topnav.html.eex:133
msgid "Search"
msgstr ""

Expand Down Expand Up @@ -1479,8 +1480,8 @@ msgid "Error: Could not determine contract creator."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:105
#: lib/block_scout_web/templates/layout/_topnav.html.eex:109
#: lib/block_scout_web/templates/layout/_topnav.html.eex:110
#: lib/block_scout_web/templates/layout/_topnav.html.eex:114
msgid "Search by address, token symbol name, transaction hash, or block number"
msgstr ""

Expand Down Expand Up @@ -1702,3 +1703,48 @@ msgstr ""
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27
msgid "There is no decompilded contracts for this address."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:14
msgid " is recommended."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:15
msgid "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."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:4
msgid "ETH RPC API Documentation"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:78
msgid "Eth RPC"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:11
msgid "However, in general, the"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:7
msgid "This API is provided to support some rpc methods in the exact format specified for ethereum nodes, which can be found "
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:10
msgid "This is useful to allow sending requests to blockscout without having to change anything about the request."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:12
msgid "custom RPC"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:9
msgid "here."
msgstr ""
56 changes: 51 additions & 5 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ msgid "Balance"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:5
#: lib/block_scout_web/templates/api_docs/index.html.eex:5
msgid "Base URL:"
msgstr ""
Expand Down Expand Up @@ -665,8 +666,8 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_logs/index.html.eex:14
#: lib/block_scout_web/templates/layout/_topnav.html.eex:111
#: lib/block_scout_web/templates/layout/_topnav.html.eex:128
#: lib/block_scout_web/templates/layout/_topnav.html.eex:116
#: lib/block_scout_web/templates/layout/_topnav.html.eex:133
msgid "Search"
msgstr ""

Expand Down Expand Up @@ -1479,8 +1480,8 @@ msgid "Error: Could not determine contract creator."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:105
#: lib/block_scout_web/templates/layout/_topnav.html.eex:109
#: lib/block_scout_web/templates/layout/_topnav.html.eex:110
#: lib/block_scout_web/templates/layout/_topnav.html.eex:114
msgid "Search by address, token symbol name, transaction hash, or block number"
msgstr ""

Expand Down Expand Up @@ -1698,7 +1699,52 @@ msgstr ""
msgid " Token Transfer"
msgstr ""

#, elixir-format, fuzzy
#, elixir-format
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27
msgid "There is no decompilded contracts for this address."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:14
msgid " is recommended."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:15
msgid "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."
msgstr ""

#, elixir-format, fuzzy
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:4
msgid "ETH RPC API Documentation"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/layout/_topnav.html.eex:78
msgid "Eth RPC"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:11
msgid "However, in general, the"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:7
msgid "This API is provided to support some rpc methods in the exact format specified for ethereum nodes, which can be found "
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:10
msgid "This is useful to allow sending requests to blockscout without having to change anything about the request."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:12
msgid "custom RPC"
msgstr ""

#, elixir-format, fuzzy
#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:9
msgid "here."
msgstr ""

0 comments on commit 883ce4e

Please sign in to comment.