Finally resolve decoding issue in right way

vb-fix-decoding
Viktor Baranov 12 months ago
parent 16307adbe5
commit 7727d93d64
  1. 4
      .dialyzer-ignore
  2. 75
      apps/block_scout_web/lib/block_scout_web/templates/address_logs/_logs.html.eex
  3. 1
      apps/block_scout_web/lib/block_scout_web/views/api/v2/transaction_view.ex
  4. 4
      apps/block_scout_web/priv/gettext/default.pot
  5. 4
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  6. 42
      apps/explorer/lib/explorer/chain/log.ex

@ -26,5 +26,5 @@ lib/indexer/fetcher/zkevm/transaction_batch.ex:252
lib/block_scout_web/views/api/v2/transaction_view.ex:431
lib/block_scout_web/views/api/v2/transaction_view.ex:472
lib/explorer/chain/transaction.ex:167
lib/explorer/chain/transaction.ex:1457
lib/explorer/chain/transaction.ex:1458
lib/explorer/chain/transaction.ex:1452
lib/explorer/chain/transaction.ex:1453

@ -27,46 +27,43 @@
) %>
</h3>
</dd>
<%= case decoded_result do %>
<% {:error, :could_not_decode} -> %>
<dt class="col-md-2"><%= gettext "Decoded" %></dt>
<dd class="col-md-10">
<div class="alert alert-danger">
<%= gettext "Failed to decode log data." %>
</div>
<% {:ok, method_id, text, mapping} -> %>
<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 %>
<% {:error, :contract_not_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 %>
</div>
<%= case decoded_result do %>
<% {:error, :could_not_decode} -> %>
<dt class="col-md-2"><%= gettext "Decoded" %></dt>
<dd class="col-md-10">
<div class="alert alert-danger">
<%= gettext "Failed to decode log data." %>
</div>
<% {:ok, method_id, text, mapping} -> %>
<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 %>
<% {:error, :contract_not_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 %>
<dt class="col-md-2"><%= gettext "Topics" %></dt>
<dd class="col-md-10">

@ -648,7 +648,6 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
defp format_decoded_input(_), do: nil
defp format_decoded_log_input({:error, :could_not_decode}), do: nil
defp format_decoded_log_input({:error, :no_matching_function}), do: nil
defp format_decoded_log_input({:ok, _method_id, _text, _mapping} = decoded), do: decoded
defp format_decoded_log_input({:error, _, candidates}), do: Enum.at(candidates, 0)

@ -1049,7 +1049,7 @@ msgstr ""
msgid "Daily Transactions"
msgstr ""
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:101
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:98
#: lib/block_scout_web/templates/log/_data_decoded_view.html.eex:7
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:23
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:121
@ -2962,7 +2962,7 @@ msgstr ""
msgid "Topic"
msgstr ""
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:71
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:68
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:91
#, elixir-autogen, elixir-format
msgid "Topics"

@ -1049,7 +1049,7 @@ msgstr ""
msgid "Daily Transactions"
msgstr ""
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:101
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:98
#: lib/block_scout_web/templates/log/_data_decoded_view.html.eex:7
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:23
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:121
@ -2962,7 +2962,7 @@ msgstr ""
msgid "Topic"
msgstr ""
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:71
#: lib/block_scout_web/templates/address_logs/_logs.html.eex:68
#: lib/block_scout_web/templates/transaction_log/_logs.html.eex:91
#, elixir-autogen, elixir-format
msgid "Topics"

@ -152,26 +152,17 @@ defmodule Explorer.Chain.Log do
defp handle_method_decode_error(error, log, transaction, options, skip_sig_provider?, contracts_acc, events_acc) do
case error do
{:error, :could_not_decode} ->
case find_method_candidates(log, transaction, options, events_acc) do
{:error, _reason} ->
case find_method_candidates(log, transaction, options, events_acc, skip_sig_provider?) do
{{:error, :contract_not_verified, []}, events_acc} ->
{decode_event_via_sig_provider(log, transaction, false, options, events_acc, skip_sig_provider?),
contracts_acc, events_acc}
{decode_event_via_sig_provider(log, transaction, false, skip_sig_provider?), contracts_acc, events_acc}
{{:error, :contract_not_verified, candidates}, events_acc} ->
{{:error, :contract_not_verified, candidates}, contracts_acc, events_acc}
{_, events_acc} ->
{decode_event_via_sig_provider(log, transaction, false, options, events_acc, skip_sig_provider?),
contracts_acc, events_acc}
{decode_event_via_sig_provider(log, transaction, false, skip_sig_provider?), contracts_acc, events_acc}
end
{:error, :no_matching_function} ->
{decode_event_via_sig_provider(log, transaction, false, options, events_acc, skip_sig_provider?), contracts_acc,
events_acc}
{:error, reason} ->
{{:error, reason}, contracts_acc, events_acc}
end
end
@ -198,7 +189,7 @@ defmodule Explorer.Chain.Log do
end
end
defp find_method_candidates(log, transaction, options, events_acc, skip_sig_provider \\ false) do
defp find_method_candidates(log, transaction, options, events_acc, skip_sig_provider?) do
with "0x" <> hex_part <- log.first_topic,
{number, ""} <- Integer.parse(hex_part, 16) do
<<method_id::binary-size(4), _rest::binary>> = :binary.encode_unsigned(number)
@ -206,7 +197,7 @@ defmodule Explorer.Chain.Log do
if Map.has_key?(events_acc, method_id) do
{events_acc[method_id], events_acc}
else
result = find_method_candidates_from_db(method_id, log, transaction, options, events_acc, skip_sig_provider)
result = find_method_candidates_from_db(method_id, log, transaction, options, skip_sig_provider?)
{result, Map.put(events_acc, method_id, result)}
end
else
@ -214,7 +205,7 @@ defmodule Explorer.Chain.Log do
end
end
defp find_method_candidates_from_db(method_id, log, transaction, options, events_acc, skip_sig_provider \\ false) do
defp find_method_candidates_from_db(method_id, log, transaction, options, skip_sig_provider?) do
candidates_query = ContractMethod.find_contract_method_query(method_id, 3)
candidates =
@ -237,9 +228,9 @@ defmodule Explorer.Chain.Log do
{:error, :contract_not_verified,
if(candidates == [],
do:
if(skip_sig_provider,
if(skip_sig_provider?,
do: [],
else: decode_event_via_sig_provider(log, transaction, true, options, events_acc)
else: decode_event_via_sig_provider(log, transaction, true)
),
else: candidates
)}
@ -290,8 +281,6 @@ defmodule Explorer.Chain.Log do
log,
transaction,
only_candidates?,
options,
events_acc,
skip_sig_provider? \\ false
) do
with true <- SigProviderInterface.enabled?(),
@ -322,18 +311,7 @@ defmodule Explorer.Chain.Log do
if only_candidates? do
[]
else
skip_sig_provider = true
case find_method_candidates(log, transaction, options, events_acc, skip_sig_provider) do
{{:error, :contract_not_verified, []}, _} ->
{:error, :could_not_decode}
{{:error, :contract_not_verified, candidates}, _} ->
{:error, :contract_not_verified, candidates}
{_, _} ->
{:error, :could_not_decode}
end
{:error, :could_not_decode}
end
end
end

Loading…
Cancel
Save