Skip to content

Commit

Permalink
feat: fix ABI decodding, and decode tx logs
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Nov 20, 2018
1 parent 4432ba4 commit 21a1c14
Show file tree
Hide file tree
Showing 9 changed files with 442 additions and 122 deletions.
25 changes: 21 additions & 4 deletions apps/block_scout_web/assets/css/components/_transaction-input.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
.raw-transaction-input{
display: none;
display: none;
}

.raw-transaction-log-topics{
display: none;
}

.raw-transaction-log-data{
display: none;
}

.transaction-input-text{
resize: vertical;
overflow: auto;
word-break: break-all;
white-space: pre;
color: black;

pre{
code{
color: black;
}
}
}

.transaction-input-table{
overflow-x: scroll;
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,102 +75,75 @@
</dl>

<!-- Input -->
<dl class="row mb-0">
<%= case decoded_input_data(@transaction) do %>
<% {:error, :contract_not_verified} -> %>
<dt class="col-sm-3 text-muted"> <%= gettext "Input" %> </dt>
<dd class="col-sm-9">
<div class="alert alert-danger">
To see decoded input data, the <a href="<%= address_verify_contract_path(@conn, :new, @transaction.to_address.hash)%>">contract must be verified.</a>
</div>
</dd>
<% {:error, :could_not_decode} -> %>
<dt class="col-sm-3 text-muted"> <%= gettext "Input" %> </dt>
<dd class="col-sm-9">
<div class="alert alert-danger">
Failed to decode input data. Some dynamic types are not currently supported.
</div>
</dd>
<% {:ok, method_id, text, mapping} -> %>
<dt class="col-sm-3 text-muted"> <%= gettext "Input" %> </dt>
<dd class="col-sm-9">
<table summary="Transaction Info" class="table thead-light table-bordered">
<tr>
<td>Method Id</td>
<td colspan="3"><code>0x<%= method_id %></code></td>
</tr>
<h3 class="text-muted"><%= gettext "Input" %></h3>
<%= case decoded_input_data(@transaction) do %>
<% {:error, :contract_not_verified} -> %>
<div class="alert alert-danger">
To see decoded input data, the <a href="<%= address_verify_contract_path(@conn, :new, @transaction.to_address.hash)%>" target="_blank">contract must be verified.</a>
</div>
<% {:error, :could_not_decode} -> %>
<div class="alert alert-danger">
Failed to decode input data. Some dynamic types are not currently supported.
</div>
<% {:ok, method_id, text, mapping} -> %>
<table summary="Transaction Info" class="table thead-light table-bordered table-responsive transaction-info-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>

<table summary="Transaction Inputs" class="table thead-light table-bordered table-responsive">
<tr>
<th scope="col"></th>
<th scope="col"><%= gettext "Name" %></th>
<th scope="col"><%= gettext "Type" %></th>
<th scope="col"><%= gettext "Data" %></th>
<tr>
<%= for {name, type, value} <- mapping do %>
<tr>
<td>Call</td>
<td colspan="3"><code><%= text %></code></td>
<th scope="row">
<% copy_text = BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) %>
<button type="button" class="copy icon-link" data-toggle="tooltip" data-placement="top" data-clipboard-text="<%= copy_text %>" aria-label="Copy Value">
<i class="fas fa-clone"></i>
</button>
</th>
<td><%= name %></td>
<td><%= type %></td>
<td>
<pre class="transaction-input-text tile"><code><%= BlockScoutWeb.ABIEncodedValueView.value_html(type, value) %></code></pre>
</td>
</tr>
</table>
<table summary="Transaction Inputs" class="table thead-light table-bordered table-responsive">
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Type</th>
<th scope="col">Data</th>
<th scope="col"></th>
<tr>
<%= for {{name, type, value}, index} <- Enum.with_index(mapping) do %>
<tr>
<th scope="row"><%= index %></th>
<td><%= name %></td>
<td><%= type %></td>
<%= case type do %>
<% "address" -> %>
<% address = "0x" <> Base.encode16(value, case: :lower) %>
<td>
<div class="transaction-input-text">
<a href="<%= address_path(@conn, :show, address) %>" target="_blank"> <%= address %> </a>
</div>
</td>
<td>
<button type="button" class="copy" id="button" data-toggle="tooltip" data-placement="top" data-clipboard-text="<%= address %>" aria-label="Copy Value">
<%= gettext "copy"%>
</button>
</td>
<% end %>
</table>
<% _ -> %>
<%= nil %>
<% end %>

<% _ -> %>
<td>
<div class="transaction-input-text"><%= value %></textarea>
</td>
<td>
<button type="button" class="copy" id="button" data-toggle="tooltip" data-placement="top" data-clipboard-text="<%= value %>" aria-label="Copy Value">
<%= gettext "copy"%>
</button>
</td>
<% end %>
</tr>
<% end %>
</table>
</dd>
<% _ -> %>
<%= nil %>
<% end %>
<%= unless @transaction.input.bytes in [<<>>, nil] do %>
<h3 class="text-muted"><%= gettext "Raw Input" %></h3>
<div swappable-item>
<button swapper class="button button-primary"><%= gettext "Show Raw Input"%></button>
</div>
<div swappable-item class="raw-transaction-input">
<button swapper type="button" class="close pr-2" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<button type="button" class="copy icon-link mb-1" data-toggle="tooltip" data-placement="top" data-clipboard-text="<%= @transaction.input %>" aria-label="Copy Value">
<i class="fas fa-clone"></i>
</button>

