diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ce5b20857dc..c07548d592fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/blob_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/blob_controller.ex index 724b4b8e9bbf..f72a6424a7c3 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/blob_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/blob_controller.ex @@ -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) @@ -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 diff --git a/apps/block_scout_web/lib/block_scout_web/views/api/v2/blob_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api/v2/blob_view.ex index 680fa5f04604..fcb792ac095e 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api/v2/blob_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api/v2/blob_view.ex @@ -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