|
|
@ -14,43 +14,63 @@ defmodule BlockScoutWeb.API.RPC.ContractView do |
|
|
|
RPCView.render("show.json", data: Jason.encode!(abi)) |
|
|
|
RPCView.render("show.json", data: Jason.encode!(abi)) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def render("getsourcecode.json", %{contract: contract, address_hash: address_hash}) do |
|
|
|
def render("getsourcecode.json", %{contract: contract}) do |
|
|
|
RPCView.render("show.json", data: [prepare_source_code_contract(contract, address_hash)]) |
|
|
|
RPCView.render("show.json", data: [prepare_source_code_contract(contract)]) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def render("error.json", assigns) do |
|
|
|
def render("error.json", assigns) do |
|
|
|
RPCView.render("error.json", assigns) |
|
|
|
RPCView.render("error.json", assigns) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def render("verify.json", %{contract: contract, address_hash: address_hash}) do |
|
|
|
def render("verify.json", %{contract: contract}) do |
|
|
|
RPCView.render("show.json", data: prepare_source_code_contract(contract, address_hash)) |
|
|
|
RPCView.render("show.json", data: prepare_source_code_contract(contract)) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp prepare_source_code_contract(nil, address_hash) do |
|
|
|
defp prepare_source_code_contract(nil) do |
|
|
|
%{ |
|
|
|
%{ |
|
|
|
"Address" => to_string(address_hash), |
|
|
|
"Address" => "", |
|
|
|
"SourceCode" => "", |
|
|
|
"SourceCode" => "", |
|
|
|
"ABI" => "Contract source code not verified", |
|
|
|
"ABI" => "Contract source code not verified", |
|
|
|
"ContractName" => "", |
|
|
|
"ContractName" => "", |
|
|
|
"CompilerVersion" => "", |
|
|
|
"CompilerVersion" => "", |
|
|
|
"DecompiledSourceCode" => "", |
|
|
|
"DecompiledSourceCode" => "", |
|
|
|
"DecompilerVersion" => "", |
|
|
|
"DecompilerVersion" => decompiler_version(nil), |
|
|
|
"OptimizationUsed" => "" |
|
|
|
"OptimizationUsed" => "" |
|
|
|
} |
|
|
|
} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp prepare_source_code_contract(contract, _) do |
|
|
|
defp prepare_source_code_contract(address) do |
|
|
|
decompiled_smart_contract = latest_decompiled_smart_contract(contract.decompiled_smart_contracts) |
|
|
|
decompiled_smart_contract = latest_decompiled_smart_contract(address.decompiled_smart_contracts) |
|
|
|
|
|
|
|
contract = address.smart_contract || %{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contract_abi = |
|
|
|
|
|
|
|
if is_nil(address.smart_contract) do |
|
|
|
|
|
|
|
"Contract source code not verified" |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
Jason.encode!(contract.abi) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contract_optimization = |
|
|
|
|
|
|
|
case Map.get(contract, :optimization, "") do |
|
|
|
|
|
|
|
true -> |
|
|
|
|
|
|
|
"1" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
false -> |
|
|
|
|
|
|
|
"0" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"" -> |
|
|
|
|
|
|
|
"" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
%{ |
|
|
|
%{ |
|
|
|
"Address" => to_string(contract.address_hash), |
|
|
|
"Address" => to_string(address.hash), |
|
|
|
"SourceCode" => contract.contract_source_code, |
|
|
|
"SourceCode" => Map.get(contract, :contract_source_code, ""), |
|
|
|
"ABI" => Jason.encode!(contract.abi), |
|
|
|
"ABI" => contract_abi, |
|
|
|
"ContractName" => contract.name, |
|
|
|
"ContractName" => Map.get(contract, :name, ""), |
|
|
|
"DecompiledSourceCode" => decompiled_source_code(decompiled_smart_contract), |
|
|
|
"DecompiledSourceCode" => decompiled_source_code(decompiled_smart_contract), |
|
|
|
"DecompilerVersion" => decompiler_version(decompiled_smart_contract), |
|
|
|
"DecompilerVersion" => decompiler_version(decompiled_smart_contract), |
|
|
|
"CompilerVersion" => contract.compiler_version, |
|
|
|
"CompilerVersion" => Map.get(contract, :compiler_version, ""), |
|
|
|
"OptimizationUsed" => if(contract.optimization, do: "1", else: "0") |
|
|
|
"OptimizationUsed" => contract_optimization |
|
|
|
} |
|
|
|
} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -63,10 +83,8 @@ defmodule BlockScoutWeb.API.RPC.ContractView do |
|
|
|
|
|
|
|
|
|
|
|
%{ |
|
|
|
%{ |
|
|
|
"Address" => to_string(hash), |
|
|
|
"Address" => to_string(hash), |
|
|
|
"SourceCode" => "", |
|
|
|
|
|
|
|
"ABI" => "Contract source code not verified", |
|
|
|
"ABI" => "Contract source code not verified", |
|
|
|
"ContractName" => "", |
|
|
|
"ContractName" => "", |
|
|
|
"DecompiledSourceCode" => decompiled_source_code(decompiled_smart_contract), |
|
|
|
|
|
|
|
"DecompilerVersion" => decompiler_version(decompiled_smart_contract), |
|
|
|
"DecompilerVersion" => decompiler_version(decompiled_smart_contract), |
|
|
|
"CompilerVersion" => "", |
|
|
|
"CompilerVersion" => "", |
|
|
|
"OptimizationUsed" => "" |
|
|
|
"OptimizationUsed" => "" |
|
|
@ -82,10 +100,8 @@ defmodule BlockScoutWeb.API.RPC.ContractView do |
|
|
|
|
|
|
|
|
|
|
|
%{ |
|
|
|
%{ |
|
|
|
"Address" => to_string(hash), |
|
|
|
"Address" => to_string(hash), |
|
|
|
"SourceCode" => contract.contract_source_code, |
|
|
|
|
|
|
|
"ABI" => Jason.encode!(contract.abi), |
|
|
|
"ABI" => Jason.encode!(contract.abi), |
|
|
|
"ContractName" => contract.name, |
|
|
|
"ContractName" => contract.name, |
|
|
|
"DecompiledSourceCode" => decompiled_source_code(decompiled_smart_contract), |
|
|
|
|
|
|
|
"DecompilerVersion" => decompiler_version(decompiled_smart_contract), |
|
|
|
"DecompilerVersion" => decompiler_version(decompiled_smart_contract), |
|
|
|
"CompilerVersion" => contract.compiler_version, |
|
|
|
"CompilerVersion" => contract.compiler_version, |
|
|
|
"OptimizationUsed" => if(contract.optimization, do: "1", else: "0") |
|
|
|
"OptimizationUsed" => if(contract.optimization, do: "1", else: "0") |
|
|
|