From 97d8a2b2df7abc963ecfb186e6d78161b000610e Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Tue, 29 Oct 2024 10:25:03 +0200 Subject: [PATCH] fix: Fix scam badge value in some API endpoints (#11054) --- .../lib/block_scout_web/channels/address_channel.ex | 2 +- .../controllers/api/v2/address_controller.ex | 2 +- .../controllers/api/v2/block_controller.ex | 2 +- .../controllers/api/v2/main_page_controller.ex | 2 +- .../controllers/api/v2/transaction_controller.ex | 8 ++++---- .../transaction_interpretation.ex | 10 +++++----- .../block_scout_web/models/transaction_state_helper.ex | 2 +- apps/block_scout_web/lib/block_scout_web/notifier.ex | 2 +- .../lib/block_scout_web/views/api/v2/helper.ex | 4 ++++ apps/explorer/lib/explorer/chain/advanced_filter.ex | 4 ++-- .../lib/explorer/chain/internal_transaction.ex | 4 ++-- apps/explorer/lib/explorer/chain/token_transfer.ex | 8 ++++---- 12 files changed, 27 insertions(+), 23 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex b/apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex index b22306431b..ebc45d00c0 100644 --- a/apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex +++ b/apps/block_scout_web/lib/block_scout_web/channels/address_channel.ex @@ -49,7 +49,7 @@ defmodule BlockScoutWeb.AddressChannel do end @transaction_associations [ - from_address: [:names, :smart_contract, :proxy_implementations], + from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations], to_address: [ :scam_badge, :names, diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/address_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/address_controller.ex index 40b4b7c40e..b2a2319cd0 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/address_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/address_controller.ex @@ -53,7 +53,7 @@ defmodule BlockScoutWeb.API.V2.AddressController do necessity_by_association: %{ [created_contract_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, - [from_address: [:names, :smart_contract, :proxy_implementations]] => :optional, + [from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, [to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, :block => :optional } diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/block_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/block_controller.ex index e889cdf599..28eeeea316 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/block_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/block_controller.ex @@ -85,7 +85,7 @@ defmodule BlockScoutWeb.API.V2.BlockController do necessity_by_association: %{ [created_contract_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, - [from_address: [:names, :smart_contract, :proxy_implementations]] => :optional, + [from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, [to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, :block => :optional } diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/main_page_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/main_page_controller.ex index ec99ba4422..cb2c41f001 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/main_page_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/main_page_controller.ex @@ -25,7 +25,7 @@ defmodule BlockScoutWeb.API.V2.MainPageController do %{ :block => :required, [created_contract_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, - [from_address: [:names, :smart_contract, :proxy_implementations]] => :optional, + [from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, [to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional } |> Map.merge(@chain_type_transaction_necessity_by_association), diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/transaction_controller.ex index 54f9991ad3..1b92aa8514 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/transaction_controller.ex @@ -78,7 +78,7 @@ defmodule BlockScoutWeb.API.V2.TransactionController do :proxy_implementations ] ] => :optional, - [from_address: [:names, :smart_contract, :proxy_implementations]] => + [from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, [ to_address: [ @@ -573,7 +573,7 @@ defmodule BlockScoutWeb.API.V2.TransactionController do options = [ necessity_by_association: %{ - [from_address: [:names, :smart_contract, :proxy_implementations]] => :optional, + [from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, [to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional } ] @@ -600,8 +600,8 @@ defmodule BlockScoutWeb.API.V2.TransactionController do options = [ necessity_by_association: %{ - [from_address: [:names, :smart_contract, :proxy_implementations]] => :optional, - [to_address: [:names, :smart_contract, :proxy_implementations]] => :optional + [from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, + [to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional } ] |> Keyword.merge(@api_true) diff --git a/apps/block_scout_web/lib/block_scout_web/microservice_interfaces/transaction_interpretation.ex b/apps/block_scout_web/lib/block_scout_web/microservice_interfaces/transaction_interpretation.ex index 0fbedf613a..17d732bc64 100644 --- a/apps/block_scout_web/lib/block_scout_web/microservice_interfaces/transaction_interpretation.ex +++ b/apps/block_scout_web/lib/block_scout_web/microservice_interfaces/transaction_interpretation.ex @@ -109,7 +109,7 @@ defmodule BlockScoutWeb.MicroserviceInterfaces.TransactionInterpretation do Chain.select_repo(@api_true).preload(transaction, [ :block, to_address: [:scam_badge, :names, :smart_contract], - from_address: [:names, :smart_contract], + from_address: [:scam_badge, :names, :smart_contract], created_contract_address: [:scam_badge, :names, :token, :smart_contract] ]) @@ -176,8 +176,8 @@ defmodule BlockScoutWeb.MicroserviceInterfaces.TransactionInterpretation do full_options = [ necessity_by_association: %{ - [from_address: [:names, :smart_contract, :proxy_implementations]] => :optional, - [to_address: [:names, :smart_contract, :proxy_implementations]] => :optional + [from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, + [to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional } ] |> Keyword.merge(@api_true) @@ -254,8 +254,8 @@ defmodule BlockScoutWeb.MicroserviceInterfaces.TransactionInterpretation do token_transfer_options = [ necessity_by_association: %{ - [from_address: [:names, :smart_contract, :proxy_implementations]] => :optional, - [to_address: [:names, :smart_contract, :proxy_implementations]] => :optional, + [from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, + [to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] => :optional, :token => :optional } ] diff --git a/apps/block_scout_web/lib/block_scout_web/models/transaction_state_helper.ex b/apps/block_scout_web/lib/block_scout_web/models/transaction_state_helper.ex index 7959c4b02e..4f1a6a2804 100644 --- a/apps/block_scout_web/lib/block_scout_web/models/transaction_state_helper.ex +++ b/apps/block_scout_web/lib/block_scout_web/models/transaction_state_helper.ex @@ -77,7 +77,7 @@ defmodule BlockScoutWeb.Models.TransactionStateHelper do to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations] ], block: [miner: [:names, :smart_contract, :proxy_implementations]], - from_address: [:names, :smart_contract, :proxy_implementations], + from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations], to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations] ) diff --git a/apps/block_scout_web/lib/block_scout_web/notifier.ex b/apps/block_scout_web/lib/block_scout_web/notifier.ex index d630a31167..8c353b68ef 100644 --- a/apps/block_scout_web/lib/block_scout_web/notifier.ex +++ b/apps/block_scout_web/lib/block_scout_web/notifier.ex @@ -206,7 +206,7 @@ defmodule BlockScoutWeb.Notifier do base_preloads = [ :block, created_contract_address: [:scam_badge, :names, :smart_contract, :proxy_implementations], - from_address: [:names, :smart_contract, :proxy_implementations], + from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations], to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations] ] diff --git a/apps/block_scout_web/lib/block_scout_web/views/api/v2/helper.ex b/apps/block_scout_web/lib/block_scout_web/views/api/v2/helper.ex index d0ffdc9608..935fdc087d 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api/v2/helper.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api/v2/helper.ex @@ -159,6 +159,10 @@ defmodule BlockScoutWeb.API.V2.Helper do def address_name(_), do: nil + def address_marked_as_scam?(%Address{scam_badge: %Ecto.Association.NotLoaded{}}) do + false + end + def address_marked_as_scam?(%Address{scam_badge: scam_badge}) when not is_nil(scam_badge) do true end diff --git a/apps/explorer/lib/explorer/chain/advanced_filter.ex b/apps/explorer/lib/explorer/chain/advanced_filter.ex index 1684670b3a..62cdc1657b 100644 --- a/apps/explorer/lib/explorer/chain/advanced_filter.ex +++ b/apps/explorer/lib/explorer/chain/advanced_filter.ex @@ -115,8 +115,8 @@ defmodule Explorer.Chain.AdvancedFilter do |> Enum.sort(&sort_function/2) |> take_page_size(paging_options) |> Chain.select_repo(options).preload( - from_address: [:names, :smart_contract, :proxy_implementations], - to_address: [:names, :smart_contract, :proxy_implementations], + from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations], + to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations], created_contract_address: [:names, :smart_contract, :proxy_implementations] ) end diff --git a/apps/explorer/lib/explorer/chain/internal_transaction.ex b/apps/explorer/lib/explorer/chain/internal_transaction.ex index 3d62885d34..5d6b452470 100644 --- a/apps/explorer/lib/explorer/chain/internal_transaction.ex +++ b/apps/explorer/lib/explorer/chain/internal_transaction.ex @@ -832,8 +832,8 @@ defmodule Explorer.Chain.InternalTransaction do preloads = DenormalizationHelper.extend_transaction_preload([ :block, - [from_address: [:names, :smart_contract, :proxy_implementations]], - [to_address: [:names, :smart_contract, :proxy_implementations]] + [from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]], + [to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] ]) __MODULE__ diff --git a/apps/explorer/lib/explorer/chain/token_transfer.ex b/apps/explorer/lib/explorer/chain/token_transfer.ex index 1b9e3ac0ac..674efce8ff 100644 --- a/apps/explorer/lib/explorer/chain/token_transfer.ex +++ b/apps/explorer/lib/explorer/chain/token_transfer.ex @@ -239,7 +239,7 @@ defmodule Explorer.Chain.TokenTransfer do DenormalizationHelper.extend_transaction_preload([ :transaction, :token, - [from_address: [:names, :smart_contract, :proxy_implementations]], + [from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]], [to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] ]) @@ -266,7 +266,7 @@ defmodule Explorer.Chain.TokenTransfer do DenormalizationHelper.extend_transaction_preload([ :transaction, :token, - [from_address: [:names, :smart_contract, :proxy_implementations]], + [from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]], [to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] ]) @@ -299,8 +299,8 @@ defmodule Explorer.Chain.TokenTransfer do DenormalizationHelper.extend_transaction_preload([ :transaction, :token, - [from_address: [:names, :smart_contract, :proxy_implementations]], - [to_address: [:names, :smart_contract, :proxy_implementations]] + [from_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]], + [to_address: [:scam_badge, :names, :smart_contract, :proxy_implementations]] ]) only_consensus_transfers_query()