Add API v2 output for Latest Batch homepage section

pull/7584/head
POA 2 years ago
parent c445cdb290
commit 5d990c941c
  1. 1
      apps/block_scout_web/lib/block_scout_web/api_router.ex
  2. 12
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/zkevm_controller.ex
  3. 4
      apps/block_scout_web/lib/block_scout_web/views/api/v2/zkevm_view.ex
  4. 15
      apps/explorer/lib/explorer/chain.ex

@ -186,6 +186,7 @@ defmodule BlockScoutWeb.ApiRouter do
get("/transactions/watchlist", V2.MainPageController, :watchlist_transactions)
get("/indexing-status", V2.MainPageController, :indexing_status)
get("/zkevm-confirmed-batches", V2.ZkevmController, :batches_confirmed)
get("/zkevm-latest-batch-number", V2.ZkevmController, :batch_latest_number)
end
scope "/stats" do

@ -36,6 +36,18 @@ defmodule BlockScoutWeb.API.V2.ZkevmController do
|> render(:zkevm_batch, %{batch: batch})
end
def batch_latest_number(conn, _params) do
number =
case Chain.zkevm_batch(:latest, api?: true) do
{:ok, batch} -> batch.number
{:error, :not_found} -> 0
end
conn
|> put_status(200)
|> render(:zkevm_batch_latest_number, %{number: number})
end
def batches(conn, params) do
{batches, next_page} =
params

@ -48,6 +48,10 @@ defmodule BlockScoutWeb.API.V2.ZkevmView do
count
end
def render("zkevm_batch_latest_number.json", %{number: number}) do
number
end
defp batch_status(batch) do
sequence_id = Map.get(batch, :sequence_id)
verify_id = Map.get(batch, :verify_id)

@ -6391,7 +6391,20 @@ defmodule Explorer.Chain do
}
)
def zkevm_batch(number, options \\ []) when is_list(options) do
def zkevm_batch(number, options \\ [])
def zkevm_batch(:latest, options) when is_list(options) do
ZkevmTxnBatch
|> order_by(desc: :number)
|> limit(1)
|> select_repo(options).one()
|> case do
nil -> {:error, :not_found}
batch -> {:ok, batch}
end
end
def zkevm_batch(number, options) when is_list(options) do
necessity_by_association = Keyword.get(options, :necessity_by_association, %{})
ZkevmTxnBatch

Loading…
Cancel
Save