Skip to content

Commit

Permalink
feat: decoding candidates for unverified contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Mar 4, 2019
1 parent 1908097 commit 48f363e
Show file tree
Hide file tree
Showing 14 changed files with 365 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,34 @@
<h1 class="card-title"><%= gettext "Input" %> </h1>
<!-- Input -->
<%= case @decoded_input_data do %>
<% {:error, :contract_not_verified} -> %>
<% {:error, :contract_not_verified, candidates} -> %>
<div class="alert alert-info">
<%= gettext "To see decoded input data, the contract must be verified." %>
<%= gettext "To see accurate decoded input data, the contract must be verified." %>
<%= case @transaction do %>
<% %{to_address: %{hash: hash}} -> %>
<%= gettext "Verify the contract " %><a href="<%= address_verify_contract_path(@conn, :new, hash)%>"><%= gettext "here" %></a>
<% _ -> %>
<%= nil %>
<% end %>
</div>
<% {:ok, method_id, text, mapping} -> %>
<table summary="<%= gettext "Transaction Info" %>" class="table thead-light table-bordered table-responsive transaction-info-table">
<tr>
<td><%= gettext "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>
<%= unless Enum.empty?(candidates) do %>
<h3><%= gettext "Potential matches from our contract method database:" %></h3>
<%= gettext "IMPORTANT: This information is a best guess based on similar functions from other verified contracts." %>
<%= gettext "To have guaranteed accuracy, use the link above to verify the contract's source code." %>

<table summary="<%= gettext "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>
<th scope="row">
<%= case BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) do %>
<% :error -> %>
<%= nil %>
<% copy_text -> %>
<button type="button" class="copy icon-link" data-toggle="tooltip" data-placement="top" data-clipboard-text="<%= copy_text %>" aria-label="<%= gettext "Copy Value" %>">
<i class="fas fa-clone"></i>
</button>
<% end %>
</th>
<td><%= name %></td>
<td><%= type %></td>
<td>
<%= case BlockScoutWeb.ABIEncodedValueView.value_html(type, value) do %>
<% :error -> %>
<div class="alert alert-danger">
<%= gettext "Error rendering value" %>
</div>
<% value -> %>
<pre class="transaction-input-text tile"><code><%= value %></code></pre>
<% end %>
<%= for {:ok, method_id, text, mapping} <- candidates do %>
<hr>
<h3><%= text %>: </h3>

</td>
</tr>
<% end %>
</table>
<%= render(BlockScoutWeb.TransactionView, "_decoded_input_body.html", method_id: method_id, text: text, mapping: mapping) %>
<% end %>
<% end %>
<% {:ok, method_id, text, mapping} -> %>
<%= render(BlockScoutWeb.TransactionView, "_decoded_input_body.html", method_id: method_id, text: text, mapping: mapping) %>
<% _ -> %>
<div class="alert alert-danger">
<%= gettext "Failed to decode input data." %>
</div>
<% end %>
<% end %>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<table summary="<%= gettext "Transaction Info" %>" class="table thead-light table-bordered table-responsive transaction-info-table">
<tr>
<td><%= gettext "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>

<%= unless Enum.empty?(@mapping) do %>
<table summary="<%= gettext "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>
<th scope="row">
<%= case BlockScoutWeb.ABIEncodedValueView.copy_text(type, value) do %>
<% :error -> %>
<%= nil %>
<% copy_text -> %>
<button type="button" class="copy icon-link" data-toggle="tooltip" data-placement="top" data-clipboard-text="<%= copy_text %>" aria-label="<%= gettext "Copy Value" %>">
<i class="fas fa-clone"></i>
</button>
<% end %>
</th>
<td><%= name %></td>
<td><%= type %></td>
<td>
<%= case BlockScoutWeb.ABIEncodedValueView.value_html(type, value) do %>
<% :error -> %>
<div class="alert alert-danger">
<%= gettext "Error rendering value" %>
</div>
<% value -> %>
<pre class="transaction-input-text tile"><code><%= value %></code></pre>
<% end %>
</td>
</tr>
<% end %>
</table>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
</div>
</div>

