Merge pull request #3551 from poanetwork/vb-fix-output-of-tuple-type

Fix contract's method's output of tuple type
pull/3557/head
Victor Baranov 4 years ago committed by GitHub
commit 0fa1504563
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 20
      apps/block_scout_web/lib/block_scout_web/views/smart_contract_view.ex

@ -5,6 +5,7 @@
- [#3540](https://github.com/poanetwork/blockscout/pull/3540) - Apply DarkForest custom theme to NFT instances - [#3540](https://github.com/poanetwork/blockscout/pull/3540) - Apply DarkForest custom theme to NFT instances
### Fixes ### Fixes
- [#3551](https://github.com/poanetwork/blockscout/pull/3551) - Fix contract's method's output of tuple type
### Chore ### Chore
- [#3540](https://github.com/poanetwork/blockscout/pull/3540), [#3545](https://github.com/poanetwork/blockscout/pull/3545) - Support different versions of DarkForest (0.4 - 0.5) - [#3540](https://github.com/poanetwork/blockscout/pull/3540), [#3545](https://github.com/poanetwork/blockscout/pull/3545) - Support different versions of DarkForest (0.4 - 0.5)

@ -48,12 +48,16 @@ defmodule BlockScoutWeb.SmartContractView do
end end
def values(values, type) when is_list(values) and type == "tuple[]" do def values(values, type) when is_list(values) and type == "tuple[]" do
array_from_tuple = tupple_to_array(values) array_from_tuple = tuple_array_to_array(values)
array_from_tuple array_from_tuple
|> Enum.join(", ") |> Enum.join(", ")
end end
def values(value, _type) when is_tuple(value) do
tuple_to_array(value)
end
def values(value, type) when type in ["address", "address payable"] do def values(value, type) when type in ["address", "address payable"] do
{:ok, address} = Explorer.Chain.Hash.Address.cast(value) {:ok, address} = Explorer.Chain.Hash.Address.cast(value)
to_string(address) to_string(address)
@ -62,16 +66,20 @@ defmodule BlockScoutWeb.SmartContractView do
def values(values, _) when is_list(values), do: Enum.join(values, ",") def values(values, _) when is_list(values), do: Enum.join(values, ",")
def values(value, _), do: value def values(value, _), do: value
defp tupple_to_array(values) do defp tuple_array_to_array(values) do
values values
|> Enum.map(fn value -> |> Enum.map(fn value ->
value tuple_to_array(value)
|> Tuple.to_list()
|> Enum.map(&binary_to_utf_string(&1))
|> Enum.join(",")
end) end)
end end
defp tuple_to_array(value) do
value
|> Tuple.to_list()
|> Enum.map(&binary_to_utf_string(&1))
|> Enum.join(",")
end
defp binary_to_utf_string(item) do defp binary_to_utf_string(item) do
if is_binary(item), do: "0x" <> Base.encode16(item, case: :lower), else: item if is_binary(item), do: "0x" <> Base.encode16(item, case: :lower), else: item
end end

Loading…
Cancel
Save