From 6a127294a734bba4ba8352ae88c9397cbd7d6f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9F=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=BD=D1=8F=D0=BA=D0=BE=D0=B2?= Date: Fri, 21 Oct 2022 16:28:09 +0300 Subject: [PATCH] Copy public tags functionality to master --- CHANGELOG.md | 1 + .../lib/block_scout_web/models/get_address_tags.ex | 6 +++--- .../block_scout_web/models/get_transaction_tags.ex | 11 +++++++++-- .../templates/address/_labels.html.eex | 3 +++ apps/explorer/config/config.exs | 2 ++ apps/explorer/lib/explorer/application.ex | 1 + config/runtime.exs | 1 + 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9ec774f88..464ad0a010 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- [#6316](https://github.com/blockscout/blockscout/pull/6316) - Copy public tags functionality to master - [#6196](https://github.com/blockscout/blockscout/pull/6196) - INDEXER_CATCHUP_BLOCKS_BATCH_SIZE and INDEXER_CATCHUP_BLOCKS_CONCURRENCY env varaibles - [#6187](https://github.com/blockscout/blockscout/pull/6187) - Filter by created time of verified contracts in listcontracts API endpoint - [#6092](https://github.com/blockscout/blockscout/pull/6092) - Blockscout Account functionality diff --git a/apps/block_scout_web/lib/block_scout_web/models/get_address_tags.ex b/apps/block_scout_web/lib/block_scout_web/models/get_address_tags.ex index 459d5dffdb..bbb02d9bdd 100644 --- a/apps/block_scout_web/lib/block_scout_web/models/get_address_tags.ex +++ b/apps/block_scout_web/lib/block_scout_web/models/get_address_tags.ex @@ -11,17 +11,17 @@ defmodule BlockScoutWeb.Models.GetAddressTags do alias Explorer.Tags.{AddressTag, AddressToTag} def get_address_tags(nil, nil), - do: %{personal_tags: [], watchlist_names: []} + do: %{common_tags: [], personal_tags: [], watchlist_names: []} def get_address_tags(%Hash{} = address_hash, current_user) do %{ - # common_tags: get_tags_on_address(address_hash), + common_tags: get_tags_on_address(address_hash), personal_tags: get_personal_tags(address_hash, current_user), watchlist_names: get_watchlist_names_on_address(address_hash, current_user) } end - def get_address_tags(_, _), do: %{personal_tags: [], watchlist_names: []} + def get_address_tags(_, _), do: %{common_tags: [], personal_tags: [], watchlist_names: []} def get_public_tags(%Hash{} = address_hash) do %{ diff --git a/apps/block_scout_web/lib/block_scout_web/models/get_transaction_tags.ex b/apps/block_scout_web/lib/block_scout_web/models/get_transaction_tags.ex index c173a43a33..2f3ef3f029 100644 --- a/apps/block_scout_web/lib/block_scout_web/models/get_transaction_tags.ex +++ b/apps/block_scout_web/lib/block_scout_web/models/get_transaction_tags.ex @@ -3,7 +3,7 @@ defmodule BlockScoutWeb.Models.GetTransactionTags do Get various types of tags associated with the transaction """ - import BlockScoutWeb.Models.GetAddressTags, only: [get_address_tags: 2] + import BlockScoutWeb.Models.GetAddressTags, only: [get_address_tags: 2, get_tags_on_address: 1] alias Explorer.Account.TagTransaction alias Explorer.Chain.Transaction @@ -18,7 +18,13 @@ defmodule BlockScoutWeb.Models.GetTransactionTags do Map.put(addresses_tags, :personal_tx_tag, tx_tag) end - def get_transaction_with_addresses_tags(_, _), do: %{personal_tags: [], watchlist_names: [], personal_tx_tag: nil} + def get_transaction_with_addresses_tags(%Transaction{} = transaction, _), + do: %{ + common_tags: get_tags_on_address(transaction.to_address_hash), + personal_tags: [], + watchlist_names: [], + personal_tx_tag: nil + } def get_transaction_tags(transaction_hash, %{id: identity_id}) do Repo.account_repo().get_by(TagTransaction, tx_hash_hash: transaction_hash, identity_id: identity_id) @@ -34,6 +40,7 @@ defmodule BlockScoutWeb.Models.GetTransactionTags do to_tags = get_address_tags(transaction.to_address_hash, %{id: identity_id, watchlist_id: watchlist_id}) %{ + common_tags: get_tags_on_address(transaction.to_address_hash), personal_tags: Enum.dedup(from_tags.personal_tags ++ to_tags.personal_tags), watchlist_names: Enum.dedup(from_tags.watchlist_names ++ to_tags.watchlist_names) } diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_labels.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_labels.html.eex index d572dec993..dbfb5bac75 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/_labels.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_labels.html.eex @@ -1,3 +1,6 @@ +<%= for common_tag <- @tags.common_tags do %> + <%= render BlockScoutWeb.FormView, "_tag.html", text: common_tag.display_name, additional_classes: [tag_name_to_label(common_tag.label), "ml-1"] %> +<% end %> <%= for personal_tag <- @tags.personal_tags do %> <%= if personal_tag.address_hash do %> <%= if personal_tag.label =~ "dark forest" do %> diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index c58d3bfd37..4ecea375fa 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -87,6 +87,8 @@ config :explorer, Explorer.Chain.Cache.GasUsage, config :explorer, Explorer.Integrations.EctoLogger, query_time_ms_threshold: :timer.seconds(2) +config :explorer, Explorer.Tags.AddressTag.Cataloger, enabled: true + config :explorer, Explorer.Chain.Cache.MinMissingBlockNumber, enabled: System.get_env("DISABLE_WRITE_API") != "true" config :explorer, Explorer.Repo, migration_timestamps: [type: :utc_datetime_usec] diff --git a/apps/explorer/lib/explorer/application.ex b/apps/explorer/lib/explorer/application.ex index 1fd3a6cd2e..c17a8c42af 100644 --- a/apps/explorer/lib/explorer/application.ex +++ b/apps/explorer/lib/explorer/application.ex @@ -100,6 +100,7 @@ defmodule Explorer.Application do configure(Explorer.Counters.AverageBlockTime), configure(Explorer.Counters.Bridge), configure(Explorer.Validator.MetadataProcessor), + configure(Explorer.Tags.AddressTag.Cataloger), configure(MinMissingBlockNumber) ] |> List.flatten() diff --git a/config/runtime.exs b/config/runtime.exs index 09091f0568..ceacf9cbcf 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -98,6 +98,7 @@ config :block_scout_web, max_length_to_show_string_without_trimming: System.get_env("MAX_STRING_LENGTH_WITHOUT_TRIMMING", "2040"), re_captcha_secret_key: System.get_env("RE_CAPTCHA_SECRET_KEY", nil), re_captcha_client_key: System.get_env("RE_CAPTCHA_CLIENT_KEY", nil), + new_tags: System.get_env("NEW_TAGS"), chain_id: System.get_env("CHAIN_ID"), json_rpc: System.get_env("JSON_RPC"), verification_max_libraries: verification_max_libraries