refactor: Refactor get_additional_sources/4 -> get_additional_sources/3 (#10046)

mf-only-health-webapp
Victor Baranov 6 months ago committed by GitHub
parent ce934ec338
commit b377ba5588
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 20
      apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex
  2. 26
      apps/block_scout_web/lib/block_scout_web/views/api/v2/smart_contract_view.ex

@ -1,9 +1,9 @@
<% contract_creation_code = contract_creation_code(@address) %>
<% minimal_proxy_template = EIP1167.get_implementation_smart_contract(@address.hash) %>
<% metadata_for_verification = minimal_proxy_template || SmartContract.get_address_verified_bytecode_twin_contract(@address.hash).verified_contract %>
<% implementation_or_bytecode_twin_contract = minimal_proxy_template || SmartContract.get_address_verified_bytecode_twin_contract(@address.hash).verified_contract %>
<% smart_contract_verified = BlockScoutWeb.AddressView.smart_contract_verified?(@address) %>
<% fully_verified = SmartContract.verified_with_full_match?(@address.hash)%>
<% additional_sources = BlockScoutWeb.API.V2.SmartContractView.get_additional_sources(@address.smart_contract, smart_contract_verified, minimal_proxy_template, SmartContract.get_address_verified_bytecode_twin_contract(@address.hash)) %>
<% additional_sources = BlockScoutWeb.API.V2.SmartContractView.get_additional_sources(@address.smart_contract, smart_contract_verified, implementation_or_bytecode_twin_contract) %>
<% visualize_sol2uml_enabled = Explorer.Visualize.Sol2uml.enabled?() %>
<section class="container">
<% is_proxy = BlockScoutWeb.AddressView.smart_contract_is_proxy?(@address) %>
@ -15,16 +15,16 @@
<div class="card-body">
<%= unless smart_contract_verified do %>
<%= if minimal_proxy_template do %>
<%= render BlockScoutWeb.CommonComponentsView, "_minimal_proxy_pattern.html", address_hash: metadata_for_verification.address_hash, conn: @conn %>
<%= render BlockScoutWeb.CommonComponentsView, "_minimal_proxy_pattern.html", address_hash: implementation_or_bytecode_twin_contract.address_hash, conn: @conn %>
<% else %>
<%= if metadata_for_verification do %>
<%= if implementation_or_bytecode_twin_contract do %>
<% path = address_verify_contract_path(@conn, :new, @address.hash) %>
<div class="mb-4">
<div style="display: inline-block;">
<%= render BlockScoutWeb.CommonComponentsView, "_info.html" %>
<span> <%= gettext("Contract is not verified. However, we found a verified contract with the same bytecode in Blockscout DB") %> <%= link(
metadata_for_verification.address_hash,
to: address_contract_path(@conn, :index, metadata_for_verification.address_hash)) %>.<br/> <%= gettext("All metadata displayed below is from that contract. In order to verify current contract, click") %> <i><%= gettext("Verify & Publish") %></i> <%= gettext("button") %></span>
implementation_or_bytecode_twin_contract.address_hash,
to: address_contract_path(@conn, :index, implementation_or_bytecode_twin_contract.address_hash)) %>.<br/> <%= gettext("All metadata displayed below is from that contract. In order to verify current contract, click") %> <i><%= gettext("Verify & Publish") %></i> <%= gettext("button") %></span>
</div>
<%= link(gettext("Verify & Publish"), to: path, class: "button button-primary button-sm float-right ml-3", "data-test": "verify_and_publish") %>
</div>
@ -40,8 +40,8 @@
</div>
<% end %>
<% end %>
<%= if smart_contract_verified || (!smart_contract_verified && metadata_for_verification) do %>
<% target_contract = if smart_contract_verified, do: @address.smart_contract, else: metadata_for_verification %>
<%= if smart_contract_verified || (!smart_contract_verified && implementation_or_bytecode_twin_contract) do %>
<% target_contract = if smart_contract_verified, do: @address.smart_contract, else: implementation_or_bytecode_twin_contract %>
<%= if @address.smart_contract && @address.smart_contract.verified_via_sourcify && @address.smart_contract.partially_verified && smart_contract_verified do %>
<div class="mb-4">
<i style="color: #f7b32b;" class="fa fa-info-circle"></i><span> <%= gettext("This contract has been partially verified via Sourcify.") %>
@ -240,8 +240,8 @@
<% end %>
</section>
<%= if smart_contract_verified || (!smart_contract_verified && metadata_for_verification) do %>
<% target_contract = if smart_contract_verified, do: @address.smart_contract, else: metadata_for_verification %>
<%= if smart_contract_verified || (!smart_contract_verified && implementation_or_bytecode_twin_contract) do %>
<% target_contract = if smart_contract_verified, do: @address.smart_contract, else: implementation_or_bytecode_twin_contract %>
<%= if target_contract.external_libraries && target_contract.external_libraries != [] do %>
<section>
<div class="d-flex justify-content-between align-items-baseline">

@ -148,7 +148,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do
def prepare_smart_contract(%Address{smart_contract: %SmartContract{} = smart_contract} = address, conn) do
bytecode_twin = SmartContract.get_address_verified_bytecode_twin_contract(address.hash, @api_true)
minimal_proxy_address_hash = address.implementation
metadata_for_verification = address.implementation || bytecode_twin.verified_contract
implementation_or_bytecode_twin_contract = address.implementation || bytecode_twin.verified_contract
smart_contract_verified = AddressView.smart_contract_verified?(address)
fully_verified = SmartContract.verified_with_full_match?(address.hash, @api_true)
write_methods? = AddressView.smart_contract_with_write_functions?(address)
@ -162,16 +162,18 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do
get_additional_sources(
smart_contract,
smart_contract_verified,
metadata_for_verification,
bytecode_twin
implementation_or_bytecode_twin_contract
)
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: implementation_or_bytecode_twin_contract
%{
"verified_twin_address_hash" =>
metadata_for_verification && Address.checksum(metadata_for_verification.address_hash),
implementation_or_bytecode_twin_contract &&
Address.checksum(implementation_or_bytecode_twin_contract.address_hash),
"is_verified" => smart_contract_verified,
"is_changed_bytecode" => smart_contract_verified && address.smart_contract.is_changed_bytecode,
"is_partially_verified" => address.smart_contract.partially_verified && smart_contract_verified,
@ -233,20 +235,18 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do
@doc """
Returns additional sources of the smart-contract or from bytecode twin or from implementation, if it fits minimal proxy pattern (EIP-1167)
"""
@spec get_additional_sources(SmartContract.t(), boolean, SmartContract.t() | nil, %{
:verified_contract => any(),
:additional_sources => SmartContractAdditionalSource.t() | nil
}) :: [SmartContractAdditionalSource.t()] | nil
def get_additional_sources(smart_contract, smart_contract_verified, minimal_proxy_template, bytecode_twin) do
@spec get_additional_sources(SmartContract.t(), boolean, SmartContract.t() | nil) ::
[SmartContractAdditionalSource.t()] | nil
def get_additional_sources(smart_contract, smart_contract_verified, implementation_or_bytecode_twin_contract) do
cond do
!is_nil(minimal_proxy_template) ->
minimal_proxy_template.smart_contract_additional_sources
!is_nil(implementation_or_bytecode_twin_contract) ->
implementation_or_bytecode_twin_contract.smart_contract_additional_sources
smart_contract_verified ->
smart_contract.smart_contract_additional_sources
true ->
bytecode_twin.additional_sources
[]
end
end

Loading…
Cancel
Save