diff --git a/CHANGELOG.md b/CHANGELOG.md index caec35e102..302784ccb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixes - [#9125](https://github.com/blockscout/blockscout/pull/9125) - Fix Explorer.Chain.Cache.GasPriceOracle.merge_fees +- [#9124](https://github.com/blockscout/blockscout/pull/9124) - EIP-1167 display multiple sources of bytecode twin - [#9110](https://github.com/blockscout/blockscout/pull/9110) - Improve update_in in gas tracker - [#9109](https://github.com/blockscout/blockscout/pull/9109) - Return current exchange rate in api/v2/stats - [#9102](https://github.com/blockscout/blockscout/pull/9102) - Fix some log topics for Suave and Polygon Edge diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex index 445b7ca486..a43c5c7b2b 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex @@ -15,7 +15,7 @@ defmodule BlockScoutWeb.AddressContractController do necessity_by_association: %{ :contracts_creation_internal_transaction => :optional, :names => :optional, - :smart_contract => :optional, + [smart_contract: :smart_contract_additional_sources] => :optional, :token => :optional, :contracts_creation_transaction => :optional } diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/smart_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/smart_contract_controller.ex index 4986c3a19a..0407d01602 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/smart_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v2/smart_contract_controller.ex @@ -20,7 +20,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do @smart_contract_address_options [ necessity_by_association: %{ :contracts_creation_internal_transaction => :optional, - :smart_contract => :optional, + [smart_contract: :smart_contract_additional_sources] => :optional, :contracts_creation_transaction => :optional }, api?: true diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex index acaee3f7bd..398a90f022 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex @@ -12,7 +12,7 @@ defmodule BlockScoutWeb.SmartContractController do def index(conn, %{"hash" => address_hash_string, "type" => contract_type, "action" => action} = params) do address_options = [ necessity_by_association: %{ - :smart_contract => :optional + [smart_contract: :smart_contract_additional_sources] => :optional } ] diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/visualize_sol2uml_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/visualize_sol2uml_controller.ex index 3863fb31a8..78c4d225f3 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/visualize_sol2uml_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/visualize_sol2uml_controller.ex @@ -16,7 +16,7 @@ defmodule BlockScoutWeb.VisualizeSol2umlController do # check that contract is verified. partial and twin verification is ok for this case false <- is_nil(address.smart_contract) do sources = - address.smart_contract_additional_sources + address.smart_contract.smart_contract_additional_sources |> Enum.map(fn additional_source -> {additional_source.file_name, additional_source.contract_source_code} end) |> Enum.into(%{}) |> Map.merge(%{ diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex index 1d6776ecf0..4a052b2fa5 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex @@ -2,9 +2,8 @@ <% minimal_proxy_template = EIP1167.get_implementation_address(@address.hash) %> <% metadata_for_verification = minimal_proxy_template || SmartContract.get_address_verified_twin_contract(@address.hash).verified_contract %> <% smart_contract_verified = BlockScoutWeb.AddressView.smart_contract_verified?(@address) %> -<% additional_sources_from_twin = SmartContract.get_address_verified_twin_contract(@address.hash).additional_sources %> <% fully_verified = SmartContract.verified_with_full_match?(@address.hash)%> -<% additional_sources = if smart_contract_verified, do: @address.smart_contract_additional_sources, else: additional_sources_from_twin %> +<% additional_sources = BlockScoutWeb.API.V2.SmartContractView.additional_sources(@address.smart_contract, smart_contract_verified, minimal_proxy_template, SmartContract.get_address_verified_twin_contract(@address.hash)) %> <% visualize_sol2uml_enabled = Explorer.Visualize.Sol2uml.enabled?() %>
<% is_proxy = BlockScoutWeb.AddressView.smart_contract_is_proxy?(@address) %> diff --git a/apps/block_scout_web/lib/block_scout_web/views/api/rpc/contract_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api/rpc/contract_view.ex index bc47f2bd85..5297bf50d1 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api/rpc/contract_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api/rpc/contract_view.ex @@ -171,7 +171,7 @@ defmodule BlockScoutWeb.API.RPC.ContractView do additional_sources = if AddressView.smart_contract_verified?(address), - do: address.smart_contract_additional_sources, + do: address.smart_contract.smart_contract_additional_sources, else: additional_sources_from_twin additional_sources_array = diff --git a/apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex index 868536acfb..549ca32497 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex @@ -10,7 +10,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do alias BlockScoutWeb.{ABIEncodedValueView, AddressContractView, AddressView} alias Ecto.Changeset alias Explorer.Chain - alias Explorer.Chain.{Address, SmartContract} + alias Explorer.Chain.{Address, SmartContract, SmartContractAdditionalSource} alias Explorer.Chain.SmartContract.Proxy.EIP1167 alias Explorer.Visualize.Sol2uml @@ -136,14 +136,13 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do # credo:disable-for-next-line def prepare_smart_contract(%Address{smart_contract: %SmartContract{} = smart_contract} = address) do minimal_proxy_template = EIP1167.get_implementation_address(address.hash, @api_true) - twin = SmartContract.get_address_verified_twin_contract(address.hash, @api_true) - metadata_for_verification = minimal_proxy_template || twin.verified_contract + bytecode_twin = SmartContract.get_address_verified_twin_contract(address.hash, @api_true) + metadata_for_verification = minimal_proxy_template || bytecode_twin.verified_contract smart_contract_verified = AddressView.smart_contract_verified?(address) - additional_sources_from_twin = twin.additional_sources fully_verified = SmartContract.verified_with_full_match?(address.hash, @api_true) additional_sources = - if smart_contract_verified, do: address.smart_contract_additional_sources, else: additional_sources_from_twin + additional_sources(smart_contract, smart_contract_verified, minimal_proxy_template, bytecode_twin) visualize_sol2uml_enabled = Sol2uml.enabled?() target_contract = if smart_contract_verified, do: address.smart_contract, else: metadata_for_verification @@ -192,6 +191,26 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do bytecode_info(address) end + @doc """ + Returns additional sources of the smart-contract or from bytecode twin or from implementation, if it fits minimal proxy pattern (EIP-1167) + """ + @spec additional_sources(SmartContract.t(), boolean, SmartContract.t() | nil, %{ + :verified_contract => any(), + :additional_sources => SmartContractAdditionalSource.t() | nil + }) :: [SmartContractAdditionalSource.t()] + def additional_sources(smart_contract, smart_contract_verified, minimal_proxy_template, bytecode_twin) do + cond do + !is_nil(minimal_proxy_template) -> + minimal_proxy_template.smart_contract_additional_sources + + smart_contract_verified -> + smart_contract.smart_contract_additional_sources + + true -> + bytecode_twin.additional_sources + end + end + defp bytecode_info(address) do case AddressContractView.contract_creation_code(address) do {:selfdestructed, init} -> diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 224aa1df77..38e44c6d5c 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -336,7 +336,7 @@ msgstr "" msgid "All functions displayed below are from ABI of that contract. In order to verify current contract, proceed with" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:28 +#: lib/block_scout_web/templates/address_contract/index.html.eex:27 #, elixir-autogen, elixir-format msgid "All metadata displayed below is from that contract. In order to verify current contract, click" msgstr "" @@ -688,12 +688,12 @@ msgstr "" msgid "Compiler" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:143 +#: lib/block_scout_web/templates/address_contract/index.html.eex:142 #, elixir-autogen, elixir-format msgid "Compiler Settings" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:72 +#: lib/block_scout_web/templates/address_contract/index.html.eex:71 #, elixir-autogen, elixir-format msgid "Compiler version" msgstr "" @@ -747,7 +747,7 @@ msgstr "" msgid "Connection Lost, click to load newer validations" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:97 +#: lib/block_scout_web/templates/address_contract/index.html.eex:96 #, elixir-autogen, elixir-format msgid "Constructor Arguments" msgstr "" @@ -763,7 +763,7 @@ msgstr "" msgid "Contract" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:158 +#: lib/block_scout_web/templates/address_contract/index.html.eex:157 #, elixir-autogen, elixir-format msgid "Contract ABI" msgstr "" @@ -793,8 +793,8 @@ msgstr "" msgid "Contract Creation" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:175 -#: lib/block_scout_web/templates/address_contract/index.html.eex:190 +#: lib/block_scout_web/templates/address_contract/index.html.eex:174 +#: lib/block_scout_web/templates/address_contract/index.html.eex:189 #, elixir-autogen, elixir-format msgid "Contract Creation Code" msgstr "" @@ -811,7 +811,7 @@ msgstr "" msgid "Contract Name" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:26 +#: lib/block_scout_web/templates/address_contract/index.html.eex:25 #: lib/block_scout_web/templates/smart_contract/_functions.html.eex:11 #, elixir-autogen, elixir-format msgid "Contract is not verified. However, we found a verified contract with the same bytecode in Blockscout DB" @@ -822,12 +822,12 @@ msgstr "" msgid "Contract name or address" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:64 +#: lib/block_scout_web/templates/address_contract/index.html.eex:63 #, elixir-autogen, elixir-format msgid "Contract name:" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:107 +#: lib/block_scout_web/templates/address_contract/index.html.eex:106 #, elixir-autogen, elixir-format msgid "Contract source code" msgstr "" @@ -842,7 +842,7 @@ msgstr "" msgid "Contracts" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:181 +#: lib/block_scout_web/templates/address_contract/index.html.eex:180 #, elixir-autogen, elixir-format msgid "Contracts that self destruct in their constructors have no contract code published and cannot be verified." msgstr "" @@ -852,7 +852,7 @@ msgstr "" msgid "Contribute" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:160 +#: lib/block_scout_web/templates/address_contract/index.html.eex:159 #, elixir-autogen, elixir-format msgid "Copy ABI" msgstr "" @@ -878,7 +878,7 @@ msgstr "" msgid "Copy Address" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:145 +#: lib/block_scout_web/templates/address_contract/index.html.eex:144 #, elixir-autogen, elixir-format msgid "Copy Compiler Settings" msgstr "" @@ -889,8 +889,8 @@ msgstr "" msgid "Copy Contract Address" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:177 -#: lib/block_scout_web/templates/address_contract/index.html.eex:193 +#: lib/block_scout_web/templates/address_contract/index.html.eex:176 +#: lib/block_scout_web/templates/address_contract/index.html.eex:192 #, elixir-autogen, elixir-format msgid "Copy Contract Creation Code" msgstr "" @@ -900,8 +900,8 @@ msgstr "" msgid "Copy Decompiled Contract Code" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:214 -#: lib/block_scout_web/templates/address_contract/index.html.eex:224 +#: lib/block_scout_web/templates/address_contract/index.html.eex:213 +#: lib/block_scout_web/templates/address_contract/index.html.eex:223 #, elixir-autogen, elixir-format msgid "Copy Deployed ByteCode" msgstr "" @@ -937,8 +937,8 @@ msgstr "" msgid "Copy Raw Trace" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:121 -#: lib/block_scout_web/templates/address_contract/index.html.eex:133 +#: lib/block_scout_web/templates/address_contract/index.html.eex:120 +#: lib/block_scout_web/templates/address_contract/index.html.eex:132 #, elixir-autogen, elixir-format msgid "Copy Source Code" msgstr "" @@ -1109,8 +1109,8 @@ msgstr "" msgid "Delegate Call" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:212 -#: lib/block_scout_web/templates/address_contract/index.html.eex:220 +#: lib/block_scout_web/templates/address_contract/index.html.eex:211 +#: lib/block_scout_web/templates/address_contract/index.html.eex:219 #, elixir-autogen, elixir-format msgid "Deployed ByteCode" msgstr "" @@ -1140,7 +1140,7 @@ msgstr "" msgid "Difficulty" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:182 +#: lib/block_scout_web/templates/address_contract/index.html.eex:181 #, elixir-autogen, elixir-format msgid "Displaying the init data provided of the creating transaction." msgstr "" @@ -1216,7 +1216,7 @@ msgstr "" msgid "ETH RPC API Documentation" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:83 +#: lib/block_scout_web/templates/address_contract/index.html.eex:82 #: lib/block_scout_web/templates/address_contract_verification_via_flattened_code/new.html.eex:30 #: lib/block_scout_web/templates/address_contract_verification_via_multi_part_files/new.html.eex:22 #, elixir-autogen, elixir-format @@ -1334,7 +1334,7 @@ msgstr "" msgid "Export Data" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:249 +#: lib/block_scout_web/templates/address_contract/index.html.eex:248 #, elixir-autogen, elixir-format msgid "External libraries" msgstr "" @@ -2002,12 +2002,12 @@ msgstr "" msgid "Optimization" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:68 +#: lib/block_scout_web/templates/address_contract/index.html.eex:67 #, elixir-autogen, elixir-format msgid "Optimization enabled" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:77 +#: lib/block_scout_web/templates/address_contract/index.html.eex:76 #: lib/block_scout_web/templates/address_contract_verification_via_flattened_code/new.html.eex:62 #: lib/block_scout_web/templates/address_contract_verification_via_multi_part_files/new.html.eex:54 #, elixir-autogen, elixir-format @@ -2776,12 +2776,12 @@ msgstr "" msgid "This block has not been processed yet." msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:48 +#: lib/block_scout_web/templates/address_contract/index.html.eex:47 #, elixir-autogen, elixir-format msgid "This contract has been partially verified via Sourcify." msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:52 +#: lib/block_scout_web/templates/address_contract/index.html.eex:51 #, elixir-autogen, elixir-format msgid "This contract has been verified via Sourcify." msgstr "" @@ -3268,7 +3268,7 @@ msgstr "" msgid "Verified Contracts" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:89 +#: lib/block_scout_web/templates/address_contract/index.html.eex:88 #, elixir-autogen, elixir-format msgid "Verified at" msgstr "" @@ -3288,10 +3288,10 @@ msgstr "" msgid "Verified contracts, %{subnetwork}, %{coin}" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:28 -#: lib/block_scout_web/templates/address_contract/index.html.eex:30 -#: lib/block_scout_web/templates/address_contract/index.html.eex:198 -#: lib/block_scout_web/templates/address_contract/index.html.eex:229 +#: lib/block_scout_web/templates/address_contract/index.html.eex:27 +#: lib/block_scout_web/templates/address_contract/index.html.eex:29 +#: lib/block_scout_web/templates/address_contract/index.html.eex:197 +#: lib/block_scout_web/templates/address_contract/index.html.eex:228 #: lib/block_scout_web/templates/smart_contract/_functions.html.eex:14 #, elixir-autogen, elixir-format msgid "Verify & Publish" @@ -3541,7 +3541,7 @@ msgstr "" msgid "balance of the address" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:28 +#: lib/block_scout_web/templates/address_contract/index.html.eex:27 #, elixir-autogen, elixir-format msgid "button" 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 4d1362f4d2..328f17c090 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 @@ -336,7 +336,7 @@ msgstr "" msgid "All functions displayed below are from ABI of that contract. In order to verify current contract, proceed with" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:28 +#: lib/block_scout_web/templates/address_contract/index.html.eex:27 #, elixir-autogen, elixir-format msgid "All metadata displayed below is from that contract. In order to verify current contract, click" msgstr "" @@ -688,12 +688,12 @@ msgstr "" msgid "Compiler" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:143 +#: lib/block_scout_web/templates/address_contract/index.html.eex:142 #, elixir-autogen, elixir-format msgid "Compiler Settings" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:72 +#: lib/block_scout_web/templates/address_contract/index.html.eex:71 #, elixir-autogen, elixir-format msgid "Compiler version" msgstr "" @@ -747,7 +747,7 @@ msgstr "" msgid "Connection Lost, click to load newer validations" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:97 +#: lib/block_scout_web/templates/address_contract/index.html.eex:96 #, elixir-autogen, elixir-format msgid "Constructor Arguments" msgstr "" @@ -763,7 +763,7 @@ msgstr "" msgid "Contract" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:158 +#: lib/block_scout_web/templates/address_contract/index.html.eex:157 #, elixir-autogen, elixir-format msgid "Contract ABI" msgstr "" @@ -793,8 +793,8 @@ msgstr "" msgid "Contract Creation" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:175 -#: lib/block_scout_web/templates/address_contract/index.html.eex:190 +#: lib/block_scout_web/templates/address_contract/index.html.eex:174 +#: lib/block_scout_web/templates/address_contract/index.html.eex:189 #, elixir-autogen, elixir-format msgid "Contract Creation Code" msgstr "" @@ -811,7 +811,7 @@ msgstr "" msgid "Contract Name" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:26 +#: lib/block_scout_web/templates/address_contract/index.html.eex:25 #: lib/block_scout_web/templates/smart_contract/_functions.html.eex:11 #, elixir-autogen, elixir-format msgid "Contract is not verified. However, we found a verified contract with the same bytecode in Blockscout DB" @@ -822,12 +822,12 @@ msgstr "" msgid "Contract name or address" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:64 +#: lib/block_scout_web/templates/address_contract/index.html.eex:63 #, elixir-autogen, elixir-format msgid "Contract name:" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:107 +#: lib/block_scout_web/templates/address_contract/index.html.eex:106 #, elixir-autogen, elixir-format msgid "Contract source code" msgstr "" @@ -842,7 +842,7 @@ msgstr "" msgid "Contracts" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:181 +#: lib/block_scout_web/templates/address_contract/index.html.eex:180 #, elixir-autogen, elixir-format msgid "Contracts that self destruct in their constructors have no contract code published and cannot be verified." msgstr "" @@ -852,7 +852,7 @@ msgstr "" msgid "Contribute" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:160 +#: lib/block_scout_web/templates/address_contract/index.html.eex:159 #, elixir-autogen, elixir-format msgid "Copy ABI" msgstr "" @@ -878,7 +878,7 @@ msgstr "" msgid "Copy Address" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:145 +#: lib/block_scout_web/templates/address_contract/index.html.eex:144 #, elixir-autogen, elixir-format msgid "Copy Compiler Settings" msgstr "" @@ -889,8 +889,8 @@ msgstr "" msgid "Copy Contract Address" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:177 -#: lib/block_scout_web/templates/address_contract/index.html.eex:193 +#: lib/block_scout_web/templates/address_contract/index.html.eex:176 +#: lib/block_scout_web/templates/address_contract/index.html.eex:192 #, elixir-autogen, elixir-format msgid "Copy Contract Creation Code" msgstr "" @@ -900,8 +900,8 @@ msgstr "" msgid "Copy Decompiled Contract Code" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:214 -#: lib/block_scout_web/templates/address_contract/index.html.eex:224 +#: lib/block_scout_web/templates/address_contract/index.html.eex:213 +#: lib/block_scout_web/templates/address_contract/index.html.eex:223 #, elixir-autogen, elixir-format msgid "Copy Deployed ByteCode" msgstr "" @@ -937,8 +937,8 @@ msgstr "" msgid "Copy Raw Trace" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:121 -#: lib/block_scout_web/templates/address_contract/index.html.eex:133 +#: lib/block_scout_web/templates/address_contract/index.html.eex:120 +#: lib/block_scout_web/templates/address_contract/index.html.eex:132 #, elixir-autogen, elixir-format msgid "Copy Source Code" msgstr "" @@ -1109,8 +1109,8 @@ msgstr "" msgid "Delegate Call" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:212 -#: lib/block_scout_web/templates/address_contract/index.html.eex:220 +#: lib/block_scout_web/templates/address_contract/index.html.eex:211 +#: lib/block_scout_web/templates/address_contract/index.html.eex:219 #, elixir-autogen, elixir-format msgid "Deployed ByteCode" msgstr "" @@ -1140,7 +1140,7 @@ msgstr "" msgid "Difficulty" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:182 +#: lib/block_scout_web/templates/address_contract/index.html.eex:181 #, elixir-autogen, elixir-format msgid "Displaying the init data provided of the creating transaction." msgstr "" @@ -1216,7 +1216,7 @@ msgstr "" msgid "ETH RPC API Documentation" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:83 +#: lib/block_scout_web/templates/address_contract/index.html.eex:82 #: lib/block_scout_web/templates/address_contract_verification_via_flattened_code/new.html.eex:30 #: lib/block_scout_web/templates/address_contract_verification_via_multi_part_files/new.html.eex:22 #, elixir-autogen, elixir-format @@ -1334,7 +1334,7 @@ msgstr "" msgid "Export Data" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:249 +#: lib/block_scout_web/templates/address_contract/index.html.eex:248 #, elixir-autogen, elixir-format msgid "External libraries" msgstr "" @@ -2002,12 +2002,12 @@ msgstr "" msgid "Optimization" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:68 +#: lib/block_scout_web/templates/address_contract/index.html.eex:67 #, elixir-autogen, elixir-format msgid "Optimization enabled" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:77 +#: lib/block_scout_web/templates/address_contract/index.html.eex:76 #: lib/block_scout_web/templates/address_contract_verification_via_flattened_code/new.html.eex:62 #: lib/block_scout_web/templates/address_contract_verification_via_multi_part_files/new.html.eex:54 #, elixir-autogen, elixir-format @@ -2776,12 +2776,12 @@ msgstr "" msgid "This block has not been processed yet." msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:48 +#: lib/block_scout_web/templates/address_contract/index.html.eex:47 #, elixir-autogen, elixir-format msgid "This contract has been partially verified via Sourcify." msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:52 +#: lib/block_scout_web/templates/address_contract/index.html.eex:51 #, elixir-autogen, elixir-format msgid "This contract has been verified via Sourcify." msgstr "" @@ -3268,7 +3268,7 @@ msgstr "" msgid "Verified Contracts" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:89 +#: lib/block_scout_web/templates/address_contract/index.html.eex:88 #, elixir-autogen, elixir-format msgid "Verified at" msgstr "" @@ -3288,10 +3288,10 @@ msgstr "" msgid "Verified contracts, %{subnetwork}, %{coin}" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:28 -#: lib/block_scout_web/templates/address_contract/index.html.eex:30 -#: lib/block_scout_web/templates/address_contract/index.html.eex:198 -#: lib/block_scout_web/templates/address_contract/index.html.eex:229 +#: lib/block_scout_web/templates/address_contract/index.html.eex:27 +#: lib/block_scout_web/templates/address_contract/index.html.eex:29 +#: lib/block_scout_web/templates/address_contract/index.html.eex:197 +#: lib/block_scout_web/templates/address_contract/index.html.eex:228 #: lib/block_scout_web/templates/smart_contract/_functions.html.eex:14 #, elixir-autogen, elixir-format msgid "Verify & Publish" @@ -3541,7 +3541,7 @@ msgstr "" msgid "balance of the address" msgstr "" -#: lib/block_scout_web/templates/address_contract/index.html.eex:28 +#: lib/block_scout_web/templates/address_contract/index.html.eex:27 #, elixir-autogen, elixir-format msgid "button" msgstr "" diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index e61f9cf6ca..f5b9ea6f1a 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -1232,7 +1232,7 @@ defmodule Explorer.Chain do options |> Keyword.get(:necessity_by_association, %{}) |> Map.merge(%{ - smart_contract_additional_sources: :optional + [smart_contract: :smart_contract_additional_sources] => :optional }) query = @@ -1246,6 +1246,7 @@ defmodule Explorer.Chain do |> join_associations(necessity_by_association) |> with_decompiled_code_flag(hash, query_decompiled_code_flag) |> select_repo(options).one() + |> Repo.preload(smart_contract: :smart_contract_additional_sources) address_updated_result = case address_result do diff --git a/apps/explorer/lib/explorer/chain/address.ex b/apps/explorer/lib/explorer/chain/address.ex index 41bac5f23c..9390063859 100644 --- a/apps/explorer/lib/explorer/chain/address.ex +++ b/apps/explorer/lib/explorer/chain/address.ex @@ -19,7 +19,6 @@ defmodule Explorer.Chain.Address do Hash, InternalTransaction, SmartContract, - SmartContractAdditionalSource, Token, Transaction, Wei, @@ -77,8 +76,7 @@ defmodule Explorer.Chain.Address do :token, :contracts_creation_internal_transaction, :contracts_creation_transaction, - :names, - :smart_contract_additional_sources + :names ]} @derive {Jason.Encoder, @@ -89,8 +87,7 @@ defmodule Explorer.Chain.Address do :token, :contracts_creation_internal_transaction, :contracts_creation_transaction, - :names, - :smart_contract_additional_sources + :names ]} @primary_key {:hash, Hash.Address, autogenerate: false} @@ -125,7 +122,6 @@ defmodule Explorer.Chain.Address do has_many(:names, Address.Name, foreign_key: :address_hash) has_many(:decompiled_smart_contracts, DecompiledSmartContract, foreign_key: :address_hash) - has_many(:smart_contract_additional_sources, SmartContractAdditionalSource, foreign_key: :address_hash) has_many(:withdrawals, Withdrawal, foreign_key: :address_hash) timestamps() diff --git a/apps/explorer/lib/explorer/chain/smart_contract.ex b/apps/explorer/lib/explorer/chain/smart_contract.ex index 1d381ef92e..9a0005b2e0 100644 --- a/apps/explorer/lib/explorer/chain/smart_contract.ex +++ b/apps/explorer/lib/explorer/chain/smart_contract.ex @@ -312,6 +312,11 @@ defmodule Explorer.Chain.SmartContract do type: Hash.Address ) + has_many(:smart_contract_additional_sources, SmartContractAdditionalSource, + references: :address_hash, + foreign_key: :address_hash + ) + timestamps() end diff --git a/apps/explorer/lib/explorer/chain/smart_contract/proxy/eip_1167.ex b/apps/explorer/lib/explorer/chain/smart_contract/proxy/eip_1167.ex index 5095c6b17c..c5b000d5ab 100644 --- a/apps/explorer/lib/explorer/chain/smart_contract/proxy/eip_1167.ex +++ b/apps/explorer/lib/explorer/chain/smart_contract/proxy/eip_1167.ex @@ -3,7 +3,7 @@ defmodule Explorer.Chain.SmartContract.Proxy.EIP1167 do Module for fetching proxy implementation from https://eips.ethereum.org/EIPS/eip-1167 (Minimal Proxy Contract) """ - alias Explorer.Chain + alias Explorer.{Chain, Repo} alias Explorer.Chain.{Address, Hash, SmartContract} alias Explorer.Chain.SmartContract.Proxy @@ -54,8 +54,14 @@ defmodule Explorer.Chain.SmartContract.Proxy.EIP1167 do defp implementation_to_smart_contract(nil, _options), do: nil defp implementation_to_smart_contract(address_hash, options) do + necessity_by_association = %{ + :smart_contract_additional_sources => :optional + } + address_hash |> SmartContract.get_smart_contract_query() + |> Chain.join_associations(necessity_by_association) |> Chain.select_repo(options).one(timeout: 10_000) + |> Repo.preload([:smart_contract_additional_sources]) end end diff --git a/apps/explorer/lib/explorer/chain/smart_contract_additional_sources.ex b/apps/explorer/lib/explorer/chain/smart_contract_additional_sources.ex index bdf2581bec..87429d1833 100644 --- a/apps/explorer/lib/explorer/chain/smart_contract_additional_sources.ex +++ b/apps/explorer/lib/explorer/chain/smart_contract_additional_sources.ex @@ -15,11 +15,13 @@ defmodule Explorer.Chain.SmartContractAdditionalSource do @typedoc """ * `file_name` - the name of the Solidity file with contract code (with extension). * `contract_source_code` - the Solidity source code from the file with `file_name`. + * `address_hash` - foreign key for `smart_contract`. """ @type t :: %Explorer.Chain.SmartContractAdditionalSource{ file_name: String.t(), - contract_source_code: String.t() + contract_source_code: String.t(), + address_hash: Hash.Address.t() } schema "smart_contracts_additional_sources" do diff --git a/apps/explorer/lib/explorer/etherscan/contracts.ex b/apps/explorer/lib/explorer/etherscan/contracts.ex index de63dc05af..5cfdc0c52b 100644 --- a/apps/explorer/lib/explorer/etherscan/contracts.ex +++ b/apps/explorer/lib/explorer/etherscan/contracts.ex @@ -26,9 +26,8 @@ defmodule Explorer.Etherscan.Contracts do address -> address_with_smart_contract = Repo.replica().preload(address, [ - :smart_contract, - :decompiled_smart_contracts, - :smart_contract_additional_sources + [smart_contract: :smart_contract_additional_sources], + :decompiled_smart_contracts ]) if address_with_smart_contract.smart_contract do diff --git a/apps/explorer/test/explorer/chain/smart_contract_test.exs b/apps/explorer/test/explorer/chain/smart_contract_test.exs index f7c45251b0..273e8dcc67 100644 --- a/apps/explorer/test/explorer/chain/smart_contract_test.exs +++ b/apps/explorer/test/explorer/chain/smart_contract_test.exs @@ -581,9 +581,10 @@ defmodule Explorer.Chain.SmartContractTest do secondary_sources: secondary_sources, changed_sources: changed_sources } do - sc_before_call = Repo.get_by(Address, hash: address.hash) |> Repo.preload(:smart_contract_additional_sources) + sc_before_call = + Repo.get_by(Address, hash: address.hash) |> Repo.preload(smart_contract: :smart_contract_additional_sources) - assert sc_before_call.smart_contract_additional_sources + assert sc_before_call.smart_contract.smart_contract_additional_sources |> Enum.with_index() |> Enum.all?(fn {el, ind} -> {:ok, src} = Enum.fetch(secondary_sources, ind) @@ -595,9 +596,10 @@ defmodule Explorer.Chain.SmartContractTest do assert {:ok, %SmartContract{}} = SmartContract.update_smart_contract(%{address_hash: address.hash}, [], changed_sources) - sc_after_call = Repo.get_by(Address, hash: address.hash) |> Repo.preload(:smart_contract_additional_sources) + sc_after_call = + Repo.get_by(Address, hash: address.hash) |> Repo.preload(smart_contract: :smart_contract_additional_sources) - assert sc_after_call.smart_contract_additional_sources + assert sc_after_call.smart_contract.smart_contract_additional_sources |> Enum.with_index() |> Enum.all?(fn {el, ind} -> {:ok, src} = Enum.fetch(changed_sources, ind) diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index fb529bb074..9c6236301d 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -3083,7 +3083,7 @@ defmodule Explorer.ChainTest do :contracts_creation_internal_transaction, :contracts_creation_transaction, :token, - :smart_contract_additional_sources + [smart_contract: :smart_contract_additional_sources] ]) options = [