|
|
@ -2,21 +2,33 @@ 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 |
|
|
|
case Chain.create_decompiled_smart_contract(params) do |
|
|
|
with :ok <- validate_address_hash(params["address_hash"]) do |
|
|
|
{:ok, _decompiled_source_code} -> |
|
|
|
case Chain.create_decompiled_smart_contract(params) do |
|
|
|
send_resp(conn, :created, "") |
|
|
|
{:ok, _decompiled_source_code} -> |
|
|
|
|
|
|
|
send_resp(conn, :created, "") |
|
|
|
|
|
|
|
|
|
|
|
{:error, _changeset} -> |
|
|
|
{:error, _changeset} -> |
|
|
|
send_resp(conn, :unprocessable_entity, "") |
|
|
|
send_resp(conn, :unprocessable_entity, "") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
:error -> send_resp(conn, :unprocessable_entity, "") |
|
|
|
end |
|
|
|
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 |
|
|
|