Skip to content

Commit

Permalink
Merge pull request #47 from aurora-is-near/sync-08-05
Browse files Browse the repository at this point in the history
Sync with origin
  • Loading branch information
spilin authored May 8, 2024
2 parents dd9c0d4 + 487b871 commit 4f7841d
Show file tree
Hide file tree
Showing 90 changed files with 1,875 additions and 2,012 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
alias BlockScoutWeb.API.RPC.{AddressController, Helper}
alias Explorer.Chain
alias Explorer.Chain.{Address, Hash, SmartContract}
alias Explorer.Chain.SmartContract.Proxy.Models.Implementation
alias Explorer.Chain.SmartContract.Proxy.VerificationStatus, as: ProxyVerificationStatus
alias Explorer.Chain.SmartContract.VerificationStatus
alias Explorer.Etherscan.Contracts
Expand Down Expand Up @@ -230,13 +231,13 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
api?: true
),
{:not_found, false} <- {:not_found, is_nil(smart_contract)},
implementation_updated_at <- Implementation.get_proxy_implementation_updated_at(address_hash, []),
{:time_interval, true} <-
{:time_interval,
SmartContract.check_implementation_refetch_necessity(smart_contract.implementation_fetched_at)},
{:time_interval, Implementation.check_implementation_refetch_necessity(implementation_updated_at)},
uid <- ProxyVerificationStatus.generate_uid(address_hash) do
ProxyVerificationStatus.insert_status(uid, :pending, address_hash)

