Merge pull request #5487 from blockscout/np-fix-contract-constructor-args-ui

Fix array displaying in decoded constructor args
pull/5491/head
Victor Baranov 3 years ago committed by GitHub
commit 6d47ee5511
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 41
      apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex

@ -7,6 +7,7 @@
### Fixes
- [#5488](https://github.com/blockscout/blockscout/pull/5488) - Split long contract output to multiple lines
- [#5487](https://github.com/blockscout/blockscout/pull/5487) - Fix array displaying in decoded constructor args
- [#5455](https://github.com/blockscout/blockscout/pull/5455) - Fix unverified_smart_contract function: add md5 of bytecode to the changeset
- [#5454](https://github.com/blockscout/blockscout/pull/5454) - Docker: Fix the qemu-x86_64 signal 11 error on Apple Silicon
- [#5443](https://github.com/blockscout/blockscout/pull/5443) - Geth: display tx revert reason

@ -33,21 +33,7 @@ defmodule BlockScoutWeb.AddressContractView do
|> decode_data(input_types)
|> Enum.zip(constructor_abi["inputs"])
|> Enum.reduce({0, "#{contract.constructor_arguments}\n\n"}, fn {val, %{"type" => type}}, {count, acc} ->
formatted_val =
cond do
type =~ "address" ->
address_hash = "0x" <> Base.encode16(val, case: :lower)
address = get_address(address_hash)
get_formatted_address_data(address, address_hash, conn)
type =~ "bytes" ->
Base.encode16(val, case: :lower)
true ->
val
end
formatted_val = val_to_string(val, type, conn)
{count + 1, "#{acc}Arg [#{count}] (<b>#{type}</b>) : #{formatted_val}\n"}
end)
@ -57,6 +43,31 @@ defmodule BlockScoutWeb.AddressContractView do
_ -> contract.constructor_arguments
end
defp val_to_string(val, type, conn) do
cond do
type =~ "[]" ->
if is_list(val) or is_tuple(val) do
"[" <>
Enum.map_join(val, ", ", fn el -> val_to_string(el, String.replace_suffix(type, "[]", ""), conn) end) <> "]"
else
to_string(val)
end
type =~ "address" ->
address_hash = "0x" <> Base.encode16(val, case: :lower)
address = get_address(address_hash)
get_formatted_address_data(address, address_hash, conn)
type =~ "bytes" ->
Base.encode16(val, case: :lower)
true ->
to_string(val)
end
end
defp get_address(address_hash) do
case Chain.string_to_address_hash(address_hash) do
{:ok, address} -> address

Loading…
Cancel
Save