From 06c87bfcfeca533a29ec41b972ca99d131ae3251 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Thu, 24 Dec 2020 13:39:04 +0300 Subject: [PATCH] Revert reason in result of contract call --- CHANGELOG.md | 1 + .../controllers/smart_contract_controller.ex | 6 ++++-- apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/encoder.ex | 4 ++++ .../test/ethereum_jsonrpc/contract_test.exs | 2 +- apps/explorer/test/explorer/token/balance_reader_test.exs | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 283881e628..80e649e11a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#3536](https://github.com/poanetwork/blockscout/pull/3536) - Revert reason in the result of contract's method call - [#3532](https://github.com/poanetwork/blockscout/pull/3532) - Contract interaction: an easy setting of precision for integer input - [#3531](https://github.com/poanetwork/blockscout/pull/3531) - Allow double quotes in input data of contract methods - [#3515](https://github.com/poanetwork/blockscout/pull/3515) - CRC total balance diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex index ee84c96e89..7b7755f41b 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex @@ -4,6 +4,8 @@ defmodule BlockScoutWeb.SmartContractController do alias Explorer.Chain alias Explorer.SmartContract.{Reader, Writer} + @burn_address "0x0000000000000000000000000000000000000000" + def index(conn, %{"hash" => address_hash_string, "type" => contract_type, "action" => action}) do address_options = [ necessity_by_association: %{ @@ -17,9 +19,9 @@ defmodule BlockScoutWeb.SmartContractController do implementation_address_hash_string = if contract_type == "proxy" do Chain.get_implementation_address_hash(address.hash, address.smart_contract.abi) || - "0x0000000000000000000000000000000000000000" + @burn_address else - "0x0000000000000000000000000000000000000000" + @burn_address end functions = diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/encoder.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/encoder.ex index a792ae728e..d382101392 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/encoder.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/encoder.ex @@ -47,6 +47,10 @@ defmodule EthereumJSONRPC.Encoder do """ @spec decode_result(map(), %ABI.FunctionSelector{} | [%ABI.FunctionSelector{}]) :: {String.t(), {:ok, any()} | {:error, String.t() | :invalid_data}} + def decode_result(%{error: %{code: code, data: data, message: message}, id: id}, _selector) do + {id, {:error, "(#{code}) #{message} (#{data})"}} + end + def decode_result(%{error: %{code: code, message: message}, id: id}, _selector) do {id, {:error, "(#{code}) #{message}"}} end diff --git a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/contract_test.exs b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/contract_test.exs index 789de5dec9..ef2f58ed4a 100644 --- a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/contract_test.exs +++ b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/contract_test.exs @@ -82,7 +82,7 @@ defmodule EthereumJSONRPC.ContractTest do blockchain_result = [ {:ok, [42]}, {:ok, [52]}, - {:error, "(-32015) Some error"} + {:error, "(-32015) Some error (something)"} ] assert EthereumJSONRPC.execute_contract_functions( diff --git a/apps/explorer/test/explorer/token/balance_reader_test.exs b/apps/explorer/test/explorer/token/balance_reader_test.exs index 871c688a78..1a98dd2455 100644 --- a/apps/explorer/test/explorer/token/balance_reader_test.exs +++ b/apps/explorer/test/explorer/token/balance_reader_test.exs @@ -55,7 +55,7 @@ defmodule Explorer.Token.BalanceReaderTest do } ]) - assert result == [{:error, "(-32015) VM execution error."}] + assert result == [{:error, "(-32015) VM execution error. (Reverted 0x)"}] end end