Solidityscan integration enhancements

pull/9439/head
Viktor Baranov 8 months ago
parent a0e801ac41
commit 08bf588955
  1. 1
      CHANGELOG.md
  2. 8
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/fallback_controller.ex
  3. 26
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/smart_contract_controller.ex
  4. 25
      apps/explorer/lib/explorer/third_party_integrations/solidityscan.ex

@ -34,6 +34,7 @@
### Chore
- [#9439](https://github.com/blockscout/blockscout/pull/9439) - Solidityscan integration enhancements
- [#9398](https://github.com/blockscout/blockscout/pull/9398) - Improve elixir dependencies caching in CI
- [#9393](https://github.com/blockscout/blockscout/pull/9393) - Bump actions/cache to v4
- [#9389](https://github.com/blockscout/blockscout/pull/9389) - Output user address as an object in API v2 for Shibarium

@ -28,6 +28,7 @@ defmodule BlockScoutWeb.API.V2.FallbackController do
@address_not_found "Address not found"
@address_is_not_smart_contract "Address is not smart-contract"
@vyper_smart_contract_is_not_supported "Vyper smart-contracts are not supported by SolidityScan"
@unverified_smart_contract "Smart-contract is unverified"
@empty_response "Empty response"
@tx_interpreter_service_disabled "Transaction Interpretation Service is not enabled"
@disabled "API endpoint is disabled"
@ -269,6 +270,13 @@ defmodule BlockScoutWeb.API.V2.FallbackController do
|> render(:message, %{message: @vyper_smart_contract_is_not_supported})
end
def call(conn, {:is_verified_smart_contract, result}) when result == false do
conn
|> put_status(:not_found)
|> put_view(ApiView)
|> render(:message, %{message: @unverified_smart_contract})
end
def call(conn, {:is_empty_response, true}) do
conn
|> put_status(500)

@ -195,28 +195,22 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do
| {:is_empty_response, true}
| {:is_smart_contract, false | nil}
| {:restricted_access, true}
| {:is_verified_smart_contract, false}
| {:is_vyper_contract, true}
| Plug.Conn.t()
def solidityscan_report(conn, %{"address_hash" => address_hash_string} = params) do
with {:format_address, {:ok, address_hash}} <- {:format_address, Chain.string_to_address_hash(address_hash_string)},
{:ok, false} <- AccessHelper.restricted_access?(address_hash_string, params),
{:address, {:ok, address}} <- {:address, Chain.hash_to_address(address_hash)},
{:is_smart_contract, true} <- {:is_smart_contract, Address.smart_contract?(address)} do
smart_contract = SmartContract.address_hash_to_smart_contract_without_twin(address_hash, @api_true)
if smart_contract && smart_contract.is_vyper_contract do
{:is_vyper_contract, true}
else
response = SolidityScan.solidityscan_request(address_hash_string)
if is_nil(response) do
{:is_empty_response, true}
else
conn
|> put_status(200)
|> json(response)
end
end
{:is_smart_contract, true} <- {:is_smart_contract, Address.smart_contract?(address)},
smart_contract = SmartContract.address_hash_to_smart_contract_without_twin(address_hash, @api_true),
{:is_verified_smart_contract, true} <- {:is_verified_smart_contract, !is_nil(smart_contract)},
{:is_vyper_contract, false} <- {:is_vyper_contract, smart_contract.is_vyper_contract},
response = SolidityScan.solidityscan_request(address_hash_string),
{:is_empty_response, false} <- {:is_empty_response, is_nil(response)} do
conn
|> put_status(200)
|> json(response)
end
end

@ -3,6 +3,7 @@ defmodule Explorer.ThirdPartyIntegrations.SolidityScan do
Module for SolidityScan integration https://apidoc.solidityscan.com/solidityscan-security-api/solidityscan-other-apis/quickscan-api-v1
"""
require Logger
alias Explorer.Helper
@blockscout_platform_id "16"
@ -17,17 +18,29 @@ defmodule Explorer.ThirdPartyIntegrations.SolidityScan do
url = base_url(address_hash_string)
case HTTPoison.get(url, headers, recv_timeout: @recv_timeout) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
Helper.decode_json(body)
if url do
case HTTPoison.get(url, headers, recv_timeout: @recv_timeout) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
Helper.decode_json(body)
_ ->
nil
_ ->
nil
end
else
Logger.warning(
"SOLIDITYSCAN_CHAIN_ID or SOLIDITYSCAN_API_TOKEN env variable is not configured on the backend. Please, set it."
)
nil
end
end
defp base_url(address_hash_string) do
"https://api.solidityscan.com/api/v1/quickscan/#{@blockscout_platform_id}/#{chain_id()}/#{address_hash_string}"
if chain_id() && api_key() do
"https://api.solidityscan.com/api/v1/quickscan/#{@blockscout_platform_id}/#{chain_id()}/#{address_hash_string}"
else
nil
end
end
defp chain_id do

Loading…
Cancel
Save