fix: Add compatibility with current frontend for some public props (#10998)

* fix: Fix renaming of public props

* Fix sanitize_duplicated_log_index_logs_test.exs

---------

Co-authored-by: Nikita Pozdniakov <nikitosing4@mail.ru>
pull/11000/head
Victor Baranov 1 week ago committed by GitHub
parent 26d906a5cc
commit 6319514bcf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/address_controller.ex
  2. 1
      apps/explorer/config/config.exs
  3. 1
      apps/explorer/config/runtime/test.exs
  4. 116
      apps/explorer/lib/encrypt.ex
  5. 2
      apps/explorer/lib/explorer/account/notifier/email.ex
  6. 4
      apps/explorer/lib/explorer/application.ex
  7. 59
      apps/explorer/lib/explorer/migrator/sanitize_duplicated_log_index_logs.ex
  8. 30
      apps/explorer/priv/repo/migrations/20241022133006_add_aux_types_for_duplicated_log_index_logs_migration.exs
  9. 2
      apps/explorer/test/explorer/account/notifier/email_test.exs
  10. 0
      apps/explorer/test/explorer/migrator/sanitize_duplicated_log_index_logs_test.exs

@ -511,7 +511,9 @@ defmodule BlockScoutWeb.API.V2.AddressController do
token_balances: :token_balances_count,
logs: :logs_count,
withdrawals: :withdrawals_count,
internal_transactions: :internal_transactions_count,
# todo: support of 2 props in API endpoint is for compatibility with the current version of frontend.
# It should be ultimately removed.
internal_transactions: [:internal_transactions_count, :internal_txs_count],
celo_election_rewards: :celo_election_rewards_count
}
@ -523,7 +525,15 @@ defmodule BlockScoutWeb.API.V2.AddressController do
|> Map.fetch(counter_name)
|> case do
{:ok, json_field_name} ->
# todo: array-type value processing here is temporary. Please remove it with updating frontend to the new version.
if is_list(json_field_name) do
# credo:disable-for-next-line
Enum.reduce(json_field_name, acc, fn field_name, acc2 ->
Map.put(acc2, field_name, counter_value)
end)
else
Map.put(acc, json_field_name, counter_value)
end
:error ->
acc

@ -131,6 +131,7 @@ config :explorer, Explorer.Migrator.RestoreOmittedWETHTransfers, enabled: true
config :explorer, Explorer.Migrator.SanitizeMissingTokenBalances, enabled: true
config :explorer, Explorer.Migrator.SanitizeReplacedTransactions, enabled: true
config :explorer, Explorer.Migrator.ReindexInternalTransactionsWithIncompatibleStatus, enabled: true
config :explorer, Explorer.Migrator.SanitizeDuplicatedLogIndexLogs, enabled: true
config :explorer, Explorer.Chain.Fetcher.CheckBytecodeMatchingOnDemand, enabled: true

@ -52,6 +52,7 @@ config :explorer, Explorer.Migrator.RestoreOmittedWETHTransfers, enabled: false
config :explorer, Explorer.Migrator.SanitizeMissingTokenBalances, enabled: false
config :explorer, Explorer.Migrator.SanitizeReplacedTransactions, enabled: false
config :explorer, Explorer.Migrator.ReindexInternalTransactionsWithIncompatibleStatus, enabled: false
config :explorer, Explorer.Migrator.SanitizeDuplicatedLogIndexLogs, enabled: false
config :explorer,
realtime_events_sender: Explorer.Chain.Events.SimpleSender

@ -1,116 +0,0 @@
defmodule Mix.Tasks.Encrypt do
@moduledoc "The encrypt mix task: `mix help encrypt`"
use Mix.Task
alias Ecto.Changeset
alias Explorer.Account.{
CustomABI,
Identity,
PublicTagsRequest,
TagAddress,
TagTransaction,
WatchlistAddress,
WatchlistNotification
}
alias Explorer.Repo.Account
alias Mix.Task
@shortdoc "Encrypt"
def run(_) do
Task.run("app.start")
Identity
|> Account.all()
|> Enum.each(fn element ->
element
|> Changeset.change(%{
encrypted_uid: element.uid,
encrypted_email: element.email,
encrypted_name: element.name,
encrypted_nickname: element.nickname,
encrypted_avatar: element.avatar,
uid_hash: element.uid
})
|> Account.update!()
end)
TagAddress
|> Account.all()
|> Enum.each(fn element ->
element
|> Changeset.change(%{
encrypted_name: element.name,
encrypted_address_hash: element.address_hash,
address_hash_hash: element.address_hash |> to_string() |> String.downcase()
})
|> Account.update!()
end)
TagTransaction
|> Account.all()
|> Enum.each(fn element ->
element
|> Changeset.change(%{
encrypted_name: element.name,
encrypted_transaction_hash: element.transaction_hash,
transaction_hash_hash: element.transaction_hash |> to_string() |> String.downcase()
})
|> Account.update!()
end)
CustomABI
|> Account.all()
|> Enum.each(fn element ->
element
|> Changeset.change(%{
encrypted_name: element.name,
encrypted_address_hash: element.address_hash,
address_hash_hash: element.address_hash |> to_string() |> String.downcase()
})
|> Account.update!()
end)
WatchlistAddress
|> Account.all()
|> Enum.each(fn element ->
element
|> Changeset.change(%{
encrypted_name: element.name,
encrypted_address_hash: element.address_hash,
address_hash_hash: element.address_hash |> to_string() |> String.downcase()
})
|> Account.update!()
end)
WatchlistNotification
|> Account.all()
|> Enum.each(fn element ->
element
|> Changeset.change(%{
encrypted_name: element.name,
encrypted_from_address_hash: element.from_address_hash,
encrypted_to_address_hash: element.to_address_hash,
encrypted_transaction_hash: element.transaction_hash,
encrypted_subject: element.subject,
from_address_hash_hash: element.from_address_hash |> to_string() |> String.downcase(),
to_address_hash_hash: element.to_address_hash |> to_string() |> String.downcase(),
transaction_hash_hash: element.transaction_hash |> to_string() |> String.downcase(),
subject_hash: element.subject
})
|> Account.update!()
end)
PublicTagsRequest
|> Account.all()
|> Enum.each(fn element ->
element
|> Changeset.change(%{
encrypted_full_name: element.full_name,
encrypted_email: element.email
})
|> Account.update!()
end)
end
end