<%= unless @transaction.input.bytes in [<<>>, nil] do %>
<dt class="col-sm-3 text-muted"><%= gettext "Raw Input" %></dt>
<dd class="col-sm-9">
<div swappable-item>
<button swapper class="button button-primary"><%= gettext "Show Raw Input"%></button>
<div class="tile tile-muted">
<pre class="pre-scrollable pre-scrollable-shorty pre-wrap mb-0">
<code><%= @transaction.input %></code>
</pre>
</div>
<div swappable-item class="raw-transaction-input">
<button swapper type="button" class="close pr-2" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<div class="tile tile-muted">
<button type="button" class="copy" id="button" data-toggle="tooltip" data-placement="top" data-clipboard-text="<%= @transaction.input %>" aria-label="Copy Value">
<%= gettext "copy"%>
</button>
<pre class="pre-scrollable pre-scrollable-shorty pre-wrap mb-0">
<code><%= @transaction.input %></code>
</pre>
</div>
</div>
</dd>
<% end %>
</dl>
</div>
<% end %>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,105 @@
) %>
</h3>
</dd>
<dt class="col-md-1"><%= gettext "Topics" %></dt>
<dt class="col-md-1"><%= gettext "Decoded" %></dt>
<dd class="col-md-11">
<%= unless is_nil(log.first_topic) do %>
<div class="text-dark">
<span class="text-dark">[0]</span>
<%= log.first_topic %>
</div>
<% end %>
<%= unless is_nil(log.second_topic) do %>
<div class="text-dark">
<span class="">[1] </span>
<%= log.second_topic %>
</div>
<% end %>
<%= unless is_nil(log.third_topic) do %>
<div class="text-dark">
<span>[2]</span>
<%= log.third_topic %>
</div>
<% end %>
<%= unless is_nil(log.fourth_topic) do %>
<div class="text-dark">
<span>[3]</span>
<%= log.fourth_topic %>
</div>
<%= case decode(log, @transaction) do %>
<% {:error, :contract_not_verified} -> %>
<div class="alert alert-danger">
To see decoded input data, the <a href="<%= address_verify_contract_path(@conn, :new, @transaction.to_address.hash)%>" target="_blank">contract must be verified.</a>
</div>
<% {:error, :could_not_decode} -> %>
<div class="alert alert-danger">
Failed to decode log data.
</div>
<% {:ok, method_id, text, mapping} -> %>
<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>
<table style="color: black;" summary="Log Data" class="table thead-light table-bordered table-responsive">
<tr>
<th scope="col"></th>
<th scope="col"><%= gettext "Name" %></th>
<th scope="col"><%= gettext "Type" %></th>
<th scope="col"><%= gettext "Indexed?" %></th>
<th scope="col"><%= gettext "Data" %></th>
<tr>
<%= for {name, type, indexed?, value} <- mapping do %>
<tr>
<th scope="row">
<% copy_text = BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) %>

<button type="button" class="copy icon-link" data-toggle="tooltip" data-placement="top" data-clipboard-text="<%= copy_text %>" aria-label="Copy Value">
<i class="fas fa-clone"></i>
</button>
</th>
<td><%= name %></td>
<td><%= type %></td>
<td><%= indexed? %></td>
<td>
<pre class="transaction-input-text tile"><code><%= BlockScoutWeb.ABIEncodedValueView.value_html(type, value) %></code></pre>
</td>
</tr>
<% end %>
</table>
<% end %>

</dd>
<dt class="col-md-1"><%= gettext "Topics" %></dt>
<dd class="col-md-11">
<div swappable-item>
<button swapper class="button button-primary"><%= gettext "Show Raw Topics"%></button>
</div>
<div swappable-item class="raw-transaction-log-topics">
<button swapper type="button" class="close pr-2" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<%= unless is_nil(log.first_topic) do %>
<div class="text-dark">
<span class="text-dark">[0]</span>
<%= log.first_topic %>
</div>
<% end %>
<%= unless is_nil(log.second_topic) do %>
<div class="text-dark">
<span class="">[1] </span>
<%= log.second_topic %>
</div>
<% end %>
<%= unless is_nil(log.third_topic) do %>
<div class="text-dark">
<span>[2]</span>
<%= log.third_topic %>
</div>
<% end %>
<%= unless is_nil(log.fourth_topic) do %>
<div class="text-dark">
<span>[3]</span>
<%= log.fourth_topic %>
</div>
<% end %>
</div>
</dd>
<dt class="col-md-1">
<%= gettext "Data" %>
</dt>
<dd class="col-md-11">
<%= unless is_nil(log.data) do %>
<div class="text-dark">
<div swappable-item>
<button swapper class="button button-primary"><%= gettext "Show Raw Data"%></button>
</div>

<div swappable-item class="text-dark raw-transaction-log-data">
<button swapper type="button" class="close pr-2" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<%= log.data %>
</div>
<% end %>
Expand Down
Loading

0 comments on commit 21a1c14

Please sign in to comment.