Merge pull request #4739 from blockscout/np-improve-logs-and-inputs-decoding

Improve logs and inputs decoding
pull/4768/head
Victor Baranov 3 years ago committed by GitHub
commit dd92450777
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 9
      apps/block_scout_web/lib/block_scout_web/templates/transaction/_decoded_input.html.eex
  3. 26
      apps/block_scout_web/lib/block_scout_web/templates/transaction_log/_logs.html.eex
  4. 11
      apps/block_scout_web/priv/gettext/default.pot
  5. 11
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  6. 20
      apps/explorer/lib/explorer/chain/log.ex
  7. 22
      apps/explorer/lib/explorer/chain/transaction.ex

@ -1,6 +1,7 @@
## Current
### Features
- [#4739](https://github.com/blockscout/blockscout/pull/4739) - Improve logs and inputs decoding
- [#4747](https://github.com/blockscout/blockscout/pull/4747) - Advanced CSV export
- [#4745](https://github.com/blockscout/blockscout/pull/4745) - Vyper contracts verification
- [#4699](https://github.com/blockscout/blockscout/pull/4699) - Address page facelifting

@ -20,7 +20,7 @@
<%= gettext "To have guaranteed accuracy, use the link above to verify the contract's source code." %>
<%= for {:ok, method_id, text, mapping} <- candidates do %>
<hr>
<hr/>
<h3><%= text %>: </h3>
<%= render(BlockScoutWeb.TransactionView, "_decoded_input_body.html", method_id: method_id, text: text, mapping: mapping) %>
@ -28,6 +28,13 @@
<% end %>
<% {:ok, method_id, text, mapping} -> %>
<%= render(BlockScoutWeb.TransactionView, "_decoded_input_body.html", method_id: method_id, text: text, mapping: mapping) %>
<% {:error, :contract_verified, candidates} -> %>
<h3><%= gettext "Potential matches from our contract method database:" %></h3>
<%= for {:ok, method_id, text, mapping} <- candidates do %>
<hr/>
<h3><%= text %>: </h3>
<%= render(BlockScoutWeb.TransactionView, "_decoded_input_body.html", method_id: method_id, text: text, mapping: mapping) %>
<% end %>
<% _ -> %>
<div class="alert alert-danger">
<%= gettext "Failed to decode input data." %>

@ -4,9 +4,9 @@
<%= {:error, :contract_not_verified, _cadidates} -> %>
<div class="alert alert-info">
<%= gettext "To see accurate decoded input data, the contract must be verified." %>
<%= case @transaction do %>
<% %{to_address: %{hash: hash}} -> %>
<% path = address_verify_contract_path(@conn, :new, hash) %>
<%= case @log do %>
<% %{address_hash: %Explorer.Chain.Hash{} = address_hash} -> %>
<% path = address_verify_contract_path(@conn, :new, address_hash) %>
<%= gettext "Verify the contract " %><a href="<%= path %>"><%= gettext "here" %></a>
<% _ -> %>
<%= nil %>
@ -52,7 +52,7 @@
</table>
<%= render BlockScoutWeb.LogView, "_data_decoded_view.html", mapping: mapping %>
<% {:error, :contract_not_verified, results} -> %>
<%= for {:ok, method_id, text, mapping} <- results do %>
<%= for {:ok, method_id, text, mapping} <- results do %>
<dt class="col-md-2"><%= gettext "Decoded" %></dt>
<dd class="col-md-10">
<table summary="Transaction Info" class="table thead-light table-bordered transaction-input-table">
@ -66,7 +66,23 @@
</tr>
</table>
<%= render BlockScoutWeb.LogView, "_data_decoded_view.html", mapping: mapping %>
<% end %>
<% end %>
<% {:error, :contract_verified, results} -> %>
<%= for {:ok, method_id, text, mapping} <- results do %>
<dt class="col-md-2"><%= gettext "Decoded" %></dt>
<dd class="col-md-10">
<table summary="Transaction Info" class="table thead-light table-bordered transaction-input-table">
<tr>
<td>Method Id</td>
<td colspan="3"><code>0x<%= method_id %></code></td>
</tr>
<tr>
<td>Call</td>
<td colspan="3"><code><%= text %></code></td>
</tr>
</table>
<%= render BlockScoutWeb.LogView, "_data_decoded_view.html", mapping: mapping %>
<% end %>
<% _ -> %>
<%= nil %>
<% end %>

@ -868,7 +868,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:101
#: lib/block_scout_web/templates/log/_data_decoded_view.html.eex:7 lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:21
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:104
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:120
msgid "Data"
msgstr ""
@ -892,7 +892,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:32
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:38 lib/block_scout_web/templates/address_logs/_logs.html.eex:53
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:33 lib/block_scout_web/templates/transaction_log/_logs.html.eex:41
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:56
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:56 lib/block_scout_web/templates/transaction_log/_logs.html.eex:72
msgid "Decoded"
msgstr ""
@ -1119,7 +1119,7 @@ msgid "External libraries"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:33
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:40
msgid "Failed to decode input data."
msgstr ""
@ -1432,7 +1432,7 @@ msgid "Log Data"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:114
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:130
msgid "Log Index"
msgstr ""
@ -1777,6 +1777,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:18
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:32
msgid "Potential matches from our contract method database:"
msgstr ""
@ -2573,7 +2574,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:71
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:74
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:90
msgid "Topics"
msgstr ""

@ -868,7 +868,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:101
#: lib/block_scout_web/templates/log/_data_decoded_view.html.eex:7 lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:21
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:104
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:120
msgid "Data"
msgstr ""
@ -892,7 +892,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:32
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:38 lib/block_scout_web/templates/address_logs/_logs.html.eex:53
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:33 lib/block_scout_web/templates/transaction_log/_logs.html.eex:41
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:56
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:56 lib/block_scout_web/templates/transaction_log/_logs.html.eex:72
msgid "Decoded"
msgstr ""
@ -1119,7 +1119,7 @@ msgid "External libraries"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:33
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:40
msgid "Failed to decode input data."
msgstr ""
@ -1432,7 +1432,7 @@ msgid "Log Data"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:114
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:130
msgid "Log Index"
msgstr ""
@ -1777,6 +1777,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:18
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:32
msgid "Potential matches from our contract method database:"
msgstr ""
@ -2573,7 +2574,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:71
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:74
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:90
msgid "Topics"
msgstr ""

@ -133,8 +133,24 @@ defmodule Explorer.Chain.Log do
with {:ok, selector, mapping} <- find_and_decode(full_abi, log, transaction),
identifier <- Base.encode16(selector.method_id, case: :lower),
text <- function_call(selector.function, mapping),
do: {:ok, identifier, text, mapping}
text <- function_call(selector.function, mapping) do
{:ok, identifier, text, mapping}
else
{:error, :could_not_decode} ->
case find_candidates(log, transaction) do
{:error, :contract_not_verified, []} ->
{:error, :could_not_decode}
{:error, :contract_not_verified, candidates} ->
{:error, :contract_verified, candidates}
_ ->
{:error, :could_not_decode}
end
output ->
output
end
_ ->
find_candidates(log, transaction)

@ -483,7 +483,27 @@ defmodule Explorer.Chain.Transaction do
to_address: %{smart_contract: %{abi: abi, address_hash: address_hash}},
hash: hash
}) do
do_decoded_input_data(data, abi, address_hash, hash)
case do_decoded_input_data(data, abi, address_hash, hash) do
# In some cases transactions use methods of some unpredictadle contracts, so we can try to look up for method in a whole DB
{:error, :could_not_decode} ->
case decoded_input_data(%__MODULE__{
to_address: %{smart_contract: nil},
input: %{bytes: data},
hash: hash
}) do
{:error, :contract_not_verified, []} ->
{:error, :could_not_decode}
{:error, :contract_not_verified, candidates} ->
{:error, :contract_verified, candidates}
_ ->
{:error, :could_not_decode}
end
output ->
output
end
end
defp do_decoded_input_data(data, abi, address_hash, hash) do

Loading…
Cancel
Save