Return additional sources in case of bytecode twin of EIP-1167 pattern

pull/9124/head
Viktor Baranov 11 months ago
parent f5463a8cb7
commit d3d7435df1
  1. 1
      CHANGELOG.md
  2. 2
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex
  3. 2
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/smart_contract_controller.ex
  4. 2
      apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex
  5. 2
      apps/block_scout_web/lib/block_scout_web/controllers/visualize_sol2uml_controller.ex
  6. 3
      apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex
  7. 2
      apps/block_scout_web/lib/block_scout_web/views/api/rpc/contract_view.ex
  8. 29
      apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex
  9. 68
      apps/block_scout_web/priv/gettext/default.pot
  10. 68
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  11. 3
      apps/explorer/lib/explorer/chain.ex
  12. 8
      apps/explorer/lib/explorer/chain/address.ex
  13. 5
      apps/explorer/lib/explorer/chain/smart_contract.ex
  14. 8
      apps/explorer/lib/explorer/chain/smart_contract/proxy/eip_1167.ex
  15. 4
      apps/explorer/lib/explorer/chain/smart_contract_additional_sources.ex
  16. 5
      apps/explorer/lib/explorer/etherscan/contracts.ex
  17. 10
      apps/explorer/test/explorer/chain/smart_contract_test.exs
  18. 2
      apps/explorer/test/explorer/chain_test.exs