SmartContract.get_implementation_address_hash(smart_contract,
Implementation.get_implementation(smart_contract,
timeout: 0,
uid: uid,
callback: &ProxyVerificationStatus.set_proxy_verification_result/2
Expand All @@ -254,7 +255,7 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
render(conn, :error, error: @restricted_access)

{:time_interval, false} ->
render(conn, :error, error: "Only one attempt in #{SmartContract.get_fresh_time_distance()}ms")
render(conn, :error, error: "Only one attempt in #{Implementation.get_fresh_time_distance()}ms")
end
end

Expand All @@ -266,9 +267,20 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
render(conn, :show, %{result: "Verification in progress"})

:pass ->
implementation_address_hashes =
Implementation.get_proxy_implementations(submission.contract_address_hash, []).address_hashes

result =
if Enum.count(implementation_address_hashes) == 1 do
implementation_address_hash = Enum.at(implementation_address_hashes, 0)

"The proxy's (#{submission.contract_address_hash}) implementation contract is found at #{implementation_address_hash} and is successfully updated."
else
"The proxy's (#{submission.contract_address_hash}) implementation contracts are found at #{inspect(implementation_address_hashes)} and they've been successfully updated."
end

render(conn, :show, %{
result:
"The proxy's (#{submission.contract_address_hash}) implementation contract is found at #{SmartContract.address_hash_to_smart_contract(submission.contract_address_hash).implementation_address_hash} and is successfully updated."
result: result
})

:fail ->
Expand Down Expand Up @@ -586,11 +598,11 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
_ = PublishHelper.check_and_verify(Hash.to_string(address_hash))

result =
case SmartContract.address_hash_to_smart_contract(address_hash) do
nil ->
case SmartContract.address_hash_to_smart_contract_with_bytecode_twin(address_hash) do
{nil, _} ->
:not_found

contract ->
{contract, _} ->
{:ok, SmartContract.preload_decompiled_smart_contract(contract)}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ defmodule BlockScoutWeb.API.V2.ImportController do
{:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)},
{:not_found, {:ok, address}} <- {:not_found, Chain.hash_to_address(address_hash, @api_true, false)},
{:already_verified, smart_contract} when is_nil(smart_contract) <-
{:already_verified, SmartContract.address_hash_to_smart_contract_without_twin(address_hash, @api_true)} do
{:already_verified, SmartContract.address_hash_to_smart_contract(address_hash, @api_true)} do
creation_tx_input = contract_creation_input(address.hash)

with {:ok, %{"sourceType" => type} = source} <-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do
alias Explorer.Chain
alias Explorer.Chain.{Address, SmartContract}
alias Explorer.Chain.SmartContract.AuditReport
alias Explorer.Chain.SmartContract.Proxy.Models.Implementation
alias Explorer.SmartContract.{Reader, Writer}
alias Explorer.SmartContract.Solidity.PublishHelper
alias Explorer.ThirdPartyIntegrations.SolidityScan
Expand Down Expand Up @@ -102,7 +103,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do
{:not_found, false} <- {:not_found, is_nil(address.smart_contract)} do
implementation_address_hash_string =
address.smart_contract
|> SmartContract.get_implementation_address_hash(@api_true)
|> Implementation.get_implementation(@api_true)
|> Tuple.to_list()
|> List.first() || burn_address_hash_string()

Expand All @@ -124,7 +125,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do
{:not_found, false} <- {:not_found, is_nil(address.smart_contract)} do
implementation_address_hash_string =
address.smart_contract
|> SmartContract.get_implementation_address_hash(@api_true)
|> Implementation.get_implementation(@api_true)
|> Tuple.to_list()
|> List.first() || burn_address_hash_string()

Expand Down Expand Up @@ -204,7 +205,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do
{:ok, false} <- AccessHelper.restricted_access?(address_hash_string, params),
{:address, {:ok, address}} <- {:address, Chain.hash_to_address(address_hash)},
{:is_smart_contract, true} <- {:is_smart_contract, Address.smart_contract?(address)},
smart_contract = SmartContract.address_hash_to_smart_contract_without_twin(address_hash, @api_true),
smart_contract = SmartContract.address_hash_to_smart_contract(address_hash, @api_true),
{:is_verified_smart_contract, true} <- {:is_verified_smart_contract, !is_nil(smart_contract)},
{:is_vyper_contract, false} <- {:is_vyper_contract, smart_contract.is_vyper_contract},
response = SolidityScan.solidityscan_request(address_hash_string),
Expand Down Expand Up @@ -304,8 +305,8 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do
defp validate_smart_contract(params, address_hash_string) do
with {:format, {:ok, address_hash}} <- {:format, Chain.string_to_address_hash(address_hash_string)},
{:ok, false} <- AccessHelper.restricted_access?(address_hash_string, params),
{:not_found, smart_contract} when not is_nil(smart_contract) <-
{:not_found, SmartContract.address_hash_to_smart_contract(address_hash, @api_true)} do
{:not_found, {smart_contract, _}} when not is_nil(smart_contract) <-
{:not_found, SmartContract.address_hash_to_smart_contract_with_bytecode_twin(address_hash, @api_true)} do
{:ok, address_hash, smart_contract}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ defmodule BlockScoutWeb.API.V2.UtilsController do
address_hash <- params["address_hash"] && Chain.string_to_address_hash(params["address_hash"]),
{:format, true} <- {:format, match?({:ok, _hash}, address_hash) || is_nil(address_hash)} do
smart_contract =
if address_hash, do: SmartContract.address_hash_to_smart_contract(elem(address_hash, 1), @api_true)
if address_hash do
{updated_smart_contract, _} =
SmartContract.address_hash_to_smart_contract_with_bytecode_twin(elem(address_hash, 1), @api_true)

updated_smart_contract
end

{decoded_input, _abi_acc, _methods_acc} =
Transaction.decoded_input_data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule BlockScoutWeb.SmartContractController do
alias BlockScoutWeb.AddressView
alias Explorer.Chain
alias Explorer.Chain.SmartContract
alias Explorer.Chain.SmartContract.Proxy.Models.Implementation
alias Explorer.SmartContract.{Reader, Writer}

import Explorer.SmartContract.Solidity.Verifier, only: [parse_boolean: 1]
Expand All @@ -27,7 +28,7 @@ defmodule BlockScoutWeb.SmartContractController do
implementation_address_hash_string =
if contract_type == "proxy" do
address.smart_contract
|> SmartContract.get_implementation_address_hash()
|> Implementation.get_implementation()
|> Tuple.to_list()
|> List.first() || burn_address_hash_string()
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule BlockScoutWeb.VisualizeSol2umlController do
if Sol2uml.enabled?() do
with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string),
{:ok, address} <- Chain.find_contract_address(address_hash, address_options, true),
# check that contract is verified. partial and twin verification is ok for this case
# check that contract is verified. partial and bytecode twin verification is ok for this case
false <- is_nil(address.smart_contract) do
sources =
address.smart_contract.smart_contract_additional_sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ defmodule BlockScoutWeb.GraphQL.Schema.Types do
field(:file_path, :string)
field(:is_vyper_contract, :boolean)
field(:is_changed_bytecode, :boolean)
field(:implementation_name, :string)
field(:implementation_address_hash, :address_hash)
field(:compiler_settings, :json)
field(:verified_via_eth_bytecode_db, :boolean)
end
Expand Down
4 changes: 2 additions & 2 deletions apps/block_scout_web/lib/block_scout_web/paging_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ defmodule BlockScoutWeb.PagingHelper do
def allowed_stability_validators_states, do: @allowed_stability_validators_states

