Merge pull request #6094 from blockscout/np-fix-inconsistency-getsourcecode

Fix inconsistent behaviour of getsourcecode method
pull/6106/head
Victor Baranov 2 years ago committed by GitHub
commit 69a4b05859
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 7
      apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/contract_controller.ex
  3. 22
      apps/block_scout_web/lib/block_scout_web/views/api/rpc/contract_view.ex
  4. 15
      apps/block_scout_web/test/block_scout_web/controllers/api/rpc/contract_controller_test.exs

@ -7,6 +7,8 @@
### Fixes
- [#6094](https://github.com/blockscout/blockscout/pull/6094) - Fix inconsistent behaviour of `getsourcecode` method
### Chore
## 4.1.8-beta

@ -7,7 +7,7 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
alias BlockScoutWeb.API.RPC.Helpers
alias Explorer.Chain
alias Explorer.Chain.Events.Publisher, as: EventsPublisher
alias Explorer.Chain.{Hash, SmartContract}
alias Explorer.Chain.{Address, Hash, SmartContract}
alias Explorer.Chain.SmartContract.VerificationStatus
alias Explorer.Etherscan.Contracts
alias Explorer.SmartContract.Helper
@ -404,7 +404,7 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
address = Contracts.address_hash_to_address_with_source_code(address_hash)
render(conn, :getsourcecode, %{
contract: address
contract: address || %Address{hash: address_hash, smart_contract: nil}
})
else
{:address_param, :error} ->
@ -412,9 +412,6 @@ defmodule BlockScoutWeb.API.RPC.ContractController do
{:format, :error} ->
render(conn, :error, error: @invalid_address)
{:contract, :not_found} ->
render(conn, :getsourcecode, %{contract: nil, address_hash: nil})
end
end

@ -3,6 +3,7 @@ defmodule BlockScoutWeb.API.RPC.ContractView do
alias BlockScoutWeb.AddressView
alias BlockScoutWeb.API.RPC.RPCView
alias Ecto.Association.NotLoaded
alias Explorer.Chain
alias Explorer.Chain.{Address, DecompiledSmartContract, SmartContract}
@ -34,25 +35,6 @@ defmodule BlockScoutWeb.API.RPC.ContractView do
RPCView.render("show.json", data: result)
end
defp prepare_source_code_contract(nil) do
%{
"Address" => "",
"SourceCode" => "",
"ABI" => "Contract source code not verified",
"ContractName" => "",
"CompilerVersion" => "",
"DecompiledSourceCode" => "",
"DecompilerVersion" => decompiler_version(nil),
"OptimizationUsed" => "",
"OptimizationRuns" => "",
"EVMVersion" => "",
"ConstructorArguments" => "",
"ExternalLibraries" => "",
"FileName" => "",
"IsProxy" => "false"
}
end
defp prepare_source_code_contract(address) do
decompiled_smart_contract = latest_decompiled_smart_contract(address.decompiled_smart_contracts)
contract = address.smart_contract || %{}
@ -220,6 +202,8 @@ defmodule BlockScoutWeb.API.RPC.ContractView do
}
end
defp latest_decompiled_smart_contract(%NotLoaded{}), do: nil
defp latest_decompiled_smart_contract([]), do: nil
defp latest_decompiled_smart_contract(contracts) do

@ -396,20 +396,7 @@ defmodule BlockScoutWeb.API.RPC.ContractControllerTest do
expected_result = [
%{
"Address" => "",
"SourceCode" => "",
"ABI" => "Contract source code not verified",
"ContractName" => "",
"CompilerVersion" => "",
"OptimizationUsed" => "",
"DecompiledSourceCode" => "",
"DecompilerVersion" => "",
"ConstructorArguments" => "",
"EVMVersion" => "",
"ExternalLibraries" => "",
"OptimizationRuns" => "",
"FileName" => "",
"IsProxy" => "false"
"Address" => "0x8bf38d4764929064f2d4d3a56520a76ab3df415b"
}
]

Loading…
Cancel
Save