diff --git a/CHANGELOG.md b/CHANGELOG.md index b772493672..9aaace4ece 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features ### Fixes +- [#4453](https://github.com/blockscout/blockscout/pull/4453) - Unescape characters for string output type in the contract response - [#4401](https://github.com/blockscout/blockscout/pull/4401) - Fix displaying of token holders with the same amount ### Chore diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/encoder.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/encoder.ex index d382101392..64d45c1444 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/encoder.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/encoder.ex @@ -83,6 +83,7 @@ defmodule EthereumJSONRPC.Encoder do |> Enum.zip(types_list) |> Enum.map(fn {value, :address} -> "0x" <> Base.encode16(value, case: :lower) + {value, :string} -> unescape(value) {value, _} -> value end) @@ -91,4 +92,15 @@ defmodule EthereumJSONRPC.Encoder do MatchError -> {id, {:error, :invalid_data}} end + + def unescape(data) do + if String.starts_with?(data, "\\x") do + charlist = String.to_charlist(data) + erlang_literal = '"#{charlist}"' + {:ok, [{:string, _, unescaped_charlist}], _} = :erl_scan.string(erlang_literal) + List.to_string(unescaped_charlist) + else + data + end + end end diff --git a/apps/explorer/lib/explorer/smart_contract/reader.ex b/apps/explorer/lib/explorer/smart_contract/reader.ex index 7c244cb7f4..b89bc11293 100644 --- a/apps/explorer/lib/explorer/smart_contract/reader.ex +++ b/apps/explorer/lib/explorer/smart_contract/reader.ex @@ -6,7 +6,7 @@ defmodule Explorer.SmartContract.Reader do [wiki](https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI). """ - alias EthereumJSONRPC.Contract + alias EthereumJSONRPC.{Contract, Encoder} alias Explorer.Chain alias Explorer.Chain.{Hash, SmartContract} alias Explorer.SmartContract.Helper @@ -503,6 +503,14 @@ defmodule Explorer.SmartContract.Reader do Map.put_new(output, "value", bytes_to_string(Enum.at(values, index))) end + defp new_value(%{"type" => :string} = output, [value], _index) do + Map.put_new(output, "value", Encoder.unescape(value)) + end + + defp new_value(%{"type" => "string"} = output, [value], _index) do + Map.put_new(output, "value", Encoder.unescape(value)) + end + defp new_value(output, [value], _index) do Map.put_new(output, "value", value) end diff --git a/bin/install_chrome_headless.sh b/bin/install_chrome_headless.sh index 9721e84ea3..c27512c776 100755 --- a/bin/install_chrome_headless.sh +++ b/bin/install_chrome_headless.sh @@ -1,6 +1,7 @@ export DISPLAY=:99.0 sh -e /etc/init.d/xvfb start -export CHROMEDRIVER_VERSION=`curl -s http://chromedriver.storage.googleapis.com/LATEST_RELEASE` +# export CHROMEDRIVER_VERSION=`curl -s http://chromedriver.storage.googleapis.com/LATEST_RELEASE` +export CHROMEDRIVER_VERSION=`92.0.4515.43` curl -L -O "http://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" unzip chromedriver_linux64.zip sudo chmod +x chromedriver