added check in web if a contract already verified

pull/4294/head
nikitosing 3 years ago
parent 84a8357099
commit 8e460713a7
  1. 40
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_controller.ex
  2. 45
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_flattened_code_controller.ex
  3. 27
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_json_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(

@ -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(

@ -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

Loading…
Cancel
Save