From 8e460713a7fc3452868fa6087d8e8df07b370318 Mon Sep 17 00:00:00 2001 From: nikitosing Date: Wed, 16 Jun 2021 12:42:40 +0700 Subject: [PATCH 1/2] added check in web if a contract already verified --- ...ddress_contract_verification_controller.ex | 40 +++++++++-------- ...ification_via_flattened_code_controller.ex | 45 ++++++++++--------- ...ntract_verification_via_json_controller.ex | 27 ++++++----- 3 files changed, 63 insertions(+), 49 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 19b1ec75e7..89087c2e47 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 @@ -10,27 +10,31 @@ defmodule BlockScoutWeb.AddressContractVerificationController do alias Explorer.ThirdPartyIntegrations.Sourcify def new(conn, %{"address_id" => address_hash_string}) do - changeset = - SmartContract.changeset( - %SmartContract{address_hash: address_hash_string}, - %{} - ) + if Chain.smart_contract_verified?(address_hash_string) do + redirect(conn, to: address_path(conn, :show, address_hash_string)) + else + changeset = + SmartContract.changeset( + %SmartContract{address_hash: address_hash_string}, + %{} + ) - compiler_versions = - case CompilerVersion.fetch_versions() do - {:ok, compiler_versions} -> - compiler_versions + compiler_versions = + case CompilerVersion.fetch_versions() do + {:ok, compiler_versions} -> + compiler_versions - {:error, _} -> - [] - end + {:error, _} -> + [] + end - render(conn, "new.html", - changeset: changeset, - compiler_versions: compiler_versions, - evm_versions: CodeCompiler.allowed_evm_versions(), - address_hash: address_hash_string - ) + render(conn, "new.html", + changeset: changeset, + compiler_versions: compiler_versions, + evm_versions: CodeCompiler.allowed_evm_versions(), + address_hash: address_hash_string + ) + end end def create( 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 239e986919..051793d7d4 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 @@ -1,31 +1,36 @@ defmodule BlockScoutWeb.AddressContractVerificationViaFlattenedCodeController do use BlockScoutWeb, :controller + alias Explorer.Chain alias Explorer.Chain.SmartContract alias Explorer.SmartContract.{PublisherWorker, Solidity.CodeCompiler, Solidity.CompilerVersion} def new(conn, %{"address_id" => address_hash_string}) do - changeset = - SmartContract.changeset( - %SmartContract{address_hash: address_hash_string}, - %{} + if Chain.smart_contract_verified?(address_hash_string) do + redirect(conn, to: address_path(conn, :show, address_hash_string)) + else + changeset = + SmartContract.changeset( + %SmartContract{address_hash: address_hash_string}, + %{} + ) + + compiler_versions = + case CompilerVersion.fetch_versions() do + {:ok, compiler_versions} -> + compiler_versions + + {:error, _} -> + [] + end + + render(conn, "new.html", + changeset: changeset, + compiler_versions: compiler_versions, + evm_versions: CodeCompiler.allowed_evm_versions(), + address_hash: address_hash_string ) - - compiler_versions = - case CompilerVersion.fetch_versions() do - {:ok, compiler_versions} -> - compiler_versions - - {:error, _} -> - [] - end - - render(conn, "new.html", - changeset: changeset, - compiler_versions: compiler_versions, - evm_versions: CodeCompiler.allowed_evm_versions(), - address_hash: address_hash_string - ) + end end def create( 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 b5dcb694ed..d4ad1d86ea 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 @@ -2,23 +2,28 @@ defmodule BlockScoutWeb.AddressContractVerificationViaJsonController do use BlockScoutWeb, :controller alias BlockScoutWeb.AddressContractVerificationController, as: VerificationController + alias Explorer.Chain alias Explorer.Chain.SmartContract alias Explorer.ThirdPartyIntegrations.Sourcify def new(conn, %{"address_id" => address_hash_string}) do - 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(conn, :show, address_hash_string)) + if Chain.smart_contract_verified?(address_hash_string) do + redirect(conn, to: address_path(conn, :show, address_hash_string)) + 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(conn, :show, address_hash_string)) - _ -> - changeset = - SmartContract.changeset( - %SmartContract{address_hash: address_hash_string}, - %{} - ) + _ -> + changeset = + SmartContract.changeset( + %SmartContract{address_hash: address_hash_string}, + %{} + ) - render(conn, "new.html", changeset: changeset, address_hash: address_hash_string) + render(conn, "new.html", changeset: changeset, address_hash: address_hash_string) + end end end end From e410a6dd877c706efeb8f33217d3cf907472264b Mon Sep 17 00:00:00 2001 From: nikitosing Date: Wed, 16 Jun 2021 13:12:18 +0700 Subject: [PATCH 2/2] CHANGELOG.MD --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08b9b9fde3..b1280aa0da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - [#4067](https://github.com/blockscout/blockscout/pull/4067) - Display LP tokens USD value and custom metadata in tokens dropdown at address page ### Fixes +- [#4294](https://github.com/blockscout/blockscout/pull/4294) - User wont be able to open verification pages for verified smart-contract - [#4240](https://github.com/blockscout/blockscout/pull/4240) - `[]` is accepted in write contract page - [#4236](https://github.com/blockscout/blockscout/pull/4236), [#4242](https://github.com/blockscout/blockscout/pull/4242) - Fix typo, constructor instead of contructor - [#4167](https://github.com/blockscout/blockscout/pull/4167) - Deduplicate block numbers in acquire_blocks function