New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solidityscan report API endpoint #8908
Conversation
d28c046
to
c36f6b5
Compare
7b1ed39
to
14a6089
Compare
end | ||
end | ||
|
||
defp base_url(address_hash_string) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename it to quickscan_url
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose? What if they change the api path? I'd say we shouldn't depend on their naming in our intertnal namings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually base_url
in our modules stands for the base path to the api (https://api.solidityscan.com/api/v1
). In this case base_url
doesn't suit to this paradigm, therefore I suggested to rename the function
{:format, :error} -> | ||
conn | ||
|> put_status(400) | ||
|> json(%{status: "error", message: "Invalid address hash"}) | ||
|
||
{:restricted_access, true} -> | ||
conn | ||
|> put_status(403) | ||
|> json(%{status: "error", message: "Access restricted"}) | ||
|
||
{:error, :not_found} -> | ||
conn | ||
|> put_status(404) | ||
|> json(%{status: "error", message: "Address not found"}) | ||
|
||
{:is_smart_contract, false} -> | ||
conn | ||
|> put_status(404) | ||
|> json(%{status: "error", message: "Smart-contract not found"}) | ||
|
||
{:is_empty_response, true} -> | ||
conn | ||
|> put_status(500) | ||
|> json(%{status: "error", message: "Empty response"}) | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In API v2 we usually state all mismatched with patters in BlockScoutWeb.API.V2.FallbackController. Most likely all of the patterns you stated, already exist in FallbackController
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, extended fallback controller with new responses in 381a6eb
9539bd5
to
ffa4f8c
Compare
ffa4f8c
to
381a6eb
Compare
|> render(:message, %{message: @address_not_found}) | ||
end | ||
|
||
def call(conn, {:is_smart_contract, false}) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that Address.is_smart_contract/1
may return nil as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Fixed in 48ac396.
apps/block_scout_web/lib/block_scout_web/controllers/api/v2/smart_contract_controller.ex
Outdated
Show resolved
Hide resolved
|> fetch_compiler_versions(:vyper) | ||
end | ||
|
||
defp fetch_compiler_versions(compiler_list, compiler_type) do | ||
if RustVerifierInterface.enabled?() do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we will pass function instead of list to not to execute request if rust verifier is disabled?
Like this
defp fetch_solc_versions do
fetch_compiler_versions(&RustVerifierInterface.get_versions_list/0, :solc)
end
defp fetch_vyper_versions do
fetch_compiler_versions(&RustVerifierInterface.vyper_get_versions_list/0, :vyper)
end
defp fetch_compiler_versions(compiler_list_fn, compiler_type) do
if RustVerifierInterface.enabled?() do
compiler_list_fn.()
else
headers = [{"Content-Type", "application/json"}]
case HTTPoison.get(source_url(compiler_type), headers) do
{:ok, %{status_code: 200, body: body}} ->
{:ok, format_data(body, compiler_type)}
{:ok, %{status_code: _status_code, body: body}} ->
{:error, Helper.decode_json(body)["error"]}
{:error, %{reason: reason}} ->
{:error, reason}
end
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Applied in 48ac396
.dialyzer-ignore
Outdated
lib/explorer/exchange_rates/source.ex:134 | ||
lib/explorer/exchange_rates/source.ex:137 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about these dialyzer warnings? It seems that HTTPoison.get
may return only %Response{}
or %Error{}
indeed, maybe we can remove this clauses https://github.com/blockscout/blockscout/blob/vb-solidityscan-support/apps/explorer/lib/explorer/exchange_rates/source.ex#L134-L138?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Implemented in 48ac396
apps/explorer/lib/explorer/third_party_integrations/sourcify.ex
Outdated
Show resolved
Hide resolved
…om solidityscan api endpoint
…art_contract_controller.ex Co-authored-by: Maxim Filonov <53992153+sl1depengwyn@users.noreply.github.com>
56b0587
to
9d4bdf9
Compare
Resolves #8907
Motivation
Adding API V2 endpoint for proxying request of Solidityscan report.
Changelog
New API v2 endpoint added:
Sample success response:
Sample failed response:
Checklist for your Pull Request (PR)
CHANGELOG.md
with this PR Solidityscan envs docs#200master
in the Version column. Changes will be reflected in this table: https://docs.blockscout.com/for-developers/information-and-settings/env-variables.