API v2 smart-contract verification extended logging

pull/8012/head
Viktor Baranov 1 year ago
parent c763e00413
commit 3cc171fcc1
  1. 4
      .dialyzer-ignore
  2. 1
      CHANGELOG.md
  3. 137
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/fallback_controller.ex
  4. 41
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/verification_controller.ex
  5. 19
      apps/block_scout_web/lib/block_scout_web/notifier.ex
  6. 10
      apps/block_scout_web/test/block_scout_web/controllers/api/v2/verification_controller_test.exs
  7. 47
      apps/explorer/lib/explorer/chain/smart_contract.ex
  8. 14
      apps/explorer/lib/explorer/smart_contract/solidity/publisher.ex
  9. 4
      apps/explorer/lib/explorer/smart_contract/solidity/publisher_worker.ex
  10. 5
      apps/explorer/lib/explorer/smart_contract/vyper/publisher.ex
  11. 4
      apps/explorer/lib/explorer/smart_contract/vyper/publisher_worker.ex

@ -6,8 +6,8 @@
lib/ethereum_jsonrpc/rolling_window.ex:171
lib/explorer/smart_contract/solidity/publisher_worker.ex:1
lib/explorer/smart_contract/vyper/publisher_worker.ex:1
lib/explorer/smart_contract/solidity/publisher_worker.ex:6
lib/explorer/smart_contract/vyper/publisher_worker.ex:6
lib/explorer/smart_contract/solidity/publisher_worker.ex:8
lib/explorer/smart_contract/vyper/publisher_worker.ex:8
lib/block_scout_web/router.ex:1
lib/block_scout_web/schema/types.ex:31
lib/phoenix/router.ex:324