def paging_options(%{"block_number" => block_number_string, "index" => index_string}, [:validated | _]) do
with {block_number, ""} <- Integer.parse(block_number_string),
{index, ""} <- Integer.parse(index_string) do
with {:ok, block_number} <- Helper.safe_parse_non_negative_integer(block_number_string),
{:ok, index} <- Helper.safe_parse_non_negative_integer(index_string) do
[paging_options: %{@default_paging_options | key: {block_number, index}}]
else
_ ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= if @address do %>
<%= if assigns[:show_full_hash] do %>
<%= if name = if assigns[:ignore_implementation_name], do: primary_name(@address), else: implementation_name(@address) || primary_name(@address) do %>
<%= if name = if assigns[:ignore_implementation_name], do: primary_name(@address), else: Implementation.name(@address) || primary_name(@address) do %>
<span><%= name %> |
<% end %>
<%= link to: address_path(BlockScoutWeb.Endpoint, :show, @address), "data-test": "address_hash_link", class: assigns[:class] do %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<span class="<%= if @contract do %>contract-address<% end %>" data-address-hash="<%= @address %>">
<%= if name = if assigns[:ignore_implementation_name], do: primary_name(@address), else: implementation_name(@address) || primary_name(@address) do %>
<%= if name = if assigns[:ignore_implementation_name], do: primary_name(@address), else: Implementation.name(@address) || primary_name(@address) do %>
<%= if assigns[:no_tooltip] do %>
<%= if @use_custom_tooltip == true do %>
<span><%= name %> (<%= short_hash(@address) %>...)</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<% end %>
<!-- Implementation -->
<%= if @is_proxy do %>
<% {implementation_address_, name} = SmartContract.get_implementation_address_hash(@address.smart_contract) %>
<% {implementation_address_, name} = Implementation.get_implementation(@address.smart_contract) %>
<% implementation_address = implementation_address_ || "0x0000000000000000000000000000000000000000" %>
<dl class="row">
<dt class="col-sm-4 col-md-4 col-lg-3 text-muted">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% contract_creation_code = contract_creation_code(@address) %>
<% 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 %>
<% 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 %>
<% smart_contract_verified = BlockScoutWeb.AddressView.smart_contract_verified?(@address) %>
<% fully_verified = SmartContract.verified_with_full_match?(@address.hash)%>
<% 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)) %>
<% 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)) %>
<% visualize_sol2uml_enabled = Explorer.Visualize.Sol2uml.enabled?() %>
<section class="container">
<% is_proxy = BlockScoutWeb.AddressView.smart_contract_is_proxy?(@address) %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% metadata_for_verification = if assigns[:retrying], do: nil, else: SmartContract.get_address_verified_twin_contract(@address_hash).verified_contract %>
<% metadata_for_verification = if assigns[:retrying], do: nil, else: SmartContract.get_address_verified_bytecode_twin_contract(@address_hash).verified_contract %>
<% changeset = (if assigns[:retrying], do: @changeset, else: SmartContract.merge_twin_contract_with_changeset(metadata_for_verification, @changeset)) |> SmartContract.address_to_checksum_address() %>
<% fetch_constructor_arguments_automatically = if metadata_for_verification, do: true, else: changeset.changes[:autodetect_constructor_args] || true %>
<% display_constructor_arguments_text_area = if fetch_constructor_arguments_automatically, do: "none", else: "block" %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% metadata_for_verification = if assigns[:retrying], do: nil, else: SmartContract.get_address_verified_twin_contract(@address_hash).verified_contract %>
<% metadata_for_verification = if assigns[:retrying], do: nil, else: SmartContract.get_address_verified_bytecode_twin_contract(@address_hash).verified_contract %>
<% changeset = (if assigns[:retrying], do: @changeset, else: SmartContract.merge_twin_contract_with_changeset(metadata_for_verification, @changeset)) |> SmartContract.address_to_checksum_address() %>
<section data-page="contract-verification" class="container new-smart-contract-container">
<%= render BlockScoutWeb.CommonComponentsView, "_channel_disconnected_message.html", text: gettext("Connection Lost") %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% metadata_for_verification = SmartContract.get_address_verified_twin_contract(@address_hash).verified_contract %>
<% metadata_for_verification = SmartContract.get_address_verified_bytecode_twin_contract(@address_hash).verified_contract %>
<% changeset = (if assigns[:retrying], do: @changeset, else: SmartContract.merge_twin_contract_with_changeset(metadata_for_verification, @changeset)) |> SmartContract.address_to_checksum_address() %>
<% fetch_constructor_arguments_automatically = if metadata_for_verification, do: true, else: changeset.changes[:autodetect_constructor_args] || true %>
<% display_constructor_arguments_text_area = if fetch_constructor_arguments_automatically, do: "none", else: "block" %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% metadata_for_verification = SmartContract.get_address_verified_twin_contract(@address_hash).verified_contract %>
<% metadata_for_verification = SmartContract.get_address_verified_bytecode_twin_contract(@address_hash).verified_contract %>
<% changeset = (if assigns[:retrying], do: @changeset, else: SmartContract.merge_twin_vyper_contract_with_changeset(metadata_for_verification, @changeset)) |> SmartContract.address_to_checksum_address() %>
<section data-page="contract-verification" class="container new-smart-contract-container">
<%= render BlockScoutWeb.CommonComponentsView, "_channel_disconnected_message.html", text: gettext("Connection Lost") %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% minimal_proxy_template = if assigns[:custom_abi], do: nil, else: EIP1167.get_implementation_address(@address.hash) %>
<% metadata_for_verification = if assigns[:custom_abi], do: nil, else: minimal_proxy_template || SmartContract.get_address_verified_twin_contract(@address.hash).verified_contract %>
<% minimal_proxy_template = if assigns[:custom_abi], do: nil, else: EIP1167.get_implementation_smart_contract(@address.hash) %>
<% metadata_for_verification = if assigns[:custom_abi], do: nil, else: minimal_proxy_template || SmartContract.get_address_verified_bytecode_twin_contract(@address.hash).verified_contract %>
<% smart_contract_verified = if assigns[:custom_abi], do: false, else: BlockScoutWeb.AddressView.smart_contract_verified?(@address) %>
<%= unless smart_contract_verified do %>
<%= if metadata_for_verification do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dt class="col-lg-2"> <%= gettext "Address" %> </dt>
<dd class="col-lg-10">
<h3 class="logs-hash">
<% name = implementation_name(@log.address) || primary_name(@log.address)%>
<% name = Implementation.name(@log.address) || primary_name(@log.address)%>
<%= link(
(if name, do: name <> " | "<> to_string(@log.address), else: @log.address),
to: address_path(@conn, :show, @log.address),
Expand Down
14 changes: 5 additions & 9 deletions apps/block_scout_web/lib/block_scout_web/views/address_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule BlockScoutWeb.AddressView do
alias Explorer.Chain.{Address, Hash, InternalTransaction, Log, SmartContract, Token, TokenTransfer, Transaction, Wei}
alias Explorer.Chain.Block.Reward
alias Explorer.Chain.SmartContract.Proxy
alias Explorer.Chain.SmartContract.Proxy.Models.Implementation
alias Explorer.ExchangeRates.Token, as: TokenExchangeRate
alias Explorer.SmartContract.{Helper, Writer}

Expand Down Expand Up @@ -200,20 +201,15 @@ defmodule BlockScoutWeb.AddressView do

def primary_name(%Address{names: _} = address) do
with false <- is_nil(address.contract_code),
twin <- SmartContract.get_verified_twin_contract(address),
false <- is_nil(twin) do
twin.name
bytecode_twin <- SmartContract.get_verified_bytecode_twin_contract(address),
false <- is_nil(bytecode_twin) do
bytecode_twin.name
else
_ ->
nil
end
end

def implementation_name(%Address{smart_contract: %{implementation_name: implementation_name}}),
do: implementation_name

def implementation_name(_), do: nil

def primary_validator_metadata(%Address{names: [_ | _] = address_names}) do
case Enum.find(address_names, &(&1.primary == true)) do
%Address.Name{
Expand Down Expand Up @@ -249,7 +245,7 @@ defmodule BlockScoutWeb.AddressView do
|> Base.encode64()
end

def smart_contract_verified?(%Address{smart_contract: %{metadata_from_verified_twin: true}}), do: false
def smart_contract_verified?(%Address{smart_contract: %{metadata_from_verified_bytecode_twin: true}}), do: false

def smart_contract_verified?(%Address{smart_contract: %SmartContract{}}), do: true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ defmodule BlockScoutWeb.API.RPC.ContractView do
end

defp insert_additional_sources(output, address) do
additional_sources_from_twin = SmartContract.get_address_verified_twin_contract(address.hash).additional_sources
additional_sources_from_bytecode_twin =
SmartContract.get_address_verified_bytecode_twin_contract(address.hash).additional_sources

additional_sources =
if AddressView.smart_contract_verified?(address),
do: address.smart_contract.smart_contract_additional_sources,
else: additional_sources_from_twin
else: additional_sources_from_bytecode_twin

additional_sources_array =
if additional_sources,
Expand Down
Loading

0 comments on commit 4f7841d

Please sign in to comment.