From 024823cd3b1b4a82aa7ad54b610e557f01161378 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 22 Jul 2020 16:49:30 +0300 Subject: [PATCH] Fix read contract bytes array type --- CHANGELOG.md | 1 + .../lib/explorer/smart_contract/reader.ex | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f6c9d4d1d..e43bd0c1f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#3145](https://github.com/poanetwork/blockscout/pull/3145) - Pending txs per address API endpoint ### Fixes +- [#3207](https://github.com/poanetwork/blockscout/pull/3207) - Fix read contract bytes array type output - [#3203](https://github.com/poanetwork/blockscout/pull/3203) - Improve "get mined blocks" query performance - [#3202](https://github.com/poanetwork/blockscout/pull/3202) - Fix contracts verification with experimental features enabled - [#3201](https://github.com/poanetwork/blockscout/pull/3201) - Connect to Metamask button diff --git a/apps/explorer/lib/explorer/smart_contract/reader.ex b/apps/explorer/lib/explorer/smart_contract/reader.ex index 72eef9aa95..de04329147 100644 --- a/apps/explorer/lib/explorer/smart_contract/reader.ex +++ b/apps/explorer/lib/explorer/smart_contract/reader.ex @@ -321,8 +321,19 @@ defmodule Explorer.SmartContract.Reader do Map.put_new(output, "value", bytes_to_string(value)) end - defp new_value(%{"type" => "bytes" <> _number} = output, values, index) do - Map.put_new(output, "value", bytes_to_string(Enum.at(values, index))) + defp new_value(%{"type" => "bytes" <> number_rest} = output, values, index) do + if String.contains?(number_rest, "[]") do + values_array = Enum.at(values, index) + + values_array_formatted = + Enum.map(values_array, fn value -> + bytes_to_string(value) + end) + + Map.put_new(output, "value", values_array_formatted) + else + Map.put_new(output, "value", bytes_to_string(Enum.at(values, index))) + end end defp new_value(%{"type" => "bytes"} = output, values, index) do