Skip to content

Commit

Permalink
fix: not found page for unknown blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev authored and vbaranov committed Feb 29, 2024
1 parent 7164222 commit 05d47d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule BlockScoutWeb.API.V2.BlobController do
use BlockScoutWeb, :controller

alias Explorer.Chain
alias Explorer.Chain.Beacon.Reader
alias Explorer.Chain.Beacon.{Blob, Reader}

action_fallback(BlockScoutWeb.API.V2.FallbackController)

Expand All @@ -14,16 +14,18 @@ defmodule BlockScoutWeb.API.V2.BlobController do
with {:format, {:ok, blob_hash}} <- {:format, Chain.string_to_transaction_hash(blob_hash_string)} do
transaction_hashes = Reader.blob_hash_to_transactions(blob_hash, api?: true)

case Reader.blob(blob_hash, true, api?: true) do
{:ok, blob} ->
conn
|> put_status(200)
|> render(:blob, %{blob: blob, transaction_hashes: transaction_hashes})
{status, blob} =
case Reader.blob(blob_hash, true, api?: true) do
{:ok, blob} -> {:ok, blob}
{:error, :not_found} -> {:pending, %Blob{hash: blob_hash}}
end

{:error, :not_found} ->
conn
|> put_status(200)
|> render(:blob, %{transaction_hashes: transaction_hashes})
if Enum.empty?(transaction_hashes) and status == :pending do
{:error, :not_found}
else
conn
|> put_status(200)
|> render(:blob, %{blob: blob, transaction_hashes: transaction_hashes})
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ defmodule BlockScoutWeb.API.V2.BlobView do
blob |> prepare_blob() |> Map.put("transaction_hashes", transaction_hashes)
end

def render("blob.json", %{transaction_hashes: transaction_hashes}) do
%{"transaction_hashes" => transaction_hashes}
end

def render("blobs.json", %{blobs: blobs}) do
%{"items" => Enum.map(blobs, &prepare_blob(&1))}
end
Expand Down

0 comments on commit 05d47d6

Please sign in to comment.