add eth_BlockNumber

pull/1933/head
Ayrat Badykov 6 years ago
parent cc3b0df467
commit f46970cab0
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 6
      apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/block_controller.ex
  2. 8
      apps/block_scout_web/lib/block_scout_web/views/api/rpc/block_view.ex
  3. 16
      apps/explorer/lib/explorer/chain.ex

@ -23,4 +23,10 @@ defmodule BlockScoutWeb.API.RPC.BlockController do
render(conn, :error, error: "Block does not exist")
end
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)
end
end

@ -22,6 +22,14 @@ defmodule BlockScoutWeb.API.RPC.BlockView do
RPCView.render("show.json", data: data)
end
def render("eth_block_number.json", %{number: number}) do
data = %{
"blockNumber" => to_string(number)
}
RPCView.render("show.json", data: data)
end
def render("error.json", %{error: error}) do
RPCView.render("error.json", error: error)
end

@ -1059,6 +1059,22 @@ defmodule Explorer.Chain do
end
end
@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
end
end
@spec fetch_count_consensus_block() :: non_neg_integer
def fetch_count_consensus_block do
query =

Loading…
Cancel
Save