@ -7,6 +7,7 @@
### Fixes ### Fixes
- [#9125](https://github.com/blockscout/blockscout/pull/9125) - Fix Explorer.Chain.Cache.GasPriceOracle.merge_fees - [#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 - [#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 - [#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 - [#9102](https://github.com/blockscout/blockscout/pull/9102) - Fix some log topics for Suave and Polygon Edge

@ -15,7 +15,7 @@ defmodule BlockScoutWeb.AddressContractController do
necessity_by_association: %{ necessity_by_association: %{
:contracts_creation_internal_transaction => :optional, :contracts_creation_internal_transaction => :optional,
:names => :optional, :names => :optional,
:smart_contract => :optional, [smart_contract: :smart_contract_additional_sources] => :optional,
:token => :optional, :token => :optional,
:contracts_creation_transaction => :optional :contracts_creation_transaction => :optional
} }

@ -20,7 +20,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do
@smart_contract_address_options [ @smart_contract_address_options [
necessity_by_association: %{ necessity_by_association: %{
:contracts_creation_internal_transaction => :optional, :contracts_creation_internal_transaction => :optional,
:smart_contract => :optional, [smart_contract: :smart_contract_additional_sources] => :optional,
:contracts_creation_transaction => :optional :contracts_creation_transaction => :optional
}, },
api?: true api?: true

@ -12,7 +12,7 @@ defmodule BlockScoutWeb.SmartContractController do
def index(conn, %{"hash" => address_hash_string, "type" => contract_type, "action" => action} = params) do def index(conn, %{"hash" => address_hash_string, "type" => contract_type, "action" => action} = params) do
address_options = [ address_options = [
necessity_by_association: %{ necessity_by_association: %{
:smart_contract => :optional [smart_contract: :smart_contract_additional_sources] => :optional
} }
] ]

@ -16,7 +16,7 @@ defmodule BlockScoutWeb.VisualizeSol2umlController do
# check that contract is verified. partial and twin verification is ok for this case # check that contract is verified. partial and twin verification is ok for this case
false <- is_nil(address.smart_contract) do false <- is_nil(address.smart_contract) do
sources = 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.map(fn additional_source -> {additional_source.file_name, additional_source.contract_source_code} end)
|> Enum.into(%{}) |> Enum.into(%{})
|> Map.merge(%{ |> Map.merge(%{

@ -2,9 +2,8 @@
<% minimal_proxy_template = EIP1167.get_implementation_address(@address.hash) %> <% 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 %> <% 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) %> <% 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)%> <% 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?() %> <% visualize_sol2uml_enabled = Explorer.Visualize.Sol2uml.enabled?() %>
<section class="container"> <section class="container">
<% is_proxy = BlockScoutWeb.AddressView.smart_contract_is_proxy?(@address) %> <% is_proxy = BlockScoutWeb.AddressView.smart_contract_is_proxy?(@address) %>

@ -171,7 +171,7 @@ defmodule BlockScoutWeb.API.RPC.ContractView do
additional_sources = additional_sources =
if AddressView.smart_contract_verified?(address), 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 else: additional_sources_from_twin
additional_sources_array = additional_sources_array =

@ -10,7 +10,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do
alias BlockScoutWeb.{ABIEncodedValueView, AddressContractView, AddressView} alias BlockScoutWeb.{ABIEncodedValueView, AddressContractView, AddressView}
alias Ecto.Changeset alias Ecto.Changeset
alias Explorer.Chain alias Explorer.Chain
alias Explorer.Chain.{Address, SmartContract} alias Explorer.Chain.{Address, SmartContract, SmartContractAdditionalSource}
alias Explorer.Chain.SmartContract.Proxy.EIP1167 alias Explorer.Chain.SmartContract.Proxy.EIP1167
alias Explorer.Visualize.Sol2uml alias Explorer.Visualize.Sol2uml
@ -136,14 +136,13 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do
# credo:disable-for-next-line # credo:disable-for-next-line
def prepare_smart_contract(%Address{smart_contract: %SmartContract{} = smart_contract} = address) do def prepare_smart_contract(%Address{smart_contract: %SmartContract{} = smart_contract} = address) do
minimal_proxy_template = EIP1167.get_implementation_address(address.hash, @api_true) minimal_proxy_template = EIP1167.get_implementation_address(address.hash, @api_true)
twin = SmartContract.get_address_verified_twin_contract(address.hash, @api_true) bytecode_twin = SmartContract.get_address_verified_twin_contract(address.hash, @api_true)
metadata_for_verification = minimal_proxy_template || twin.verified_contract metadata_for_verification = minimal_proxy_template || bytecode_twin.verified_contract
smart_contract_verified = AddressView.smart_contract_verified?(address) 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) fully_verified = SmartContract.verified_with_full_match?(address.hash, @api_true)
additional_sources = 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?() visualize_sol2uml_enabled = Sol2uml.enabled?()
target_contract = if smart_contract_verified, do: address.smart_contract, else: metadata_for_verification 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) bytecode_info(address)
end 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 defp bytecode_info(address) do
case AddressContractView.contract_creation_code(address) do case AddressContractView.contract_creation_code(address) do
{:selfdestructed, init} -> {:selfdestructed, init} ->

@ -336,7 +336,7 @@ msgstr ""
msgid "All functions displayed below are from ABI of that contract. In order to verify current contract, proceed with" msgid "All functions displayed below are from ABI of that contract. In order to verify current contract, proceed with"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "All metadata displayed below is from that contract. In order to verify current contract, click" msgid "All metadata displayed below is from that contract. In order to verify current contract, click"
msgstr "" msgstr ""
@ -688,12 +688,12 @@ msgstr ""
msgid "Compiler" msgid "Compiler"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Compiler Settings" msgid "Compiler Settings"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Compiler version" msgid "Compiler version"
msgstr "" msgstr ""
@ -747,7 +747,7 @@ msgstr ""
msgid "Connection Lost, click to load newer validations" msgid "Connection Lost, click to load newer validations"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Constructor Arguments" msgid "Constructor Arguments"
msgstr "" msgstr ""
@ -763,7 +763,7 @@ msgstr ""
msgid "Contract" msgid "Contract"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Contract ABI" msgid "Contract ABI"
msgstr "" msgstr ""
@ -793,8 +793,8 @@ msgstr ""
msgid "Contract Creation" msgid "Contract Creation"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:175 #: lib/block_scout_web/templates/address_contract/index.html.eex:174
#: lib/block_scout_web/templates/address_contract/index.html.eex:190 #: lib/block_scout_web/templates/address_contract/index.html.eex:189
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Contract Creation Code" msgid "Contract Creation Code"
msgstr "" msgstr ""
@ -811,7 +811,7 @@ msgstr ""
msgid "Contract Name" msgid "Contract Name"
msgstr "" 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 #: lib/block_scout_web/templates/smart_contract/_functions.html.eex:11
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Contract is not verified. However, we found a verified contract with the same bytecode in Blockscout DB" 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" msgid "Contract name or address"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Contract name:" msgid "Contract name:"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Contract source code" msgid "Contract source code"
msgstr "" msgstr ""
@ -842,7 +842,7 @@ msgstr ""
msgid "Contracts" msgid "Contracts"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Contracts that self destruct in their constructors have no contract code published and cannot be verified." msgid "Contracts that self destruct in their constructors have no contract code published and cannot be verified."
msgstr "" msgstr ""
@ -852,7 +852,7 @@ msgstr ""
msgid "Contribute" msgid "Contribute"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Copy ABI" msgid "Copy ABI"
msgstr "" msgstr ""
@ -878,7 +878,7 @@ msgstr ""
msgid "Copy Address" msgid "Copy Address"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Copy Compiler Settings" msgid "Copy Compiler Settings"
msgstr "" msgstr ""
@ -889,8 +889,8 @@ msgstr ""
msgid "Copy Contract Address" msgid "Copy Contract Address"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:177 #: lib/block_scout_web/templates/address_contract/index.html.eex:176
#: lib/block_scout_web/templates/address_contract/index.html.eex:193 #: lib/block_scout_web/templates/address_contract/index.html.eex:192
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Copy Contract Creation Code" msgid "Copy Contract Creation Code"
msgstr "" msgstr ""
@ -900,8 +900,8 @@ msgstr ""
msgid "Copy Decompiled Contract Code" msgid "Copy Decompiled Contract Code"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:214 #: lib/block_scout_web/templates/address_contract/index.html.eex:213
#: lib/block_scout_web/templates/address_contract/index.html.eex:224 #: lib/block_scout_web/templates/address_contract/index.html.eex:223
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Copy Deployed ByteCode" msgid "Copy Deployed ByteCode"
msgstr "" msgstr ""
@ -937,8 +937,8 @@ msgstr ""
msgid "Copy Raw Trace" msgid "Copy Raw Trace"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:121 #: lib/block_scout_web/templates/address_contract/index.html.eex:120
#: lib/block_scout_web/templates/address_contract/index.html.eex:133 #: lib/block_scout_web/templates/address_contract/index.html.eex:132
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Copy Source Code" msgid "Copy Source Code"
msgstr "" msgstr ""
@ -1109,8 +1109,8 @@ msgstr ""
msgid "Delegate Call" msgid "Delegate Call"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:212 #: lib/block_scout_web/templates/address_contract/index.html.eex:211
#: lib/block_scout_web/templates/address_contract/index.html.eex:220 #: lib/block_scout_web/templates/address_contract/index.html.eex:219
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Deployed ByteCode" msgid "Deployed ByteCode"
msgstr "" msgstr ""
@ -1140,7 +1140,7 @@ msgstr ""
msgid "Difficulty" msgid "Difficulty"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Displaying the init data provided of the creating transaction." msgid "Displaying the init data provided of the creating transaction."
msgstr "" msgstr ""
@ -1216,7 +1216,7 @@ msgstr ""
msgid "ETH RPC API Documentation" msgid "ETH RPC API Documentation"
msgstr "" 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_flattened_code/new.html.eex:30
#: lib/block_scout_web/templates/address_contract_verification_via_multi_part_files/new.html.eex:22 #: lib/block_scout_web/templates/address_contract_verification_via_multi_part_files/new.html.eex:22
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
@ -1334,7 +1334,7 @@ msgstr ""
msgid "Export Data" msgid "Export Data"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "External libraries" msgid "External libraries"
msgstr "" msgstr ""
@ -2002,12 +2002,12 @@ msgstr ""
msgid "Optimization" msgid "Optimization"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Optimization enabled" msgid "Optimization enabled"
msgstr "" 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_flattened_code/new.html.eex:62
#: lib/block_scout_web/templates/address_contract_verification_via_multi_part_files/new.html.eex:54 #: lib/block_scout_web/templates/address_contract_verification_via_multi_part_files/new.html.eex:54
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
@ -2776,12 +2776,12 @@ msgstr ""
msgid "This block has not been processed yet." msgid "This block has not been processed yet."
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "This contract has been partially verified via Sourcify." msgid "This contract has been partially verified via Sourcify."
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "This contract has been verified via Sourcify." msgid "This contract has been verified via Sourcify."
msgstr "" msgstr ""
@ -3268,7 +3268,7 @@ msgstr ""
msgid "Verified Contracts" msgid "Verified Contracts"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Verified at" msgid "Verified at"
msgstr "" msgstr ""
@ -3288,10 +3288,10 @@ msgstr ""
msgid "Verified contracts, %{subnetwork}, %{coin}" msgid "Verified contracts, %{subnetwork}, %{coin}"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:28 #: lib/block_scout_web/templates/address_contract/index.html.eex:27
#: lib/block_scout_web/templates/address_contract/index.html.eex:30 #: lib/block_scout_web/templates/address_contract/index.html.eex:29
#: lib/block_scout_web/templates/address_contract/index.html.eex:198 #: lib/block_scout_web/templates/address_contract/index.html.eex:197
#: lib/block_scout_web/templates/address_contract/index.html.eex:229 #: lib/block_scout_web/templates/address_contract/index.html.eex:228
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:14 #: lib/block_scout_web/templates/smart_contract/_functions.html.eex:14
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Verify & Publish" msgid "Verify & Publish"
@ -3541,7 +3541,7 @@ msgstr ""
msgid "balance of the address" msgid "balance of the address"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "button" msgid "button"
msgstr "" msgstr ""

@ -336,7 +336,7 @@ msgstr ""
msgid "All functions displayed below are from ABI of that contract. In order to verify current contract, proceed with" msgid "All functions displayed below are from ABI of that contract. In order to verify current contract, proceed with"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "All metadata displayed below is from that contract. In order to verify current contract, click" msgid "All metadata displayed below is from that contract. In order to verify current contract, click"
msgstr "" msgstr ""
@ -688,12 +688,12 @@ msgstr ""
msgid "Compiler" msgid "Compiler"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Compiler Settings" msgid "Compiler Settings"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Compiler version" msgid "Compiler version"
msgstr "" msgstr ""
@ -747,7 +747,7 @@ msgstr ""
msgid "Connection Lost, click to load newer validations" msgid "Connection Lost, click to load newer validations"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Constructor Arguments" msgid "Constructor Arguments"
msgstr "" msgstr ""
@ -763,7 +763,7 @@ msgstr ""
msgid "Contract" msgid "Contract"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Contract ABI" msgid "Contract ABI"
msgstr "" msgstr ""
@ -793,8 +793,8 @@ msgstr ""
msgid "Contract Creation" msgid "Contract Creation"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:175 #: lib/block_scout_web/templates/address_contract/index.html.eex:174
#: lib/block_scout_web/templates/address_contract/index.html.eex:190 #: lib/block_scout_web/templates/address_contract/index.html.eex:189
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Contract Creation Code" msgid "Contract Creation Code"
msgstr "" msgstr ""
@ -811,7 +811,7 @@ msgstr ""
msgid "Contract Name" msgid "Contract Name"
msgstr "" 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 #: lib/block_scout_web/templates/smart_contract/_functions.html.eex:11
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Contract is not verified. However, we found a verified contract with the same bytecode in Blockscout DB" 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" msgid "Contract name or address"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Contract name:" msgid "Contract name:"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Contract source code" msgid "Contract source code"
msgstr "" msgstr ""
@ -842,7 +842,7 @@ msgstr ""
msgid "Contracts" msgid "Contracts"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Contracts that self destruct in their constructors have no contract code published and cannot be verified." msgid "Contracts that self destruct in their constructors have no contract code published and cannot be verified."
msgstr "" msgstr ""
@ -852,7 +852,7 @@ msgstr ""
msgid "Contribute" msgid "Contribute"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Copy ABI" msgid "Copy ABI"
msgstr "" msgstr ""
@ -878,7 +878,7 @@ msgstr ""
msgid "Copy Address" msgid "Copy Address"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Copy Compiler Settings" msgid "Copy Compiler Settings"
msgstr "" msgstr ""
@ -889,8 +889,8 @@ msgstr ""
msgid "Copy Contract Address" msgid "Copy Contract Address"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:177 #: lib/block_scout_web/templates/address_contract/index.html.eex:176
#: lib/block_scout_web/templates/address_contract/index.html.eex:193 #: lib/block_scout_web/templates/address_contract/index.html.eex:192
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Copy Contract Creation Code" msgid "Copy Contract Creation Code"
msgstr "" msgstr ""
@ -900,8 +900,8 @@ msgstr ""
msgid "Copy Decompiled Contract Code" msgid "Copy Decompiled Contract Code"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:214 #: lib/block_scout_web/templates/address_contract/index.html.eex:213
#: lib/block_scout_web/templates/address_contract/index.html.eex:224 #: lib/block_scout_web/templates/address_contract/index.html.eex:223
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Copy Deployed ByteCode" msgid "Copy Deployed ByteCode"
msgstr "" msgstr ""
@ -937,8 +937,8 @@ msgstr ""
msgid "Copy Raw Trace" msgid "Copy Raw Trace"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:121 #: lib/block_scout_web/templates/address_contract/index.html.eex:120
#: lib/block_scout_web/templates/address_contract/index.html.eex:133 #: lib/block_scout_web/templates/address_contract/index.html.eex:132
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Copy Source Code" msgid "Copy Source Code"
msgstr "" msgstr ""
@ -1109,8 +1109,8 @@ msgstr ""
msgid "Delegate Call" msgid "Delegate Call"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:212 #: lib/block_scout_web/templates/address_contract/index.html.eex:211
#: lib/block_scout_web/templates/address_contract/index.html.eex:220 #: lib/block_scout_web/templates/address_contract/index.html.eex:219
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Deployed ByteCode" msgid "Deployed ByteCode"
msgstr "" msgstr ""
@ -1140,7 +1140,7 @@ msgstr ""
msgid "Difficulty" msgid "Difficulty"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Displaying the init data provided of the creating transaction." msgid "Displaying the init data provided of the creating transaction."
msgstr "" msgstr ""
@ -1216,7 +1216,7 @@ msgstr ""
msgid "ETH RPC API Documentation" msgid "ETH RPC API Documentation"
msgstr "" 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_flattened_code/new.html.eex:30
#: lib/block_scout_web/templates/address_contract_verification_via_multi_part_files/new.html.eex:22 #: lib/block_scout_web/templates/address_contract_verification_via_multi_part_files/new.html.eex:22
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
@ -1334,7 +1334,7 @@ msgstr ""
msgid "Export Data" msgid "Export Data"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "External libraries" msgid "External libraries"
msgstr "" msgstr ""
@ -2002,12 +2002,12 @@ msgstr ""
msgid "Optimization" msgid "Optimization"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Optimization enabled" msgid "Optimization enabled"
msgstr "" 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_flattened_code/new.html.eex:62
#: lib/block_scout_web/templates/address_contract_verification_via_multi_part_files/new.html.eex:54 #: lib/block_scout_web/templates/address_contract_verification_via_multi_part_files/new.html.eex:54
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
@ -2776,12 +2776,12 @@ msgstr ""
msgid "This block has not been processed yet." msgid "This block has not been processed yet."
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "This contract has been partially verified via Sourcify." msgid "This contract has been partially verified via Sourcify."
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "This contract has been verified via Sourcify." msgid "This contract has been verified via Sourcify."
msgstr "" msgstr ""
@ -3268,7 +3268,7 @@ msgstr ""
msgid "Verified Contracts" msgid "Verified Contracts"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "Verified at" msgid "Verified at"
msgstr "" msgstr ""
@ -3288,10 +3288,10 @@ msgstr ""
msgid "Verified contracts, %{subnetwork}, %{coin}" msgid "Verified contracts, %{subnetwork}, %{coin}"
msgstr "" msgstr ""
#: lib/block_scout_web/templates/address_contract/index.html.eex:28 #: lib/block_scout_web/templates/address_contract/index.html.eex:27
#: lib/block_scout_web/templates/address_contract/index.html.eex:30 #: lib/block_scout_web/templates/address_contract/index.html.eex:29
#: lib/block_scout_web/templates/address_contract/index.html.eex:198 #: lib/block_scout_web/templates/address_contract/index.html.eex:197
#: lib/block_scout_web/templates/address_contract/index.html.eex:229 #: lib/block_scout_web/templates/address_contract/index.html.eex:228
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:14 #: lib/block_scout_web/templates/smart_contract/_functions.html.eex:14
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Verify & Publish" msgid "Verify & Publish"
@ -3541,7 +3541,7 @@ msgstr ""
msgid "balance of the address" msgid "balance of the address"
msgstr "" 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 #, elixir-autogen, elixir-format
msgid "button" msgid "button"
msgstr "" msgstr ""

@ -1232,7 +1232,7 @@ defmodule Explorer.Chain do
options options
|> Keyword.get(:necessity_by_association, %{}) |> Keyword.get(:necessity_by_association, %{})
|> Map.merge(%{ |> Map.merge(%{
smart_contract_additional_sources: :optional [smart_contract: :smart_contract_additional_sources] => :optional
}) })
query = query =
@ -1246,6 +1246,7 @@ defmodule Explorer.Chain do
|> join_associations(necessity_by_association) |> join_associations(necessity_by_association)
|> with_decompiled_code_flag(hash, query_decompiled_code_flag) |> with_decompiled_code_flag(hash, query_decompiled_code_flag)
|> select_repo(options).one() |> select_repo(options).one()
|> Repo.preload(smart_contract: :smart_contract_additional_sources)
address_updated_result = address_updated_result =
case address_result do case address_result do

@ -19,7 +19,6 @@ defmodule Explorer.Chain.Address do
Hash, Hash,
InternalTransaction, InternalTransaction,
SmartContract, SmartContract,
SmartContractAdditionalSource,
Token, Token,
Transaction, Transaction,
Wei, Wei,
@ -77,8 +76,7 @@ defmodule Explorer.Chain.Address do
:token, :token,
:contracts_creation_internal_transaction, :contracts_creation_internal_transaction,
:contracts_creation_transaction, :contracts_creation_transaction,
:names, :names
:smart_contract_additional_sources
]} ]}
@derive {Jason.Encoder, @derive {Jason.Encoder,
@ -89,8 +87,7 @@ defmodule Explorer.Chain.Address do
:token, :token,
:contracts_creation_internal_transaction, :contracts_creation_internal_transaction,
:contracts_creation_transaction, :contracts_creation_transaction,
:names, :names
:smart_contract_additional_sources
]} ]}
@primary_key {:hash, Hash.Address, autogenerate: false} @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(:names, Address.Name, foreign_key: :address_hash)
has_many(:decompiled_smart_contracts, DecompiledSmartContract, 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) has_many(:withdrawals, Withdrawal, foreign_key: :address_hash)
timestamps() timestamps()

