diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_tabs.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_tabs.html.eex
index 0c978b83e7..6f904e34e4 100644
--- a/apps/block_scout_web/lib/block_scout_web/templates/address/_tabs.html.eex
+++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_tabs.html.eex
@@ -58,10 +58,10 @@
<% end %>
- <%= if @address.has_decompiled_code? do %>
+ <%= if has_decompiled_code?(@address) do %>
<%= link(
- to: address_contract_path(@conn, :index, @address.hash),
+ to: address_decompiled_contract_path(@conn, :index, @address.hash),
class: "nav-link #{tab_status("contracts", @conn.request_path)}") do %>
<%= gettext("Decompiled code") %>
<% end %>
@@ -125,6 +125,14 @@
<%= if smart_contract_verified?(@address) do %>
<% end %>
+
+ <%= if has_decompiled_code?(@address) do %>
+ <%= link(
+ to: address_decompiled_contract_path(@conn, :index, @address.hash),
+ class: "nav-link #{tab_status("contracts", @conn.request_path)}") do %>
+ <%= gettext("Decompiled code") %>
+ <% end %>
+ <% end %>
<% end %>
<% end %>
<%= if smart_contract_with_read_only_functions?(@address) do %>
diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_view.ex
index fe6245ec54..0c7a21cac3 100644
--- a/apps/block_scout_web/lib/block_scout_web/views/address_view.ex
+++ b/apps/block_scout_web/lib/block_scout_web/views/address_view.ex
@@ -16,6 +16,7 @@ defmodule BlockScoutWeb.AddressView do
@tabs [
"coin_balances",
"contracts",
+ "decompiled_contracts",
"internal_transactions",
"read_contract",
"tokens",
@@ -205,6 +206,11 @@ defmodule BlockScoutWeb.AddressView do
def smart_contract_with_read_only_functions?(%Address{smart_contract: nil}), do: false
+ def has_decompiled_code?(address) do
+ address.has_decompiled_code? ||
+ (Ecto.assoc_loaded?(address.decompiled_smart_contracts) && Enum.count(address.decompiled_smart_contracts) > 0)
+ end
+
def token_title(%Token{name: nil, contract_address_hash: contract_address_hash}) do
contract_address_hash
|> to_string
@@ -288,6 +294,7 @@ defmodule BlockScoutWeb.AddressView do
defp tab_name(["transactions"]), do: gettext("Transactions")
defp tab_name(["internal_transactions"]), do: gettext("Internal Transactions")
defp tab_name(["contracts"]), do: gettext("Code")
+ defp tab_name(["decompiled_contracts"]), do: gettext("Decompiled Code")
defp tab_name(["read_contract"]), do: gettext("Read Contract")
defp tab_name(["coin_balances"]), do: gettext("Coin Balance History")
defp tab_name(["validations"]), do: gettext("Blocks Validated")
diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex
index b3b1e436f9..e52c6c4686 100644
--- a/apps/explorer/lib/explorer/chain.ex
+++ b/apps/explorer/lib/explorer/chain.ex
@@ -647,17 +647,9 @@ defmodule Explorer.Chain do
"""
@spec hash_to_address(Hash.Address.t()) :: {:ok, Address.t()} | {:error, :not_found}
def hash_to_address(%Hash{byte_count: unquote(Hash.Address.byte_count())} = hash) do
- has_decompiled_code_query =
- from(decompiled_contract in DecompiledSmartContract,
- where: decompiled_contract.address_hash == ^hash,
- limit: 1,
- select: %{has_decompiled_code?: not is_nil(decompiled_contract.address_hash)}
- )
-
query =
from(
address in Address,
- left_join: decompiled_code in subquery(has_decompiled_code_query),
preload: [
:contracts_creation_internal_transaction,
:names,
@@ -665,9 +657,9 @@ defmodule Explorer.Chain do
:token,
:contracts_creation_transaction
],
- where: address.hash == ^hash,
- select_merge: %{has_decompiled_code?: decompiled_code.has_decompiled_code?}
+ where: address.hash == ^hash
)
+ |> with_decompiled_code_flag(hash)
query
|> Repo.one()
@@ -786,6 +778,7 @@ defmodule Explorer.Chain do
],
where: address.hash == ^hash and not is_nil(address.contract_code)
)
+ |> with_decompiled_code_flag(hash)
address = Repo.one(query)
@@ -804,6 +797,7 @@ defmodule Explorer.Chain do
preload: [
:contracts_creation_internal_transaction,
:names,
+ :smart_contract,
:token,
:contracts_creation_transaction,
:decompiled_smart_contracts
@@ -2682,4 +2676,19 @@ defmodule Explorer.Chain do
value
end
+
+ defp with_decompiled_code_flag(query, hash) do
+ has_decompiled_code_query =
+ from(decompiled_contract in DecompiledSmartContract,
+ where: decompiled_contract.address_hash == ^hash,
+ limit: 1,
+ select: %{has_decompiled_code?: not is_nil(decompiled_contract.address_hash)}
+ )
+
+ from(
+ address in query,
+ left_join: decompiled_code in subquery(has_decompiled_code_query),
+ select_merge: %{has_decompiled_code?: decompiled_code.has_decompiled_code?}
+ )
+ end
end