@ -35,6 +35,8 @@ defmodule Explorer.Account.Notifier.Email do
|> add_dynamic_field("block_number", notification.block_number)
|> add_dynamic_field("amount", amount(notification))
|> add_dynamic_field("name", notification.name)
# todo: keep next line for compatibility with old version of SendGrid template. Remove it when the changes released and Sendgrid template updated.
|> add_dynamic_field("tx_fee", notification.transaction_fee)
|> add_dynamic_field("transaction_fee", notification.transaction_fee)
|> add_dynamic_field("direction", direction(notification))
|> add_dynamic_field("method", notification.method)

@ -146,7 +146,9 @@ defmodule Explorer.Application do
configure_mode_dependent_process(Explorer.Migrator.ShrinkInternalTransactions, :indexer),
configure_chain_type_dependent_process(Explorer.Chain.Cache.BlackfortValidatorsCounters, :blackfort),
configure_chain_type_dependent_process(Explorer.Chain.Cache.StabilityValidatorsCounters, :stability),
configure_chain_type_dependent_process(Explorer.Migrator.SanitizeDuplicatedLogIndexLogs, [
Explorer.Migrator.SanitizeDuplicatedLogIndexLogs
|> configure()
|> configure_chain_type_dependent_process([
:polygon_zkevm,
:rsk,
:filecoin

@ -199,11 +199,7 @@ defmodule Explorer.Migrator.SanitizeDuplicatedLogIndexLogs do
logs
|> Enum.sort_by(&{&1.transaction.index, &1.index, &1.transaction_hash})
# credo:disable-for-next-line Credo.Check.Refactor.Nesting
|> Enum.map_reduce(0, fn log, index ->
{{log, index}, index + 1}
end)
|> elem(0)
|> Enum.with_index(&{&1, &2})
end
end
@ -215,57 +211,4 @@ defmodule Explorer.Migrator.SanitizeDuplicatedLogIndexLogs do
defp token_transfer_to_index(token_transfer) do
{token_transfer.transaction_hash, token_transfer.block_hash, token_transfer.log_index}
end
@doc """
Callback function that is executed before the migration process starts.
"""
@impl FillingMigration
def before_start do
"""
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'log_id') THEN
CREATE TYPE log_id AS (
transaction_hash bytea,
block_hash bytea,
log_index integer
);
END IF;
END$$;
"""
|> Repo.query!()
"""
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'nft_id') THEN
CREATE TYPE nft_id AS (
block_number bigint,
log_index integer
);
END IF;
END$$;
"""
|> Repo.query!()
:ok
end
@doc """
Callback function that is executed when the migration process finishes.
"""
@impl FillingMigration
def on_finish do
"""
DROP TYPE log_id;
"""
|> Repo.query!([], timeout: :infinity)
"""
DROP TYPE nft_id;
"""
|> Repo.query!([], timeout: :infinity)
:ok
end
end

@ -0,0 +1,30 @@
defmodule Explorer.Repo.Migrations.AddAuxTypesForDuplicatedLogIndexLogsMigration do
use Ecto.Migration
def up do
execute("""
CREATE TYPE log_id AS (
transaction_hash bytea,
block_hash bytea,
log_index integer
);
""")
execute("""
CREATE TYPE nft_id AS (
block_number bigint,
log_index integer
);
""")
end
def down do
execute("""
DROP TYPE log_id;
""")
execute("""
DROP TYPE nft_id;
""")
end
end

@ -110,6 +110,8 @@ defmodule Explorer.Account.Notifier.EmailTest do
"transaction_url" =>
"https://eth.blockscout.com/tx/0x5d5ff210261f1b2d6e4af22ea494f428f9997d4ab614a629d4f1390004b3e80d",
"transaction_fee" => Decimal.new(210_000),
# todo: keep next line for compatibility with old version of SendGrid template. Remove it when the changes released and Sendgrid template updated.
"tx_fee" => Decimal.new(210_000),
"username" => "John Snow"
},
template_id: "d-666"

Loading…
Cancel
Save