@ -312,6 +312,11 @@ defmodule Explorer.Chain.SmartContract do
type: Hash.Address type: Hash.Address
) )
has_many(:smart_contract_additional_sources, SmartContractAdditionalSource,
references: :address_hash,
foreign_key: :address_hash
)
timestamps() timestamps()
end end

@ -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) 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.{Address, Hash, SmartContract}
alias Explorer.Chain.SmartContract.Proxy 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(nil, _options), do: nil
defp implementation_to_smart_contract(address_hash, options) do defp implementation_to_smart_contract(address_hash, options) do
necessity_by_association = %{
:smart_contract_additional_sources => :optional
}
address_hash address_hash
|> SmartContract.get_smart_contract_query() |> SmartContract.get_smart_contract_query()
|> Chain.join_associations(necessity_by_association)
|> Chain.select_repo(options).one(timeout: 10_000) |> Chain.select_repo(options).one(timeout: 10_000)
|> Repo.preload([:smart_contract_additional_sources])
end end
end end

@ -15,11 +15,13 @@ defmodule Explorer.Chain.SmartContractAdditionalSource do
@typedoc """ @typedoc """
* `file_name` - the name of the Solidity file with contract code (with extension). * `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`. * `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{ @type t :: %Explorer.Chain.SmartContractAdditionalSource{
file_name: String.t(), 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 schema "smart_contracts_additional_sources" do

@ -26,9 +26,8 @@ defmodule Explorer.Etherscan.Contracts do
address -> address ->
address_with_smart_contract = address_with_smart_contract =
Repo.replica().preload(address, [ Repo.replica().preload(address, [
:smart_contract, [smart_contract: :smart_contract_additional_sources],
:decompiled_smart_contracts, :decompiled_smart_contracts
:smart_contract_additional_sources
]) ])
if address_with_smart_contract.smart_contract do if address_with_smart_contract.smart_contract do

@ -581,9 +581,10 @@ defmodule Explorer.Chain.SmartContractTest do
secondary_sources: secondary_sources, secondary_sources: secondary_sources,
changed_sources: changed_sources changed_sources: changed_sources
} do } 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.with_index()
|> Enum.all?(fn {el, ind} -> |> Enum.all?(fn {el, ind} ->
{:ok, src} = Enum.fetch(secondary_sources, ind) {:ok, src} = Enum.fetch(secondary_sources, ind)
@ -595,9 +596,10 @@ defmodule Explorer.Chain.SmartContractTest do
assert {:ok, %SmartContract{}} = assert {:ok, %SmartContract{}} =
SmartContract.update_smart_contract(%{address_hash: address.hash}, [], changed_sources) 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.with_index()
|> Enum.all?(fn {el, ind} -> |> Enum.all?(fn {el, ind} ->
{:ok, src} = Enum.fetch(changed_sources, ind) {:ok, src} = Enum.fetch(changed_sources, ind)

@ -3083,7 +3083,7 @@ defmodule Explorer.ChainTest do
:contracts_creation_internal_transaction, :contracts_creation_internal_transaction,
:contracts_creation_transaction, :contracts_creation_transaction,
:token, :token,
:smart_contract_additional_sources [smart_contract: :smart_contract_additional_sources]
]) ])
options = [ options = [

Loading…
Cancel
Save