diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b01729a6f..342d35d5b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - [#5239](https://github.com/blockscout/blockscout/pull/5239) - Add accounting for block rewards in `getblockreward` api method ### Chore +- [#5419](https://github.com/blockscout/blockscout/pull/5419) - Add check if address exists for some api methods - [#5408](https://github.com/blockscout/blockscout/pull/5408) - Update websocket_client hex package - [#5407](https://github.com/blockscout/blockscout/pull/5407) - Update hackney, certifi, tzdata - [#5369](https://github.com/blockscout/blockscout/pull/5369) - Manage indexer memory limit diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/address_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/address_controller.ex index 2bab5e5b2f..54ef51a4e4 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/address_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/address_controller.ex @@ -100,6 +100,7 @@ defmodule BlockScoutWeb.API.RPC.AddressController do with {:address_param, {:ok, address_param}} <- fetch_address(params), {:format, {:ok, address_hash}} <- to_address_hash(address_param), + {:address, :ok} <- {:address, Chain.check_address_exists(address_hash)}, {:ok, transactions} <- list_transactions(address_hash, options) do render(conn, :txlist, %{transactions: transactions}) else @@ -113,7 +114,7 @@ defmodule BlockScoutWeb.API.RPC.AddressController do |> put_status(200) |> render(:error, error: "Invalid address format") - {:error, :not_found} -> + {_, :not_found} -> render(conn, :error, error: "No transactions found", data: []) end end @@ -148,13 +149,14 @@ defmodule BlockScoutWeb.API.RPC.AddressController do options = optional_params(params) with {:format, {:ok, address_hash}} <- to_address_hash(address_param), + {:address, :ok} <- {:address, Chain.check_address_exists(address_hash)}, {:ok, internal_transactions} <- list_internal_transactions(address_hash, options) do render(conn, :txlistinternal, %{internal_transactions: internal_transactions}) else {:format, :error} -> render(conn, :error, error: "Invalid address format") - {:error, :not_found} -> + {_, :not_found} -> render(conn, :error, error: "No internal transactions found", data: []) end end @@ -165,6 +167,7 @@ defmodule BlockScoutWeb.API.RPC.AddressController do with {:address_param, {:ok, address_param}} <- fetch_address(params), {:format, {:ok, address_hash}} <- to_address_hash(address_param), {:contract_address, {:ok, contract_address_hash}} <- to_contract_address_hash(params["contractaddress"]), + {:address, :ok} <- {:address, Chain.check_address_exists(address_hash)}, {:ok, token_transfers} <- list_token_transfers(address_hash, contract_address_hash, options) do render(conn, :tokentx, %{token_transfers: token_transfers}) else @@ -177,7 +180,7 @@ defmodule BlockScoutWeb.API.RPC.AddressController do {:contract_address, :error} -> render(conn, :error, error: "Invalid contract address format") - {:error, :not_found} -> + {_, :not_found} -> render(conn, :error, error: "No token transfers found", data: []) end end @@ -202,6 +205,7 @@ defmodule BlockScoutWeb.API.RPC.AddressController do def tokenlist(conn, params) do with {:address_param, {:ok, address_param}} <- fetch_address(params), {:format, {:ok, address_hash}} <- to_address_hash(address_param), + {:address, :ok} <- {:address, Chain.check_address_exists(address_hash)}, {:ok, token_list} <- list_tokens(address_hash) do render(conn, :token_list, %{token_list: token_list}) else @@ -211,7 +215,7 @@ defmodule BlockScoutWeb.API.RPC.AddressController do {:format, :error} -> render(conn, :error, error: "Invalid address format") - {:error, :not_found} -> + {_, :not_found} -> render(conn, :error, error: "No tokens found", data: []) end end @@ -221,6 +225,7 @@ defmodule BlockScoutWeb.API.RPC.AddressController do with {:address_param, {:ok, address_param}} <- fetch_address(params), {:format, {:ok, address_hash}} <- to_address_hash(address_param), + {:address, :ok} <- {:address, Chain.check_address_exists(address_hash)}, {:ok, blocks} <- list_blocks(address_hash, options) do render(conn, :getminedblocks, %{blocks: blocks}) else @@ -230,7 +235,7 @@ defmodule BlockScoutWeb.API.RPC.AddressController do {:format, :error} -> render(conn, :error, error: "Invalid address format") - {:error, :not_found} -> + {_, :not_found} -> render(conn, :error, error: "No blocks found", data: []) end end @@ -495,8 +500,8 @@ defmodule BlockScoutWeb.API.RPC.AddressController do end end - defp list_internal_transactions(transaction_hash, options) do - case Etherscan.list_internal_transactions(transaction_hash, options) do + defp list_internal_transactions(address_hash, options) do + case Etherscan.list_internal_transactions(address_hash, options) do [] -> {:error, :not_found} internal_transactions -> {:ok, internal_transactions} end