@ -56,6 +56,7 @@
- [#8105](https://github.com/blockscout/blockscout/pull/8105) - Extend API v1 with endpoints used by new UI
- [#8104](https://github.com/blockscout/blockscout/pull/8104) - remove "TODO" from API v2 response
- [#8100](https://github.com/blockscout/blockscout/pull/8100), [#8103](https://github.com/blockscout/blockscout/pull/8103) - Extend docker-compose configs with new config when front is running externally
- [#8012](https://github.com/blockscout/blockscout/pull/8012) - API v2 smart-contract verification extended logging
<details>
<summary>Dependencies version bumps</summary>

@ -1,134 +1,235 @@
defmodule BlockScoutWeb.API.V2.FallbackController do
use Phoenix.Controller
require Logger
alias BlockScoutWeb.API.V2.ApiView
def call(conn, {:format, _}) do
@verification_failed "API v2 smart-contract verification failed"
@invalid_parameters "Invalid parameter(s)"
@invalid_address_hash "Invalid address hash"
@invalid_hash "Invalid hash"
@invalid_number "Invalid number"
@invalid_url "Invalid URL"
@not_found "Not found"
@contract_interaction_disabled "Contract interaction disabled"
@restricted_access "Restricted access"
@already_verified "Already verified"
@json_not_found "JSON files not found"
@error_while_reading_json "Error while reading JSON file"
@error_in_libraries "Libraries are not valid JSON map"
@block_lost_consensus "Block lost consensus"
@invalid_captcha_resp "Invalid reCAPTCHA response"
@unauthorized "Unauthorized"
@not_configured_api_key "API key not configured on the server"
@wrong_api_key "Wrong API key"
def call(conn, {:format, _params}) do
Logger.error(fn ->
["#{@verification_failed}: #{@invalid_parameters}"]
end)
conn
|> put_status(:unprocessable_entity)
|> put_view(ApiView)
|> render(:message, %{message: "Invalid parameter(s)"})
|> render(:message, %{message: @invalid_parameters})
end
def call(conn, {:format_address, _}) do
Logger.error(fn ->
["#{@verification_failed}: #{@invalid_address_hash}"]
end)
conn
|> put_status(:unprocessable_entity)
|> put_view(ApiView)
|> render(:message, %{message: "Invalid address hash"})
|> render(:message, %{message: @invalid_address_hash})
end
def call(conn, {:format_url, _}) do
Logger.error(fn ->
["#{@verification_failed}: #{@invalid_url}"]
end)
conn
|> put_status(:unprocessable_entity)
|> put_view(ApiView)
|> render(:message, %{message: "Invalid URL"})
|> render(:message, %{message: @invalid_url})
end
def call(conn, {:not_found, _, :empty_items_with_next_page_params}) do
Logger.error(fn ->
["#{@verification_failed}: :empty_items_with_next_page_params"]
end)
conn
|> json(%{"items" => [], "next_page_params" => nil})
end
def call(conn, {:not_found, _}) do
Logger.error(fn ->
["#{@verification_failed}: #{@not_found}"]
end)
conn
|> put_status(:not_found)
|> put_view(ApiView)
|> render(:message, %{message: "Not found"})
|> render(:message, %{message: @not_found})
end
def call(conn, {:contract_interaction_disabled, _}) do
Logger.error(fn ->
["#{@verification_failed}: #{@contract_interaction_disabled}"]
end)
conn
|> put_status(:forbidden)
|> put_view(ApiView)
|> render(:message, %{message: "Contract interaction disabled"})
|> render(:message, %{message: @contract_interaction_disabled})
end
def call(conn, {:error, {:invalid, :hash}}) do
Logger.error(fn ->
["#{@verification_failed}: #{@invalid_hash}"]
end)
conn
|> put_status(:unprocessable_entity)
|> put_view(ApiView)
|> render(:message, %{message: "Invalid hash"})
|> render(:message, %{message: @invalid_hash})
end
def call(conn, {:error, {:invalid, :number}}) do
Logger.error(fn ->
["#{@verification_failed}: #{@invalid_number}"]
end)
conn
|> put_status(:unprocessable_entity)
|> put_view(ApiView)
|> render(:message, %{message: "Invalid number"})
|> render(:message, %{message: @invalid_number})
end
def call(conn, {:error, :not_found}) do
Logger.error(fn ->
["#{@verification_failed}: :not_found"]
end)
conn
|> call({:not_found, nil})
end
def call(conn, {:restricted_access, true}) do
Logger.error(fn ->
["#{@verification_failed}: #{@restricted_access}"]
end)
conn
|> put_status(:forbidden)
|> put_view(ApiView)
|> render(:message, %{message: "Restricted access"})
|> render(:message, %{message: @restricted_access})
end
def call(conn, {:already_verified, true}) do
Logger.error(fn ->
["#{@verification_failed}: #{@already_verified}"]
end)
conn
|> put_view(ApiView)
|> render(:message, %{message: "Already verified"})
|> render(:message, %{message: @already_verified})
end
def call(conn, {:no_json_file, _}) do
Logger.error(fn ->
["#{@verification_failed}: #{@json_not_found}"]
end)
conn
|> put_view(ApiView)
|> render(:message, %{message: "JSON files not found"})
|> render(:message, %{message: @json_not_found})
end
def call(conn, {:file_error, _}) do
Logger.error(fn ->
["#{@verification_failed}: #{@error_while_reading_json}"]
end)
conn
|> put_view(ApiView)
|> render(:message, %{message: "Error while reading JSON file"})
|> render(:message, %{message: @error_while_reading_json})
end
def call(conn, {:libs_format, _}) do
Logger.error(fn ->
["#{@verification_failed}: #{@error_in_libraries}"]
end)
conn
|> put_view(ApiView)
|> render(:message, %{message: "Libraries are not valid JSON map"})
|> render(:message, %{message: @error_in_libraries})
end
def call(conn, {:lost_consensus, {:ok, block}}) do
Logger.error(fn ->
["#{@verification_failed}: #{@block_lost_consensus}"]
end)
conn
|> put_status(:not_found)
|> json(%{message: "Block lost consensus", hash: to_string(block.hash)})
|> json(%{message: @block_lost_consensus, hash: to_string(block.hash)})
end
def call(conn, {:lost_consensus, {:error, :not_found}}) do
Logger.error(fn ->
["#{@verification_failed}: #{@block_lost_consensus}"]
end)
conn
|> call({:not_found, nil})
end
def call(conn, {:recaptcha, _}) do
Logger.error(fn ->
["#{@verification_failed}: #{@invalid_captcha_resp}"]
end)
conn
|> put_status(:forbidden)
|> put_view(ApiView)
|> render(:message, %{message: "Invalid reCAPTCHA response"})
|> render(:message, %{message: @invalid_captcha_resp})
end
def call(conn, {:auth, _}) do
Logger.error(fn ->
["#{@verification_failed}: #{@unauthorized}"]
end)
conn
|> put_status(:unauthorized)
|> put_view(ApiView)
|> render(:message, %{message: "Unauthorized"})
|> render(:message, %{message: @unauthorized})
end
def call(conn, {:sensitive_endpoints_api_key, _}) do
Logger.error(fn ->
["#{@verification_failed}: #{@not_configured_api_key}"]
end)
conn
|> put_status(:forbidden)
|> put_view(ApiView)
|> render(:message, %{message: "API key not configured on the server"})
|> render(:message, %{message: @not_configured_api_key})
end
def call(conn, {:api_key, _}) do
Logger.error(fn ->
["#{@verification_failed}: #{@wrong_api_key}"]
end)
conn
|> put_status(:unauthorized)
|> put_view(ApiView)
|> render(:message, %{message: "Wrong API key"})
|> render(:message, %{message: @wrong_api_key})
end
end

@ -3,6 +3,8 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
import Explorer.SmartContract.Solidity.Verifier, only: [parse_boolean: 1]
require Logger
alias BlockScoutWeb.AccessHelper
alias BlockScoutWeb.API.V2.ApiView
alias Explorer.Chain
@ -14,6 +16,7 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
action_fallback(BlockScoutWeb.API.V2.FallbackController)
@api_true [api?: true]
@sc_verification_started "Smart-contract verification started"
def config(conn, _params) do
solidity_compiler_versions = CompilerVersion.fetch_version_list(:solc)
@ -46,6 +49,8 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
%{"address_hash" => address_hash_string, "compiler_version" => compiler_version, "source_code" => source_code} =
params
) do
Logger.info("API v2 smart-contract #{address_hash_string} verification via flattened file")
with :validated <- validate_address(params) do
verification_params =
%{
@ -65,11 +70,12 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
|> Map.put("external_libraries", Map.get(params, "libraries", %{}))
|> Map.put("is_yul", Map.get(params, "is_yul_contract", false))
log_sc_verification_started(address_hash_string)
Que.add(SolidityPublisherWorker, {"flattened_api_v2", verification_params})
conn
|> put_view(ApiView)
|> render(:message, %{message: "Verification started"})
|> render(:message, %{message: @sc_verification_started})
end
end
@ -77,6 +83,8 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
conn,
%{"address_hash" => address_hash_string, "files" => _files, "compiler_version" => compiler_version} = params
) do
Logger.info("API v2 smart-contract #{address_hash_string} verification via standard json input")
with {:json_input, json_input} <- validate_params_standard_json_input(params) do
verification_params =
%{
@ -87,15 +95,18 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
|> Map.put("constructor_arguments", Map.get(params, "constructor_args", ""))
|> Map.put("name", Map.get(params, "contract_name", ""))
log_sc_verification_started(address_hash_string)
Que.add(SolidityPublisherWorker, {"json_api_v2", verification_params, json_input})
conn
|> put_view(ApiView)
|> render(:message, %{message: "Verification started"})
|> render(:message, %{message: @sc_verification_started})
end
end
def verification_via_sourcify(conn, %{"address_hash" => address_hash_string, "files" => files} = params) do
Logger.info("API v2 smart-contract #{address_hash_string} verification via Sourcify")
with {:not_found, true} <-
{:not_found, Application.get_env(:explorer, Explorer.ThirdPartyIntegrations.Sourcify)[:enabled]},
:validated <- validate_address(params),
@ -105,6 +116,8 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
files_content <- PublishHelper.read_files(files_array) do
chosen_contract = params["chosen_contract_index"]
log_sc_verification_started(address_hash_string)
Que.add(
SolidityPublisherWorker,
{"sourcify_api_v2", String.downcase(address_hash_string), files_content, conn, chosen_contract}
@ -112,7 +125,7 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
conn
|> put_view(ApiView)
|> render(:message, %{message: "Verification started"})
|> render(:message, %{message: @sc_verification_started})
end
end
@ -120,6 +133,8 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
conn,
%{"address_hash" => address_hash_string, "compiler_version" => compiler_version, "files" => files} = params
) do
Logger.info("API v2 smart-contract #{address_hash_string} verification via multipart")
with :verifier_enabled <- check_microservice(),
:validated <- validate_address(params),
libraries <- Map.get(params, "libraries", "{}"),
@ -142,11 +157,12 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
|> PublishHelper.prepare_files_array()
|> PublishHelper.read_files()
log_sc_verification_started(address_hash_string)
Que.add(SolidityPublisherWorker, {"multipart_api_v2", verification_params, files_array})
conn
|> put_view(ApiView)
|> render(:message, %{message: "Verification started"})
|> render(:message, %{message: @sc_verification_started})
end
end
@ -166,11 +182,12 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
|> Map.put("name", Map.get(params, "contract_name", "Vyper_contract"))
|> Map.put("evm_version", Map.get(params, "evm_version"))
log_sc_verification_started(address_hash_string)
Que.add(VyperPublisherWorker, {"vyper_flattened", verification_params})
conn
|> put_view(ApiView)
|> render(:message, %{message: "Verification started"})
|> render(:message, %{message: @sc_verification_started})
end
end
@ -178,6 +195,8 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
conn,
%{"address_hash" => address_hash_string, "compiler_version" => compiler_version, "files" => files} = params
) do
Logger.info("API v2 vyper smart-contract #{address_hash_string} verification")
with :verifier_enabled <- check_microservice(),
:validated <- validate_address(params) do
interfaces = parse_interfaces(params["interfaces"])
@ -195,11 +214,12 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
|> PublishHelper.prepare_files_array()
|> PublishHelper.read_files()
log_sc_verification_started(address_hash_string)
Que.add(VyperPublisherWorker, {"vyper_multipart", verification_params, files_array})
conn
|> put_view(ApiView)
|> render(:message, %{message: "Verification started"})
|> render(:message, %{message: @sc_verification_started})
end
end
@ -207,6 +227,8 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
conn,
%{"address_hash" => address_hash_string, "files" => _files, "compiler_version" => compiler_version} = params
) do
Logger.info("API v2 vyper smart-contract #{address_hash_string} verification via standard json input")
with :verifier_enabled <- check_microservice(),
{:json_input, json_input} <- validate_params_standard_json_input(params) do
verification_params = %{
@ -215,11 +237,12 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
"input" => json_input
}
log_sc_verification_started(address_hash_string)
Que.add(VyperPublisherWorker, {"vyper_standard_json", verification_params})
conn
|> put_view(ApiView)
|> render(:message, %{message: "Verification started"})
|> render(:message, %{message: @sc_verification_started})
end
end
@ -269,4 +292,8 @@ defmodule BlockScoutWeb.API.V2.VerificationController do
:verifier_enabled
end
end
defp log_sc_verification_started(address_hash_string) do
Logger.info("API v2 smart-contract #{address_hash_string} verification request sent to the microservice")
end
end

@ -3,6 +3,8 @@ defmodule BlockScoutWeb.Notifier do
Responds to events by sending appropriate channel updates to front-end.
"""
require Logger
alias Absinthe.Subscription
alias BlockScoutWeb.API.V2, as: API_V2
@ -48,6 +50,8 @@ defmodule BlockScoutWeb.Notifier do
def handle_event(
{:chain_event, :contract_verification_result, :on_demand, {address_hash, contract_verification_result}}
) do
log_broadcast_verification_results_for_address(address_hash)
Endpoint.broadcast(
"addresses:#{address_hash}",
"verification_result",
@ -60,6 +64,7 @@ defmodule BlockScoutWeb.Notifier do
def handle_event(
{:chain_event, :contract_verification_result, :on_demand, {address_hash, contract_verification_result, conn}}
) do
log_broadcast_verification_results_for_address(address_hash)
%{view: view, compiler: compiler} = select_contract_type_and_form_view(conn.params)
contract_verification_result =
@ -218,6 +223,7 @@ defmodule BlockScoutWeb.Notifier do
end
def handle_event({:chain_event, :smart_contract_was_verified, :on_demand, [address_hash]}) do
log_broadcast_smart_contract_was_verified(address_hash)
Endpoint.broadcast("addresses:#{to_string(address_hash)}", "smart_contract_was_verified", %{})
end
@ -227,7 +233,10 @@ defmodule BlockScoutWeb.Notifier do
})
end
def handle_event(_), do: nil
def handle_event(event) do
Logger.warning("Unknown broadcasted event #{inspect(event)}.")
nil
end
def fetch_compiler_version(compiler) do
case CompilerVersion.fetch_versions(compiler) do
@ -481,4 +490,12 @@ defmodule BlockScoutWeb.Notifier do
Endpoint.broadcast("addresses:#{address_hash}", event, %{map_key => elements})
end
end
defp log_broadcast_verification_results_for_address(address_hash) do
Logger.info("Broadcast smart-contract #{address_hash} verification results")
end
defp log_broadcast_smart_contract_was_verified(address_hash) do
Logger.info("Broadcast smart-contract #{address_hash} was verified")
end
end

@ -75,7 +75,7 @@ defmodule BlockScoutWeb.API.V2.VerificationControllerTest do
request = post(conn, "/api/v2/smart-contracts/#{contract_address.hash}/verification/via/flattened-code", params)
assert %{"message" => "Verification started"} = json_response(request, 200)
assert %{"message" => "Smart-contract verification started"} = json_response(request, 200)
assert_receive %Phoenix.Socket.Message{
payload: %{status: "success"},
@ -118,7 +118,7 @@ defmodule BlockScoutWeb.API.V2.VerificationControllerTest do
request = post(conn, "/api/v2/smart-contracts/#{contract_address.hash}/verification/via/flattened-code", params)
assert %{"message" => "Verification started"} = json_response(request, 200)
assert %{"message" => "Smart-contract verification started"} = json_response(request, 200)
assert_receive %Phoenix.Socket.Message{
payload: %{status: "error", errors: %{name: ["Wrong contract name, please try again."]}},
@ -198,7 +198,7 @@ defmodule BlockScoutWeb.API.V2.VerificationControllerTest do
body
)
assert %{"message" => "Verification started"} = json_response(request, 200)
assert %{"message" => "Smart-contract verification started"} = json_response(request, 200)
assert_receive %Phoenix.Socket.Message{
payload: %{status: "success"},
@ -259,7 +259,7 @@ defmodule BlockScoutWeb.API.V2.VerificationControllerTest do
body
)
assert %{"message" => "Verification started"} = json_response(request, 200)
assert %{"message" => "Smart-contract verification started"} = json_response(request, 200)
assert_receive %Phoenix.Socket.Message{
payload: %{status: "success"},
@ -329,7 +329,7 @@ defmodule BlockScoutWeb.API.V2.VerificationControllerTest do
request = post(conn, "/api/v2/smart-contracts/#{contract_address.hash}/verification/via/vyper-code", params)
assert %{"message" => "Verification started"} = json_response(request, 200)
assert %{"message" => "Smart-contract verification started"} = json_response(request, 200)
assert_receive %Phoenix.Socket.Message{
payload: %{status: "success"},

@ -424,30 +424,53 @@ defmodule Explorer.Chain.SmartContract do
defp upsert_contract_methods(changeset), do: changeset
defp error_message(:compilation), do: "There was an error compiling your contract."
defp error_message(:compiler_version), do: "Compiler version does not match, please try again."
defp error_message(:generated_bytecode), do: "Bytecode does not match, please try again."
defp error_message(:constructor_arguments), do: "Constructor arguments do not match, please try again."
defp error_message(:name), do: "Wrong contract name, please try again."
defp error_message(:json), do: "Invalid JSON file."
defp error_message(:compilation), do: error_message_with_log("There was an error compiling your contract.")
defp error_message(:compiler_version),
do: error_message_with_log("Compiler version does not match, please try again.")
defp error_message(:generated_bytecode), do: error_message_with_log("Bytecode does not match, please try again.")
defp error_message(:constructor_arguments),
do: error_message_with_log("Constructor arguments do not match, please try again.")
defp error_message(:name), do: error_message_with_log("Wrong contract name, please try again.")
defp error_message(:json), do: error_message_with_log("Invalid JSON file.")
defp error_message(:autodetect_constructor_arguments_failed),
do: "Autodetection of constructor arguments failed. Please try to input constructor arguments manually."
do:
error_message_with_log(
"Autodetection of constructor arguments failed. Please try to input constructor arguments manually."
)
defp error_message(:no_creation_data),
do: "The contract creation transaction has not been indexed yet. Please wait a few minutes and try again."
do:
error_message_with_log(
"The contract creation transaction has not been indexed yet. Please wait a few minutes and try again."
)
defp error_message(:unknown_error), do: "Unable to verify: unknown error."
defp error_message(:deployed_bytecode), do: "Deployed bytecode does not correspond to contract creation code."
defp error_message(:unknown_error), do: error_message_with_log("Unable to verify: unknown error.")
defp error_message(string) when is_binary(string), do: string
defp error_message(:deployed_bytecode),
do: error_message_with_log("Deployed bytecode does not correspond to contract creation code.")
defp error_message(:contract_source_code), do: error_message_with_log("Empty contract source code.")
defp error_message(string) when is_binary(string), do: error_message_with_log(string)
defp error_message(%{"message" => string} = error) when is_map(error), do: error_message_with_log(string)
defp error_message(error) do
Logger.warn(fn -> ["Unknown verifier error: ", inspect(error)] end)
"There was an error validating your contract, please try again."
end
defp error_message(:compilation, error_message), do: "There was an error compiling your contract: #{error_message}"
defp error_message(:compilation, error_message),
do: error_message_with_log("There was an error compiling your contract: #{error_message}")
defp error_message_with_log(error_string) do
Logger.error("Smart-contract verification error: #{error_string}")
error_string
end
defp select_error_field(:no_creation_data), do: :address_hash
defp select_error_field(:compiler_version), do: :compiler_version

@ -3,6 +3,8 @@ defmodule Explorer.SmartContract.Solidity.Publisher do
Module responsible to control the contract verification.
"""
require Logger
import Explorer.SmartContract.Helper, only: [cast_libraries: 1]
alias Explorer.Chain
@ -10,6 +12,10 @@ defmodule Explorer.SmartContract.Solidity.Publisher do
alias Explorer.SmartContract.{CompilerVersion, Helper}
alias Explorer.SmartContract.Solidity.Verifier
@sc_verification_via_flattened_file_started "Smart-contract verification via flattened file started"
@sc_verification_via_standard_json_input_started "Smart-contract verification via standard json input started"
@sc_verification_via_multipart_files_started "Smart-contract verification via multipart files started"
@doc """
Evaluates smart contract authenticity and saves its details.
@ -27,6 +33,7 @@ defmodule Explorer.SmartContract.Solidity.Publisher do
"""
def publish(address_hash, params, external_libraries \\ %{}) do
Logger.info(@sc_verification_via_flattened_file_started)
params_with_external_libraries = add_external_libraries(params, external_libraries)
case Verifier.evaluate_authenticity(address_hash, params_with_external_libraries) do
@ -65,6 +72,8 @@ defmodule Explorer.SmartContract.Solidity.Publisher do
end
def publish_with_standard_json_input(%{"address_hash" => address_hash} = params, json_input) do
Logger.info(@sc_verification_via_standard_json_input_started)
case Verifier.evaluate_authenticity_via_standard_json_input(address_hash, params, json_input) do
{:ok,
%{
@ -102,6 +111,7 @@ defmodule Explorer.SmartContract.Solidity.Publisher do
end
def publish_with_multi_part_files(%{"address_hash" => address_hash} = params, external_libraries \\ %{}, files) do
Logger.info(@sc_verification_via_multipart_files_started)
params_with_external_libraries = add_external_libraries(params, external_libraries)
case Verifier.evaluate_authenticity_via_multi_part_files(address_hash, params_with_external_libraries, files) do
@ -187,6 +197,8 @@ defmodule Explorer.SmartContract.Solidity.Publisher do
end
defp create_or_update_smart_contract(address_hash, attrs) do
Logger.info("Publish successfully verified Solidity smart-contract #{address_hash} into the DB")
if Chain.smart_contract_verified?(address_hash) do
Chain.update_smart_contract(attrs, attrs.external_libraries, attrs.secondary_sources)
else
@ -209,6 +221,8 @@ defmodule Explorer.SmartContract.Solidity.Publisher do
verification_with_files?
)
Logger.error("Solidity smart-contract verification #{address_hash} failed because of the error #{error}")
%{changeset | action: :insert}
end

@ -3,6 +3,8 @@ defmodule Explorer.SmartContract.Solidity.PublisherWorker do
Background smart contract verification worker.
"""
require Logger
use Que.Worker, concurrency: 5
alias Explorer.Chain.Events.Publisher, as: EventsPublisher
@ -68,6 +70,8 @@ defmodule Explorer.SmartContract.Solidity.PublisherWorker do
{:error, changeset}
end
Logger.info("Smart-contract #{address_hash} verification: broadcast verification results")
if conn do
EventsPublisher.broadcast([{:contract_verification_result, {address_hash, result, conn}}], :on_demand)
else

@ -5,6 +5,8 @@ defmodule Explorer.SmartContract.Vyper.Publisher do
import Explorer.SmartContract.Helper, only: [cast_libraries: 1]
require Logger
alias Explorer.Chain
alias Explorer.Chain.SmartContract
alias Explorer.SmartContract.CompilerVersion
@ -119,6 +121,7 @@ defmodule Explorer.SmartContract.Vyper.Publisher do
end
def publish_smart_contract(address_hash, params, abi) do
Logger.info("Publish successfully verified Vyper smart-contract #{address_hash} into the DB")
attrs = address_hash |> attributes(params, abi)
Chain.create_smart_contract(attrs, attrs.external_libraries, attrs.secondary_sources)
@ -136,6 +139,8 @@ defmodule Explorer.SmartContract.Vyper.Publisher do
verification_with_files?
)
Logger.error("Vyper smart-contract verification #{address_hash} failed because of the error #{error}")
%{changeset | action: :insert}
end

@ -3,6 +3,8 @@ defmodule Explorer.SmartContract.Vyper.PublisherWorker do
Background smart contract verification worker.
"""
require Logger
use Que.Worker, concurrency: 5
alias Explorer.Chain.Events.Publisher, as: EventsPublisher
@ -34,6 +36,8 @@ defmodule Explorer.SmartContract.Vyper.PublisherWorker do
{:error, changeset}
end
Logger.info("Smart-contract #{address_hash} verification: broadcast verification results")
if conn do
EventsPublisher.broadcast([{:contract_verification_result, {address_hash, result, conn}}], :on_demand)
else

Loading…
Cancel
Save