Unescape characters for string output type in the contract response

pull/4453/head
Viktor Baranov 3 years ago
parent e22363598f
commit 688d5eb3b2
  1. 1
      CHANGELOG.md
  2. 12
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/encoder.ex
  3. 10
      apps/explorer/lib/explorer/smart_contract/reader.ex
  4. 3
      bin/install_chrome_headless.sh

@ -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

@ -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

@ -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

@ -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

Loading…
Cancel
Save