|
|
@ -2,9 +2,11 @@ defmodule BlockScoutWeb.API.V1.DecompiledSmartContractController do |
|
|
|
use BlockScoutWeb, :controller |
|
|
|
use BlockScoutWeb, :controller |
|
|
|
|
|
|
|
|
|
|
|
alias Explorer.Chain |
|
|
|
alias Explorer.Chain |
|
|
|
|
|
|
|
alias Explorer.Chain.Hash.Address |
|
|
|
|
|
|
|
|
|
|
|
def create(conn, params) do |
|
|
|
def create(conn, params) do |
|
|
|
if auth_token(conn) == actual_token() do |
|
|
|
if auth_token(conn) == actual_token() do |
|
|
|
|
|
|
|
with :ok <- validate_address_hash(params["address_hash"]) do |
|
|
|
case Chain.create_decompiled_smart_contract(params) do |
|
|
|
case Chain.create_decompiled_smart_contract(params) do |
|
|
|
{:ok, _decompiled_source_code} -> |
|
|
|
{:ok, _decompiled_source_code} -> |
|
|
|
send_resp(conn, :created, "") |
|
|
|
send_resp(conn, :created, "") |
|
|
@ -12,11 +14,21 @@ defmodule BlockScoutWeb.API.V1.DecompiledSmartContractController do |
|
|
|
{:error, _changeset} -> |
|
|
|
{:error, _changeset} -> |
|
|
|
send_resp(conn, :unprocessable_entity, "") |
|
|
|
send_resp(conn, :unprocessable_entity, "") |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
:error -> send_resp(conn, :unprocessable_entity, "") |
|
|
|
|
|
|
|
end |
|
|
|
else |
|
|
|
else |
|
|
|
send_resp(conn, :forbidden, "") |
|
|
|
send_resp(conn, :forbidden, "") |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp validate_address_hash(address_hash) do |
|
|
|
|
|
|
|
case Address.cast(address_hash) do |
|
|
|
|
|
|
|
{:ok, _} -> :ok |
|
|
|
|
|
|
|
:error -> :error |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp auth_token(conn) do |
|
|
|
defp auth_token(conn) do |
|
|
|
case get_req_header(conn, "auth_token") do |
|
|
|
case get_req_header(conn, "auth_token") do |
|
|
|
[token] -> token |
|
|
|
[token] -> token |
|
|
|