Merge pull request #4320 from blockscout/np-fix-getsourcecode-bug

Fix getsourcecode bug
pull/4342/head
Victor Baranov 3 years ago committed by GitHub
commit b299231bb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 27
      apps/block_scout_web/lib/block_scout_web/views/api/rpc/contract_view.ex
  3. 3
      apps/explorer/lib/explorer/chain.ex

@ -10,6 +10,7 @@
- [#4067](https://github.com/blockscout/blockscout/pull/4067) - Display LP tokens USD value and custom metadata in tokens dropdown at address page
### Fixes
- [#4320](https://github.com/blockscout/blockscout/pull/4320) - Fix absence of imported smart-contracts' source code in `getsourcecode` api method
- [#4274](https://github.com/blockscout/blockscout/pull/4302) - Fix search token-autocomplete
- [#4316](https://github.com/blockscout/blockscout/pull/4316) - Fix `/decompiled-contracts` bug
- [#4310](https://github.com/blockscout/blockscout/pull/4310) - Fix logo URL redirection, set font-family defaults for chart.js

@ -1,7 +1,9 @@
defmodule BlockScoutWeb.API.RPC.ContractView do
use BlockScoutWeb, :view
alias BlockScoutWeb.AddressView
alias BlockScoutWeb.API.RPC.RPCView
alias Explorer.Chain
alias Explorer.Chain.{Address, DecompiledSmartContract, SmartContract}
defguardp is_empty_string(input) when input == "" or input == nil
@ -140,9 +142,34 @@ defmodule BlockScoutWeb.API.RPC.ContractView do
|> Map.put_new(:CompilerVersion, Map.get(contract, :compiler_version, ""))
|> Map.put_new(:OptimizationUsed, contract_optimization)
|> Map.put_new(:EVMVersion, Map.get(contract, :evm_version, ""))
|> insert_additional_sources(address)
end
end
defp insert_additional_sources(output, address) do
additional_sources_from_twin = Chain.get_address_verified_twin_contract(address.hash).additional_sources
additional_sources =
if AddressView.smart_contract_verified?(address),
do: address.smart_contract_additional_sources,
else: additional_sources_from_twin
additional_sources_array =
if additional_sources,
do:
Enum.map(additional_sources, fn src ->
%{
Filename: src.file_name,
SourceCode: SmartContract.add_submitted_comment(src.contract_source_code, src.inserted_at)
}
end),
else: []
if additional_sources_array == [],
do: output,
else: Map.put_new(output, :AdditionalSources, additional_sources_array)
end
defp prepare_contract(%Address{
hash: hash,
smart_contract: nil

@ -3537,7 +3537,8 @@ defmodule Explorer.Chain do
nil
address ->
address_with_smart_contract = Repo.preload(address, [:smart_contract, :decompiled_smart_contracts])
address_with_smart_contract =
Repo.preload(address, [:smart_contract, :decompiled_smart_contracts, :smart_contract_additional_sources])
if address_with_smart_contract.smart_contract do
formatted_code = format_source_code_output(address_with_smart_contract.smart_contract)

Loading…
Cancel
Save