parent
ec5240edd4
commit
dbc3921a97
@ -0,0 +1,26 @@ |
||||
defmodule BlockScoutWeb.API.V2.ZkevmController do |
||||
use BlockScoutWeb, :controller |
||||
|
||||
alias Explorer.Chain |
||||
|
||||
action_fallback(BlockScoutWeb.API.V2.FallbackController) |
||||
|
||||
@batch_necessity_by_association %{ |
||||
:sequence_transaction => :optional, |
||||
:verify_transaction => :optional, |
||||
:l2_transactions => :required |
||||
} |
||||
|
||||
def batch(conn, %{"batch_number" => batch_number} = _params) do |
||||
{:ok, batch} = |
||||
Chain.zkevm_batch( |
||||
batch_number, |
||||
necessity_by_association: @batch_necessity_by_association, |
||||
api?: true |
||||
) |
||||
|
||||
conn |
||||
|> put_status(200) |
||||
|> render(:zkevm_batch, %{batch: batch}) |
||||
end |
||||
end |
@ -0,0 +1,22 @@ |
||||
defmodule BlockScoutWeb.API.V2.ZkevmView do |
||||
use BlockScoutWeb, :view |
||||
|
||||
def render("zkevm_batch.json", %{batch: batch}) do |
||||
%{ |
||||
"number" => batch.number, |
||||
"status" => batch_status(batch), |
||||
"timestamp" => batch.timestamp |
||||
} |
||||
end |
||||
|
||||
defp batch_status(batch) do |
||||
sequence_id = Map.get(batch, :sequence_id) |
||||
verify_id = Map.get(batch, :verify_id) |
||||
|
||||
cond do |
||||
is_nil(sequence_id) && is_nil(verify_id) -> "Unfinalized" |
||||
!is_nil(sequence_id) && is_nil(verify_id) -> "L1 Sequence Confirmed" |
||||
!is_nil(verify_id) -> "Finalized" |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue