Fix address on twin verification; Change redirect routes for verified contracts

pull/5479/head
nikitosing 3 years ago
parent fd35c5598f
commit f99610710f
  1. 6
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_controller.ex
  2. 6
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_flattened_code_controller.ex
  3. 8
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_json_controller.ex
  4. 6
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_standard_json_input_controller.ex
  5. 11
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_vyper_controller.ex
  6. 9
      apps/explorer/lib/explorer/chain/smart_contract.ex

@ -14,12 +14,12 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
def new(conn, %{"address_id" => address_hash_string}) do
if Chain.smart_contract_fully_verified?(address_hash_string) do
address_path =
address_contract_path =
conn
|> address_path(:show, address_hash_string)
|> address_contract_path(:index, address_hash_string)
|> Controller.full_path()
redirect(conn, to: address_path)
redirect(conn, to: address_contract_path)
else
changeset =
SmartContract.changeset(

@ -8,12 +8,12 @@ defmodule BlockScoutWeb.AddressContractVerificationViaFlattenedCodeController do
def new(conn, %{"address_id" => address_hash_string}) do
if Chain.smart_contract_fully_verified?(address_hash_string) do
address_path =
address_contract_path =
conn
|> address_path(:show, address_hash_string)
|> address_contract_path(:index, address_hash_string)
|> Controller.full_path()
redirect(conn, to: address_path)
redirect(conn, to: address_contract_path)
else
changeset =
SmartContract.changeset(

@ -8,18 +8,18 @@ defmodule BlockScoutWeb.AddressContractVerificationViaJsonController do
alias Explorer.ThirdPartyIntegrations.Sourcify
def new(conn, %{"address_id" => address_hash_string}) do
address_path =
address_contract_path =
conn
|> address_path(:show, address_hash_string)
|> address_contract_path(:index, address_hash_string)
|> Controller.full_path()
if Chain.smart_contract_fully_verified?(address_hash_string) do
redirect(conn, to: address_path)
redirect(conn, to: address_contract_path)
else
case Sourcify.check_by_address(address_hash_string) do
{:ok, _verified_status} ->
VerificationController.get_metadata_and_publish(address_hash_string, conn)
redirect(conn, to: address_path)
redirect(conn, to: address_contract_path)
_ ->
changeset =

@ -8,12 +8,12 @@ defmodule BlockScoutWeb.AddressContractVerificationViaStandardJsonInputControlle
def new(conn, %{"address_id" => address_hash_string}) do
if Chain.smart_contract_fully_verified?(address_hash_string) do
address_path =
address_contract_path =
conn
|> address_path(:show, address_hash_string)
|> address_contract_path(:index, address_hash_string)
|> Controller.full_path()
redirect(conn, to: address_path)
redirect(conn, to: address_contract_path)
else
changeset =
SmartContract.changeset(

@ -1,10 +1,20 @@
defmodule BlockScoutWeb.AddressContractVerificationVyperController do
use BlockScoutWeb, :controller
alias BlockScoutWeb.Controller
alias Explorer.Chain
alias Explorer.Chain.SmartContract
alias Explorer.SmartContract.{CompilerVersion, Vyper.PublisherWorker}
def new(conn, %{"address_id" => address_hash_string}) do
if Chain.smart_contract_fully_verified?(address_hash_string) do
address_contract_path =
conn
|> address_contract_path(:index, address_hash_string)
|> Controller.full_path()
redirect(conn, to: address_contract_path)
else
changeset =
SmartContract.changeset(
%SmartContract{address_hash: address_hash_string},
@ -26,6 +36,7 @@ defmodule BlockScoutWeb.AddressContractVerificationVyperController do
address_hash: address_hash_string
)
end
end
def create(
conn,

@ -423,10 +423,11 @@ defmodule Explorer.Chain.SmartContract do
defp select_error_field(:name), do: :name
defp select_error_field(_), do: :contract_source_code
def merge_twin_contract_with_changeset(%__MODULE__{} = twin_contract, %Changeset{} = _changeset) do
def merge_twin_contract_with_changeset(%__MODULE__{} = twin_contract, %Changeset{} = changeset) do
%__MODULE__{}
|> changeset(Map.from_struct(twin_contract))
|> Changeset.put_change(:autodetect_constructor_args, true)
|> Changeset.force_change(:address_hash, Changeset.get_field(changeset, :address_hash))
end
def merge_twin_contract_with_changeset(nil, %Changeset{} = changeset) do
@ -442,9 +443,11 @@ defmodule Explorer.Chain.SmartContract do
def merge_twin_vyper_contract_with_changeset(
%__MODULE__{is_vyper_contract: true} = twin_contract,
%Changeset{} = _changeset
%Changeset{} = changeset
) do
changeset(twin_contract, %{})
twin_contract
|> changeset(%{})
|> Changeset.force_change(:address_hash, Changeset.get_field(changeset, :address_hash))
end
def merge_twin_vyper_contract_with_changeset(%__MODULE__{is_vyper_contract: false}, %Changeset{} = changeset) do

Loading…
Cancel
Save