Skip to content

Commit

Permalink
Fix bugs in smart contracts API v2
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitosing committed Jan 6, 2023
1 parent d5c4cc6 commit 015e99d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

### Fixes

- [#6676](https://github.com/blockscout/blockscout/pull/6676) - Fix `/smart-contracts` bugs in API v2
- [#6603](https://github.com/blockscout/blockscout/pull/6603) - Add to MM button explorer URL fix
- [#6512](https://github.com/blockscout/blockscout/pull/6512) - Allow gasUsed in failed internal txs; Leave error field for staticcall
- [#6532](https://github.com/blockscout/blockscout/pull/6532) - Fix index creation migration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do
"file_path" => target_contract.file_path,
"additional_sources" => Enum.map(additional_sources, &prepare_additional_sourse/1),
"compiler_settings" => target_contract.compiler_settings,
"external_libraries" => target_contract.external_libraries,
"external_libraries" => prepare_external_libraries(target_contract.external_libraries),
"constructor_args" => target_contract.constructor_arguments,
"decoded_constructor_args" =>
format_constructor_arguments(target_contract.abi, target_contract.constructor_arguments)
Expand Down Expand Up @@ -173,6 +173,12 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do
end
end

defp prepare_external_libraries(libraries) when is_list(libraries) do
Enum.map(libraries, fn %Explorer.Chain.SmartContract.ExternalLibrary{name: name, address_hash: address_hash} ->
%{name: name, address_hash: address_hash}
end)
end

defp prepare_additional_sourse(source) do
%{
"source_code" => source.contract_source_code,
Expand All @@ -190,7 +196,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do
|> AddressContractView.decode_data(input_types)
|> Enum.zip(constructor_abi["inputs"])
|> Enum.map(fn {value, %{"type" => type} = input_arg} ->
{ABIEncodedValueView.value_json(type, value), input_arg}
[ABIEncodedValueView.value_json(type, value), input_arg]
end)

result
Expand Down

0 comments on commit 015e99d

Please sign in to comment.