Logging error in publishing of smart-contract

pull/5450/head
Viktor Baranov 3 years ago
parent 6a918892f6
commit e1541db6d6
  1. 1
      CHANGELOG.md
  2. 47
      apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/contract_controller.ex

@ -28,6 +28,7 @@
- [#5239](https://github.com/blockscout/blockscout/pull/5239) - Add accounting for block rewards in `getblockreward` api method
### Chore
- [#5450](https://github.com/blockscout/blockscout/pull/5450) - Logging error in publishing of smart-contract
- [#5433](https://github.com/blockscout/blockscout/pull/5433) - Caching modules refactoring
- [#5419](https://github.com/blockscout/blockscout/pull/5419) - Add check if address exists for some api methods
- [#5408](https://github.com/blockscout/blockscout/pull/5408) - Update websocket_client hex package

@ -1,6 +1,8 @@
defmodule BlockScoutWeb.API.RPC.ContractController do
use BlockScoutWeb, :controller
require Logger
alias BlockScoutWeb.AddressContractVerificationController, as: VerificationController
alias BlockScoutWeb.API.RPC.Helpers
alias Explorer.Chain
@ -13,6 +15,12 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
alias Explorer.SmartContract.Vyper.Publisher, as: VyperPublisher
alias Explorer.ThirdPartyIntegrations.Sourcify
@smth_went_wrong "Something went wrong while publishing the contract."
@verified "Smart-contract already verified."
@invalid_address "Invalid address hash"
@invalid_args "Invalid args format"
@address_required "Query parameter address is required"
def verify(conn, %{"addressHash" => address_hash} = params) do
with {:params, {:ok, fetched_params}} <- {:params, fetch_verify_params(params)},
{:format, {:ok, casted_address_hash}} <- to_address_hash(address_hash),
@ -36,13 +44,20 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
]}
]
}}} ->
render(conn, :error, error: "Smart-contract already verified.")
render(conn, :error, error: @verified)
{:publish, _} ->
render(conn, :error, error: "Something went wrong while publishing the contract.")
{:publish, error} ->
Logger.error(fn ->
[
@smth_went_wrong,
inspect(error)
]
end)
render(conn, :error, error: @smth_went_wrong)
{:format, :error} ->
render(conn, :error, error: "Invalid address hash")
render(conn, :error, error: @invalid_address)
{:params, {:error, error}} ->
render(conn, :error, error: error)
@ -58,7 +73,7 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
end
if Chain.smart_contract_fully_verified?(address_hash) do
render(conn, :error, error: "Smart-contract already verified.")
render(conn, :error, error: @verified)
else
case Sourcify.check_by_address(address_hash) do
{:ok, _verified_status} ->
@ -97,10 +112,10 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
render(conn, :show, %{result: uid})
else
{:check_verified_status, true} ->
render(conn, :error, error: "Smart-contract already verified.", data: "Smart-contract already verified")
render(conn, :error, error: @verified, data: @verified)
{:format, :error} ->
render(conn, :error, error: "Invalid address hash", data: "Invalid address hash")
render(conn, :error, error: @invalid_address, data: @invalid_address)
{:params, {:error, error}} ->
render(conn, :error, error: error, data: error)
@ -128,7 +143,7 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
end
defp prepare_params(files) when is_struct(files) do
{:error, "Invalid args format"}
{:error, @invalid_args}
end
defp prepare_params(files) when is_map(files) do
@ -140,7 +155,7 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
end
defp prepare_params(_arg) do
{:error, "Invalid args format"}
{:error, @invalid_args}
end
defp validate_files(files) do
@ -269,13 +284,13 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
]}
]
}}} ->
render(conn, :error, error: "Smart-contract already verified.")
render(conn, :error, error: @verified)
{:publish, _} ->
render(conn, :error, error: "Something went wrong while publishing the contract.")
render(conn, :error, error: @smth_went_wrong)
{:format, :error} ->
render(conn, :error, error: "Invalid address hash")
render(conn, :error, error: @invalid_address)
{:params, {:error, error}} ->
render(conn, :error, error: error)
@ -357,10 +372,10 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
render(conn, :getabi, %{abi: contract.abi})
else
{:address_param, :error} ->
render(conn, :error, error: "Query parameter address is required")
render(conn, :error, error: @address_required)
{:format, :error} ->
render(conn, :error, error: "Invalid address hash")
render(conn, :error, error: @invalid_address)
{:contract, :not_found} ->
render(conn, :error, error: "Contract source code not verified")
@ -378,10 +393,10 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
})
else
{:address_param, :error} ->
render(conn, :error, error: "Query parameter address is required")
render(conn, :error, error: @address_required)
{:format, :error} ->
render(conn, :error, error: "Invalid address hash")
render(conn, :error, error: @invalid_address)
{:contract, :not_found} ->
render(conn, :getsourcecode, %{contract: nil, address_hash: nil})

Loading…
Cancel
Save