From 1e5a1a8ab11a0d6f1626f4b166f06a5f56714a24 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 27 Mar 2019 13:04:02 +0300 Subject: [PATCH] show multiple decompiled contracts --- .../index.html.eex | 29 +++++++++++-------- .../views/address_decompiled_contract_view.ex | 3 ++ apps/block_scout_web/priv/gettext/default.pot | 9 ++++-- .../priv/gettext/en/LC_MESSAGES/default.po | 9 ++++-- apps/explorer/lib/explorer/chain.ex | 10 ++++--- 5 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex index b86db16f7d..db017c1d77 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_decompiled_contract/index.html.eex @@ -6,19 +6,24 @@ <%= render BlockScoutWeb.AddressView, "_tabs.html", assigns %> -
-
-
-

<%= gettext "Decompiled contract code" %>

- -
+ <%= for {contract, _i} <- Enum.with_index(@address.decompiled_smart_contracts) do %> +
+

<%= gettext "Decompiler version" %>

-
<%= List.first(@address.decompiled_smart_contracts).decompiled_source_code %>
+
<%= contract.decompiler_version %>
-
- -
+
+
+

<%= gettext "Decompiled contract code" %>

+ +
+
+
<%= contract.decompiled_source_code %>
+
+
+ + <% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex new file mode 100644 index 0000000000..74713cdcde --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/views/address_decompiled_contract_view.ex @@ -0,0 +1,3 @@ +defmodule BlockScoutWeb.AddressDecompiledContractView do + use BlockScoutWeb, :view +end diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 9f2f47b254..a76d954431 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -1709,7 +1709,7 @@ msgid "Decompiled code" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:14 +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:19 msgid "Copy Decompiled Contract Code" msgstr "" @@ -1719,6 +1719,11 @@ msgid "Decompiled Code" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:12 +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:17 msgid "Decompiled contract code" msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:11 +msgid "Decompiler version" +msgstr "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index 55700c182a..288e7d0a6a 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -1709,7 +1709,7 @@ msgid "Decompiled code" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:14 +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:19 msgid "Copy Decompiled Contract Code" msgstr "" @@ -1719,6 +1719,11 @@ msgid "Decompiled Code" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:12 +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:17 msgid "Decompiled contract code" msgstr "" + +#, elixir-format, fuzzy +#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:11 +msgid "Decompiler version" +msgstr "" diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index e52c6c4686..c3582042f4 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -659,9 +659,10 @@ defmodule Explorer.Chain do ], where: address.hash == ^hash ) - |> with_decompiled_code_flag(hash) - query + query_with_decompiled_flag = with_decompiled_code_flag(query, hash) + + query_with_decompiled_flag |> Repo.one() |> case do nil -> {:error, :not_found} @@ -778,9 +779,10 @@ defmodule Explorer.Chain do ], where: address.hash == ^hash and not is_nil(address.contract_code) ) - |> with_decompiled_code_flag(hash) - address = Repo.one(query) + query_with_decompiled_flag = with_decompiled_code_flag(query, hash) + + address = Repo.one(query_with_decompiled_flag) if address do {:ok, address}