@ -23,4 +23,10 @@ defmodule BlockScoutWeb.API.RPC.BlockController do
render(conn, :error, error: "Block does not exist")
end
def eth_block_number(conn, _params) do
max_block_number = Chain.fetch_max_block_number()
render(conn, :eth_block_number, number: max_block_number)
@ -22,6 +22,14 @@ defmodule BlockScoutWeb.API.RPC.BlockView do
RPCView.render("show.json", data: data)
def render("eth_block_number.json", %{number: number}) do
data = %{
"blockNumber" => to_string(number)
}
def render("error.json", %{error: error}) do
RPCView.render("error.json", error: error)
@ -1059,6 +1059,22 @@ defmodule Explorer.Chain do
@spec fetch_max_block_number() :: non_neg_integer
def fetch_max_block_number do
query =
from(block in Block,
select: max(block.number),
where: block.consensus == true
)
result = Repo.one!(query)
case result do
nil -> 0
_ -> result
@spec fetch_count_consensus_block() :: non_neg_integer
def fetch_count_consensus_block do