diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index b83b3fe3e3..d7b031cd51 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -2946,7 +2946,7 @@ defmodule Explorer.Chain do on: token.contract_address_hash == token_transfer.token_contract_address_hash, left_join: instance in Instance, on: token_transfer.token_id == instance.token_id, - where: token.type == ^"ERC-721" and is_nil(instance.token_id), + where: token.type == ^"ERC-721" and is_nil(instance.token_id) and not is_nil(token_transfer.token_id), distinct: [token_transfer.token_contract_address_hash, token_transfer.token_id], select: %{contract_address_hash: token_transfer.token_contract_address_hash, token_id: token_transfer.token_id} ) diff --git a/apps/explorer/lib/explorer/token/instance_metadata_retriever.ex b/apps/explorer/lib/explorer/token/instance_metadata_retriever.ex index a4cf460e74..f1472c7a38 100644 --- a/apps/explorer/lib/explorer/token/instance_metadata_retriever.ex +++ b/apps/explorer/lib/explorer/token/instance_metadata_retriever.ex @@ -61,6 +61,11 @@ defmodule Explorer.Token.InstanceMetadataRetriever do {:error, %Error{reason: reason}} -> {:error, reason} end + rescue + e -> + Logger.error(fn -> ["Could not send request to token uri #{inspect(token_uri)}. error #{inspect(e)}"] end) + + {:error, :request_error} end defp fetch_json(result) do diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index c623ea2d4c..4556153b09 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -3645,6 +3645,28 @@ defmodule Explorer.ChainTest do assert result.contract_address_hash == token_transfer.token_contract_address_hash end + test "does not fetch token transfers without token id" do + token_contract_address = insert(:contract_address) + token = insert(:token, contract_address: token_contract_address, type: "ERC-721") + + transaction = + :transaction + |> insert() + |> with_block(insert(:block, number: 1)) + + insert( + :token_transfer, + block_number: 1000, + to_address: build(:address), + transaction: transaction, + token_contract_address: token_contract_address, + token: token, + token_id: nil + ) + + assert {:ok, []} = Chain.stream_unfetched_token_instances([], &[&1 | &2]) + end + test "do not fetch records with token instances" do token_contract_address = insert(:contract_address) token = insert(:token, contract_address: token_contract_address, type: "ERC-721")