Skip to content

Commit

Permalink
Merge pull request blockscout#9493 from blockscout/kf-blob-not-found
Browse files Browse the repository at this point in the history
Fix not found page for unknown blobs
  • Loading branch information
vbaranov authored Feb 29, 2024
2 parents 7164222 + 20f1f70 commit df1d259
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixes

- [#9502](https://github.com/blockscout/blockscout/pull/9502) - Add batch_size and concurrency envs for tt token type migration
- [#9493](https://github.com/blockscout/blockscout/pull/9493) - Fix API response for unknown blob hashes

### Chore

Expand Down
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 df1d259

Please sign in to comment.