Merge pull request #4294 from blockscout/np-contract-verification-fix

Аdded check in web if a contract already verified
pull/4295/head
Victor Baranov 4 years ago committed by GitHub
commit 9b8432789f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 40
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_controller.ex
  3. 45
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_flattened_code_controller.ex
  4. 27
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_via_json_controller.ex

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

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