From 6829890875b1916279f377d09f5523185cb96296 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Mon, 2 Nov 2020 22:31:32 +0300 Subject: [PATCH] Functions to support GnosisSafe link --- CHANGELOG.md | 1 + .../lib/block_scout_web/views/address_view.ex | 10 ++++--- apps/block_scout_web/priv/gettext/default.pot | 26 +++++++++---------- .../priv/gettext/en/LC_MESSAGES/default.po | 26 +++++++++---------- apps/explorer/lib/explorer/chain.ex | 14 ++++++++-- 5 files changed, 46 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12d69f97ed..950ae1d468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ - [#3335](https://github.com/poanetwork/blockscout/pull/3335) - MarketCap calculation: check that ETS tables exist before inserting new data or lookup from the table ### Chore +- [#3421](https://github.com/poanetwork/blockscout/pull/3421) - Functions to enable GnosisSafe app link - [#3414](https://github.com/poanetwork/blockscout/pull/3414) - Manage lis of other explorers in the footer via env var - [#3407](https://github.com/poanetwork/blockscout/pull/3407) - Add EthereumJSONRPC.HTTP.HTTPoison.json_rpc function clause when URL is null - [#3405](https://github.com/poanetwork/blockscout/pull/3405) - N/A instead of 0 for market cap if it is not fetched 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 0d77a14009..c8508c592d 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 @@ -294,9 +294,7 @@ defmodule BlockScoutWeb.AddressView do address.contracts_creation_transaction.from_address_hash end - def from_address_hash(_address) do - nil - end + def from_address_hash(_address), do: nil def address_link_to_other_explorer(link, address, full) do if full do @@ -383,4 +381,10 @@ defmodule BlockScoutWeb.AddressView do true -> "#{to_string(address)}" end end + + def smart_contract_is_gnosis_safe_proxy?(%Address{smart_contract: %SmartContract{}} = address) do + address.smart_contract.name == "GnosisSafeProxy" && Chain.gnosis_safe_contract?(address.smart_contract.abi) + end + + def smart_contract_is_gnosis_safe_proxy?(_address), do: false end diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index ffc1efb150..8b5671d160 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -899,7 +899,7 @@ msgstr "" #: lib/block_scout_web/templates/tokens/transfer/index.html.eex:14 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:4 #: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 -#: lib/block_scout_web/views/address_view.ex:350 +#: lib/block_scout_web/views/address_view.ex:348 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:119 #: lib/block_scout_web/views/tokens/overview_view.ex:40 #: lib/block_scout_web/views/transaction_view.ex:395 @@ -1798,7 +1798,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:46 #: lib/block_scout_web/templates/address_validation/index.html.eex:13 -#: lib/block_scout_web/views/address_view.ex:358 +#: lib/block_scout_web/views/address_view.ex:356 msgid "Blocks Validated" msgstr "" @@ -1808,18 +1808,18 @@ msgstr "" #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187 #: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:126 #: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:149 -#: lib/block_scout_web/views/address_view.ex:351 +#: lib/block_scout_web/views/address_view.ex:349 msgid "Code" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:32 -#: lib/block_scout_web/views/address_view.ex:357 +#: lib/block_scout_web/views/address_view.ex:355 msgid "Coin Balance History" msgstr "" #, elixir-format -#: lib/block_scout_web/views/address_view.ex:352 +#: lib/block_scout_web/views/address_view.ex:350 msgid "Decompiled Code" msgstr "" @@ -1828,7 +1828,7 @@ msgstr "" #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:19 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:11 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 -#: lib/block_scout_web/views/address_view.ex:348 +#: lib/block_scout_web/views/address_view.ex:346 #: lib/block_scout_web/views/transaction_view.ex:396 msgid "Internal Transactions" msgstr "" @@ -1838,7 +1838,7 @@ msgstr "" #: lib/block_scout_web/templates/address_logs/index.html.eex:8 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: lib/block_scout_web/templates/transaction_log/index.html.eex:8 -#: lib/block_scout_web/views/address_view.ex:359 +#: lib/block_scout_web/views/address_view.ex:357 #: lib/block_scout_web/views/transaction_view.ex:397 msgid "Logs" msgstr "" @@ -1846,7 +1846,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:79 #: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:25 -#: lib/block_scout_web/views/address_view.ex:353 +#: lib/block_scout_web/views/address_view.ex:351 #: lib/block_scout_web/views/tokens/overview_view.ex:42 msgid "Read Contract" msgstr "" @@ -1858,7 +1858,7 @@ msgstr "" #: lib/block_scout_web/templates/layout/_topnav.html.eex:87 #: lib/block_scout_web/templates/layout/_topnav.html.eex:108 #: lib/block_scout_web/templates/tokens/index.html.eex:4 -#: lib/block_scout_web/views/address_view.ex:347 +#: lib/block_scout_web/views/address_view.ex:345 msgid "Tokens" msgstr "" @@ -1869,7 +1869,7 @@ msgstr "" #: lib/block_scout_web/templates/block_transaction/index.html.eex:18 #: lib/block_scout_web/templates/chain/show.html.eex:238 #: lib/block_scout_web/templates/layout/_topnav.html.eex:53 -#: lib/block_scout_web/views/address_view.ex:349 +#: lib/block_scout_web/views/address_view.ex:347 msgid "Transactions" msgstr "" @@ -1909,13 +1909,13 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:86 -#: lib/block_scout_web/views/address_view.ex:354 +#: lib/block_scout_web/views/address_view.ex:352 msgid "Read Proxy" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:93 -#: lib/block_scout_web/views/address_view.ex:355 +#: lib/block_scout_web/views/address_view.ex:353 msgid "Write Contract" msgstr "" @@ -1932,7 +1932,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:100 -#: lib/block_scout_web/views/address_view.ex:356 +#: lib/block_scout_web/views/address_view.ex:354 msgid "Write Proxy" 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 ffc1efb150..8b5671d160 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 @@ -899,7 +899,7 @@ msgstr "" #: lib/block_scout_web/templates/tokens/transfer/index.html.eex:14 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:4 #: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 -#: lib/block_scout_web/views/address_view.ex:350 +#: lib/block_scout_web/views/address_view.ex:348 #: lib/block_scout_web/views/tokens/instance/overview_view.ex:119 #: lib/block_scout_web/views/tokens/overview_view.ex:40 #: lib/block_scout_web/views/transaction_view.ex:395 @@ -1798,7 +1798,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:46 #: lib/block_scout_web/templates/address_validation/index.html.eex:13 -#: lib/block_scout_web/views/address_view.ex:358 +#: lib/block_scout_web/views/address_view.ex:356 msgid "Blocks Validated" msgstr "" @@ -1808,18 +1808,18 @@ msgstr "" #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:187 #: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:126 #: lib/block_scout_web/templates/api_docs/_eth_rpc_item.html.eex:149 -#: lib/block_scout_web/views/address_view.ex:351 +#: lib/block_scout_web/views/address_view.ex:349 msgid "Code" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:32 -#: lib/block_scout_web/views/address_view.ex:357 +#: lib/block_scout_web/views/address_view.ex:355 msgid "Coin Balance History" msgstr "" #, elixir-format -#: lib/block_scout_web/views/address_view.ex:352 +#: lib/block_scout_web/views/address_view.ex:350 msgid "Decompiled Code" msgstr "" @@ -1828,7 +1828,7 @@ msgstr "" #: lib/block_scout_web/templates/address_internal_transaction/index.html.eex:19 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:11 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 -#: lib/block_scout_web/views/address_view.ex:348 +#: lib/block_scout_web/views/address_view.ex:346 #: lib/block_scout_web/views/transaction_view.ex:396 msgid "Internal Transactions" msgstr "" @@ -1838,7 +1838,7 @@ msgstr "" #: lib/block_scout_web/templates/address_logs/index.html.eex:8 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: lib/block_scout_web/templates/transaction_log/index.html.eex:8 -#: lib/block_scout_web/views/address_view.ex:359 +#: lib/block_scout_web/views/address_view.ex:357 #: lib/block_scout_web/views/transaction_view.ex:397 msgid "Logs" msgstr "" @@ -1846,7 +1846,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:79 #: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:25 -#: lib/block_scout_web/views/address_view.ex:353 +#: lib/block_scout_web/views/address_view.ex:351 #: lib/block_scout_web/views/tokens/overview_view.ex:42 msgid "Read Contract" msgstr "" @@ -1858,7 +1858,7 @@ msgstr "" #: lib/block_scout_web/templates/layout/_topnav.html.eex:87 #: lib/block_scout_web/templates/layout/_topnav.html.eex:108 #: lib/block_scout_web/templates/tokens/index.html.eex:4 -#: lib/block_scout_web/views/address_view.ex:347 +#: lib/block_scout_web/views/address_view.ex:345 msgid "Tokens" msgstr "" @@ -1869,7 +1869,7 @@ msgstr "" #: lib/block_scout_web/templates/block_transaction/index.html.eex:18 #: lib/block_scout_web/templates/chain/show.html.eex:238 #: lib/block_scout_web/templates/layout/_topnav.html.eex:53 -#: lib/block_scout_web/views/address_view.ex:349 +#: lib/block_scout_web/views/address_view.ex:347 msgid "Transactions" msgstr "" @@ -1909,13 +1909,13 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:86 -#: lib/block_scout_web/views/address_view.ex:354 +#: lib/block_scout_web/views/address_view.ex:352 msgid "Read Proxy" msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:93 -#: lib/block_scout_web/views/address_view.ex:355 +#: lib/block_scout_web/views/address_view.ex:353 msgid "Write Contract" msgstr "" @@ -1932,7 +1932,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/_tabs.html.eex:100 -#: lib/block_scout_web/views/address_view.ex:356 +#: lib/block_scout_web/views/address_view.ex:354 msgid "Write Proxy" msgstr "" diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index d6987e769c..b7835abdd4 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -5326,10 +5326,20 @@ defmodule Explorer.Chain do if implementation_method_abi, do: true, else: false end - def proxy_contract?(abi) when is_nil(abi) do - false + def proxy_contract?(abi) when is_nil(abi), do: false + + def gnosis_safe_contract?(abi) when not is_nil(abi) do + implementation_method_abi = + abi + |> Enum.find(fn method -> + master_copy_pattern?(method) + end) + + if implementation_method_abi, do: true, else: false end + def gnosis_safe_contract?(abi) when is_nil(abi), do: false + def get_implementation_address_hash(proxy_address_hash, abi) when not is_nil(proxy_address_hash) and not is_nil(abi) do implementation_method_abi =