<%= unless should_decode?(@transaction) do %>
<%= unless skip_decoding?(@transaction) do %>
<div class="row">
<div class="col-md-12">
<%= render BlockScoutWeb.TransactionView, "_decoded_input.html", Map.put(assigns, :decoded_input_data, decoded_input_data) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ defmodule BlockScoutWeb.TransactionView do
Cldr.Number.to_string!(gas)
end

def should_decode?(transaction) do
def skip_decoding?(transaction) do
contract_creation?(transaction) || value_transfer?(transaction)
end

Expand Down
39 changes: 29 additions & 10 deletions apps/block_scout_web/priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ msgid "Curl"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:33
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:18
#: lib/block_scout_web/templates/transaction_log/index.html.eex:60
#: lib/block_scout_web/templates/transaction_log/index.html.eex:118
msgid "Data"
Expand Down Expand Up @@ -574,7 +574,7 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:29
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:31
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:16
#: lib/block_scout_web/templates/transaction_log/index.html.eex:57
msgid "Name"
msgstr ""
Expand Down Expand Up @@ -1305,29 +1305,28 @@ msgid "Indexed?"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:32
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:17
#: lib/block_scout_web/templates/transaction_log/index.html.eex:58
msgid "Type"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:19
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:3
msgid "Method Id"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:8
#: lib/block_scout_web/templates/transaction_log/index.html.eex:31
msgid "To see decoded input data, the contract must be verified."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:17
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:1
msgid "Transaction Info"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:28
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:13
msgid "Transaction Inputs"
msgstr ""

Expand All @@ -1344,17 +1343,17 @@ msgid "here"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:65
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:32
msgid "Failed to decode input data."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:53
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:38
msgid "Error rendering value"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:42
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:27
#: lib/block_scout_web/templates/transaction_log/index.html.eex:69
msgid "Copy Value"
msgstr ""
Expand Down Expand Up @@ -1492,6 +1491,26 @@ msgstr ""
msgid "Uncle Reward"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:18
msgid "IMPORTANT: This information is a best guess based on similar functions from other verified contracts."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:17
msgid "Potential matches from our contract method database:"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:19
msgid "To have guaranteed accuracy, use the link above to verify the contract's source code."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:8
msgid "To see accurate decoded input data, the contract must be verified."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:5
msgid "Emission Contract"
Expand Down
39 changes: 29 additions & 10 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ msgid "Curl"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:33
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:18
#: lib/block_scout_web/templates/transaction_log/index.html.eex:60
#: lib/block_scout_web/templates/transaction_log/index.html.eex:118
msgid "Data"
Expand Down Expand Up @@ -574,7 +574,7 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:29
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:31
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:16
#: lib/block_scout_web/templates/transaction_log/index.html.eex:57
msgid "Name"
msgstr ""
Expand Down Expand Up @@ -1305,29 +1305,28 @@ msgid "Indexed?"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:32
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:17
#: lib/block_scout_web/templates/transaction_log/index.html.eex:58
msgid "Type"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:19
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:3
msgid "Method Id"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:8
#: lib/block_scout_web/templates/transaction_log/index.html.eex:31
msgid "To see decoded input data, the contract must be verified."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:17
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:1
msgid "Transaction Info"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:28
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:13
msgid "Transaction Inputs"
msgstr ""

Expand All @@ -1344,17 +1343,17 @@ msgid "here"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:65
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:32
msgid "Failed to decode input data."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:53
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:38
msgid "Error rendering value"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:42
#: lib/block_scout_web/templates/transaction/_decoded_input_body.html.eex:27
#: lib/block_scout_web/templates/transaction_log/index.html.eex:69
msgid "Copy Value"
msgstr ""
Expand Down Expand Up @@ -1492,6 +1491,26 @@ msgstr ""
msgid "Uncle Reward"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:18
msgid "IMPORTANT: This information is a best guess based on similar functions from other verified contracts."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:17
msgid "Potential matches from our contract method database:"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:19
msgid "To have guaranteed accuracy, use the link above to verify the contract's source code."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_decoded_input.html.eex:8
msgid "To see accurate decoded input data, the contract must be verified."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:5
msgid "Emission Contract"
Expand Down
Loading

0 comments on commit 48f363e

Please sign in to comment.