Apply refactoring to solidity publisher worker

pull/6744/head
Nikita Pozdniakov 2 years ago
parent a01a45572c
commit 14d7e96803
No known key found for this signature in database
GPG Key ID: F344106F9804FE5F
  1. 89
      apps/explorer/lib/explorer/smart_contract/solidity/publisher_worker.ex

@ -11,68 +11,29 @@ defmodule Explorer.SmartContract.Solidity.PublisherWorker do
alias Explorer.ThirdPartyIntegrations.Sourcify alias Explorer.ThirdPartyIntegrations.Sourcify
def perform({"flattened", %{"address_hash" => address_hash} = params, external_libraries, conn}) do def perform({"flattened", %{"address_hash" => address_hash} = params, external_libraries, conn}) do
result = broadcast(:publish, address_hash, [address_hash, params, external_libraries], conn)
case Publisher.publish(address_hash, params, external_libraries) do
{:ok, _contract} = result ->
result
{:error, changeset} ->
{:error, changeset}
end
EventsPublisher.broadcast([{:contract_verification_result, {address_hash, result, conn}}], :on_demand)
end end
def perform({"multipart", %{"address_hash" => address_hash} = params, files_map, external_libraries, conn}) def perform({"multipart", %{"address_hash" => address_hash} = params, files_map, external_libraries, conn})
when is_map(files_map) do when is_map(files_map) do
result = broadcast(:publish_with_multi_part_files, address_hash, [params, external_libraries, files_map], conn)
case Publisher.publish_with_multi_part_files(params, external_libraries, files_map) do
{:ok, _contract} = result ->
result
{:error, changeset} ->
{:error, changeset}
end
EventsPublisher.broadcast([{:contract_verification_result, {address_hash, result, conn}}], :on_demand)
end
def perform({"json_api", %{"address_hash" => address_hash} = params, json_input, uid}) when is_binary(uid) do
VerificationStatus.insert_status(uid, :pending, address_hash)
case Publisher.publish_with_standard_json_input(params, json_input) do
{:ok, _contract} ->
VerificationStatus.update_status(uid, :pass)
{:error, _changeset} ->
VerificationStatus.update_status(uid, :fail)
end
end end
def perform({"json_web", %{"address_hash" => address_hash} = params, json_input, conn}) do def perform({"json_web", %{"address_hash" => address_hash} = params, json_input, conn}) do
result = broadcast(:publish_with_standard_json_input, address_hash, [params, json_input], conn)
case Publisher.publish_with_standard_json_input(params, json_input) do
{:ok, _contract} = result ->
result
{:error, changeset} ->
{:error, changeset}
end
EventsPublisher.broadcast([{:contract_verification_result, {address_hash, result, conn}}], :on_demand)
end end
def perform({"flattened_api_v2", %{"address_hash" => address_hash} = params}) do def perform({"flattened_api_v2", %{"address_hash" => address_hash} = params}) do
result = broadcast(:publish, address_hash, [address_hash, params])
case Publisher.publish(address_hash, params) do end
{:ok, _contract} = result ->
result
{:error, changeset} -> def perform({"json_api_v2", %{"address_hash" => address_hash} = params, json_input}) do
{:error, changeset} broadcast(:publish_with_standard_json_input, address_hash, [params, json_input])
end end
EventsPublisher.broadcast([{:contract_verification_result, {address_hash, result}}], :on_demand) def perform({"multipart_api_v2", %{"address_hash" => address_hash} = params, files_map})
when is_map(files_map) do
broadcast(:publish_with_multi_part_files, address_hash, [params, files_map])
end end
def perform({"sourcify_api_v2", address_hash_string, files_array, conn, chosen_contract}) do def perform({"sourcify_api_v2", address_hash_string, files_array, conn, chosen_contract}) do
@ -85,23 +46,21 @@ defmodule Explorer.SmartContract.Solidity.PublisherWorker do
end end
end end
def perform({"json_api_v2", %{"address_hash" => address_hash} = params, json_input}) do def perform({"json_api", %{"address_hash" => address_hash} = params, json_input, uid}) when is_binary(uid) do
result = VerificationStatus.insert_status(uid, :pending, address_hash)
case Publisher.publish_with_standard_json_input(params, json_input) do
{:ok, _contract} = result ->
result
{:error, changeset} -> case Publisher.publish_with_standard_json_input(params, json_input) do
{:error, changeset} {:ok, _contract} ->
end VerificationStatus.update_status(uid, :pass)
EventsPublisher.broadcast([{:contract_verification_result, {address_hash, result}}], :on_demand) {:error, _changeset} ->
VerificationStatus.update_status(uid, :fail)
end
end end
def perform({"multipart_api_v2", %{"address_hash" => address_hash} = params, files_map}) defp broadcast(method, address_hash, args, conn \\ nil) do
when is_map(files_map) do
result = result =
case Publisher.publish_with_multi_part_files(params, files_map) do case apply(Publisher, method, args) do
{:ok, _contract} = result -> {:ok, _contract} = result ->
result result
@ -109,6 +68,10 @@ defmodule Explorer.SmartContract.Solidity.PublisherWorker do
{:error, changeset} {:error, changeset}
end end
EventsPublisher.broadcast([{:contract_verification_result, {address_hash, result}}], :on_demand) if conn do
EventsPublisher.broadcast([{:contract_verification_result, {address_hash, result, conn}}], :on_demand)
else
EventsPublisher.broadcast([{:contract_verification_result, {address_hash, result}}], :on_demand)
end
end end
end end

Loading…
Cancel
Save