From f99610710fa1cb7f116762db020bb2937d070a84 Mon Sep 17 00:00:00 2001 From: nikitosing Date: Thu, 19 May 2022 12:51:25 +0300 Subject: [PATCH] Fix address on twin verification; Change redirect routes for verified contracts --- ...ddress_contract_verification_controller.ex | 6 +-- ...ification_via_flattened_code_controller.ex | 6 +-- ...ntract_verification_via_json_controller.ex | 8 +-- ...tion_via_standard_json_input_controller.ex | 6 +-- ..._contract_verification_vyper_controller.ex | 49 ++++++++++++------- .../lib/explorer/chain/smart_contract.ex | 9 ++-- 6 files changed, 49 insertions(+), 35 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_controller.ex index 524a81d336..3658f4de66 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_controller.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( diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_flattened_code_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_flattened_code_controller.ex index e36ef050f5..2da0424b8f 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_flattened_code_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_flattened_code_controller.ex @@ -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( diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_json_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_json_controller.ex index 069afb94e0..4b29a66f7b 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_json_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_json_controller.ex @@ -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 = diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_standard_json_input_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_standard_json_input_controller.ex index cfb78d50ce..1938269f79 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_standard_json_input_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_standard_json_input_controller.ex @@ -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( diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_vyper_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_vyper_controller.ex index f1cb3832e2..6490e94540 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_vyper_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_vyper_controller.ex @@ -1,30 +1,41 @@ 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 - changeset = - SmartContract.changeset( - %SmartContract{address_hash: address_hash_string}, - %{} + 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}, + %{} + ) + + compiler_versions = + case CompilerVersion.fetch_versions(:vyper) do + {:ok, compiler_versions} -> + compiler_versions + + {:error, _} -> + [] + end + + render(conn, "new.html", + changeset: changeset, + compiler_versions: compiler_versions, + address_hash: address_hash_string ) - - compiler_versions = - case CompilerVersion.fetch_versions(:vyper) do - {:ok, compiler_versions} -> - compiler_versions - - {:error, _} -> - [] - end - - render(conn, "new.html", - changeset: changeset, - compiler_versions: compiler_versions, - address_hash: address_hash_string - ) + end end def create( diff --git a/apps/explorer/lib/explorer/chain/smart_contract.ex b/apps/explorer/lib/explorer/chain/smart_contract.ex index 354e64a598..acfda6a23d 100644 --- a/apps/explorer/lib/explorer/chain/smart_contract.ex +++ b/apps/explorer/lib/explorer/chain/smart_contract.ex @@ -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