Skip to content

Commit

Permalink
feat: display init for selfdestructed contracts.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed May 16, 2019
1 parent e1c7ef8 commit 6c85f8b
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 54 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- [#1876](https://github.com/poanetwork/blockscout/pull/1876) - async calculate a count of blocks
- [#1941](https://github.com/poanetwork/blockscout/pull/1941) - feat: add on demand fetching and stale attr to rpc
- [#1952](https://github.com/poanetwork/blockscout/pull/1952) - feat: exclude empty contracts by default
- [#1954](https://github.com/poanetwork/blockscout/pull/1954) - feat: use creation init on self destruct

### Fixes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<% contract_creation_code = contract_creation_code(@address) %>

<section class="container">
<%= render BlockScoutWeb.AddressView, "overview.html", assigns %>

<div class="card">
<%= render BlockScoutWeb.AddressView, "_tabs.html", assigns %>
<div class="card-body">
<%= if !BlockScoutWeb.AddressView.smart_contract_verified?(@address) do %>
<%= link(
gettext("Verify & Publish"),
to: address_verify_contract_path(@conn, :new, @address.hash),
class: "button button-primary button-sm float-right ml-3",
"data-test": "verify_and_publish"
) %>
<%= if match?({:selfdestructed, _}, contract_creation_code) do %>
<div class="button button-disabled button-sm float-right ml-3">
<%= gettext("Verify & Publish") %>
</div>
<% else %>
<%= if !BlockScoutWeb.AddressView.smart_contract_verified?(@address) do %>
<%= link(
gettext("Verify & Publish"),
to: address_verify_contract_path(@conn, :new, @address.hash),
class: "button button-primary button-sm float-right ml-3",
"data-test": "verify_and_publish"
) %>
<% end %>
<% end %>

<%= if BlockScoutWeb.AddressView.smart_contract_verified?(@address) do %>
<div class="mb-4">
<dl class="row">
Expand Down Expand Up @@ -56,15 +63,32 @@

<% end %>
<section>
<div class="d-flex justify-content-between align-items-baseline">
<h3><%= gettext "Contract creation code" %></h3>
<button type="button" class="button button-secondary button-sm" id="button" data-clipboard-text="<%= @address.contract_code %>" aria-label="copy contract creation code">
<%= gettext "Copy Contract Creation Code" %>
</button>
</div>
<div class="tile tile-muted">
<pre class="pre-wrap pre-scrollable"><code class="nohighlight"><%= @address.contract_code %></code></pre>
</div>
<%= case contract_creation_code do %>
<% {:selfdestructed, transaction_init} -> %>
<div class="d-flex justify-content-between align-items-baseline">
<h3><%= gettext "Contract Creation Code" %></h3>
<button type="button" class="button button-secondary button-sm" id="button" data-clipboard-text="<%= transaction_init %>" aria-label="copy contract creation code">
<%= gettext "Copy Contract Creation Code" %>
</button>
</div>
<div class="alert alert-info">
<p><%= gettext "Contracts that self destruct in their constructors have no contract code published and cannot be verified." %></p>
<p><%= gettext "Displaying the init data provided of the creating transaction." %></p>
</div>
<div class="tile tile-muted">
<pre class="pre-wrap pre-scrollable"><code class="nohighlight"><%= transaction_init %></code></pre>
</div>
<% {:ok, contract_code} -> %>
<div class="d-flex justify-content-between align-items-baseline">
<h3><%= gettext "Contract Byte Code" %></h3>
<button type="button" class="button button-secondary button-sm" id="button" data-clipboard-text="<%= contract_code %>" aria-label="copy contract creation code">
<%= gettext "Copy Contract Byte Code" %>
</button>
</div>
<div class="tile tile-muted">
<pre class="pre-wrap pre-scrollable"><code class="nohighlight"><%= contract_code %></code></pre>
</div>
<% end %>
</section>

</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule BlockScoutWeb.AddressContractView do
use BlockScoutWeb, :view

alias Explorer.Chain.{Address, Data, InternalTransaction}

def render("scripts.html", %{conn: conn}) do
render_scripts(conn, "address_contract/code_highlighting.js")
end
Expand Down Expand Up @@ -34,4 +36,15 @@ defmodule BlockScoutWeb.AddressContractView do
{value, String.pad_leading(to_string(line), max_digits, " ")}
end)
end

def contract_creation_code(%Address{
contract_code: %Data{bytes: <<>>},
contracts_creation_internal_transaction: %InternalTransaction{init: init}
}) do
{:selfdestructed, init}
end

def contract_creation_code(%Address{contract_code: contract_code}) do
{:ok, contract_code}
end
end
53 changes: 37 additions & 16 deletions apps/block_scout_web/priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ msgid "Compiler"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:23
#: lib/block_scout_web/templates/address_contract/index.html.eex:30
msgid "Compiler version"
msgstr ""

Expand Down Expand Up @@ -256,7 +256,7 @@ msgid "Connection Lost, click to load newer validations"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:46
#: lib/block_scout_web/templates/address_contract/index.html.eex:53
msgid "Contract ABI"
msgstr ""

Expand Down Expand Up @@ -289,17 +289,12 @@ msgid "Contract Name"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:60
msgid "Contract creation code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:19
#: lib/block_scout_web/templates/address_contract/index.html.eex:26
msgid "Contract name:"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:34
#: lib/block_scout_web/templates/address_contract/index.html.eex:41
msgid "Contract source code"
msgstr ""

Expand Down Expand Up @@ -621,7 +616,7 @@ msgid "Older"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:27
#: lib/block_scout_web/templates/address_contract/index.html.eex:34
msgid "Optimization enabled"
msgstr ""

Expand Down Expand Up @@ -982,7 +977,8 @@ msgid "Value"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:9
#: lib/block_scout_web/templates/address_contract/index.html.eex:11
#: lib/block_scout_web/templates/address_contract/index.html.eex:16
msgid "Verify & Publish"
msgstr ""

Expand Down Expand Up @@ -1047,7 +1043,7 @@ msgid "at"
msgstr ""

#, elixir-format
#: lib/block_scout_web/views/address_contract_view.ex:20
#: lib/block_scout_web/views/address_contract_view.ex:22
msgid "false"
msgstr ""

Expand All @@ -1065,7 +1061,7 @@ msgid "string"
msgstr ""

#, elixir-format
#: lib/block_scout_web/views/address_contract_view.ex:19
#: lib/block_scout_web/views/address_contract_view.ex:21
msgid "true"
msgstr ""

Expand Down Expand Up @@ -1509,17 +1505,17 @@ msgid "Support"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:48
#: lib/block_scout_web/templates/address_contract/index.html.eex:55
msgid "Copy ABI"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:62
#: lib/block_scout_web/templates/address_contract/index.html.eex:71
msgid "Copy Contract Creation Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:36
#: lib/block_scout_web/templates/address_contract/index.html.eex:43
msgid "Copy Source Code"
msgstr ""

Expand Down Expand Up @@ -1745,3 +1741,28 @@ msgstr ""
#: lib/block_scout_web/templates/common_components/_pagination_container.html.eex:37
msgid "of"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:83
msgid "Contract Byte Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:69
msgid "Contract Creation Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:75
msgid "Contracts that self destruct in their constructors have no contract code published and cannot be verified."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:85
msgid "Copy Contract Byte Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:76
msgid "Displaying the init data provided of the creating transaction."
msgstr ""
57 changes: 39 additions & 18 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ msgid "Compiler"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:23
#: lib/block_scout_web/templates/address_contract/index.html.eex:30
msgid "Compiler version"
msgstr ""

Expand Down Expand Up @@ -256,7 +256,7 @@ msgid "Connection Lost, click to load newer validations"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:46
#: lib/block_scout_web/templates/address_contract/index.html.eex:53
msgid "Contract ABI"
msgstr ""

Expand Down Expand Up @@ -289,17 +289,12 @@ msgid "Contract Name"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:60
msgid "Contract creation code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:19
#: lib/block_scout_web/templates/address_contract/index.html.eex:26
msgid "Contract name:"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:34
#: lib/block_scout_web/templates/address_contract/index.html.eex:41
msgid "Contract source code"
msgstr ""

Expand Down Expand Up @@ -621,7 +616,7 @@ msgid "Older"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:27
#: lib/block_scout_web/templates/address_contract/index.html.eex:34
msgid "Optimization enabled"
msgstr ""

Expand Down Expand Up @@ -982,7 +977,8 @@ msgid "Value"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:9
#: lib/block_scout_web/templates/address_contract/index.html.eex:11
#: lib/block_scout_web/templates/address_contract/index.html.eex:16
msgid "Verify & Publish"
msgstr ""

Expand Down Expand Up @@ -1047,7 +1043,7 @@ msgid "at"
msgstr ""

#, elixir-format
#: lib/block_scout_web/views/address_contract_view.ex:20
#: lib/block_scout_web/views/address_contract_view.ex:22
msgid "false"
msgstr ""

Expand All @@ -1065,7 +1061,7 @@ msgid "string"
msgstr ""

#, elixir-format
#: lib/block_scout_web/views/address_contract_view.ex:19
#: lib/block_scout_web/views/address_contract_view.ex:21
msgid "true"
msgstr ""

Expand Down Expand Up @@ -1357,7 +1353,7 @@ msgid "Loading balances"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_coin_balance/index.html.eex:23
#: lib/block_scout_web/templates/address_coin_balance/index.html.eex:22
#: lib/block_scout_web/templates/chain/show.html.eex:13
msgid "Loading chart"
msgstr ""
Expand All @@ -1368,7 +1364,7 @@ msgid "There is no coin history for this address."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_coin_balance/index.html.eex:26
#: lib/block_scout_web/templates/address_coin_balance/index.html.eex:25
#: lib/block_scout_web/templates/chain/show.html.eex:16
msgid "There was a problem loading the chart."
msgstr ""
Expand Down Expand Up @@ -1509,17 +1505,17 @@ msgid "Support"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:48
#: lib/block_scout_web/templates/address_contract/index.html.eex:55
msgid "Copy ABI"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:62
#: lib/block_scout_web/templates/address_contract/index.html.eex:71
msgid "Copy Contract Creation Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:36
#: lib/block_scout_web/templates/address_contract/index.html.eex:43
msgid "Copy Source Code"
msgstr ""

Expand Down Expand Up @@ -1745,3 +1741,28 @@ msgstr ""
#: lib/block_scout_web/templates/common_components/_pagination_container.html.eex:37
msgid "of"
msgstr ""

#, elixir-format, fuzzy
#: lib/block_scout_web/templates/address_contract/index.html.eex:83
msgid "Contract Byte Code"
msgstr ""

#, elixir-format, fuzzy
#: lib/block_scout_web/templates/address_contract/index.html.eex:69
msgid "Contract Creation Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:75
msgid "Contracts that self destruct in their constructors have no contract code published and cannot be verified."
msgstr ""

#, elixir-format, fuzzy
#: lib/block_scout_web/templates/address_contract/index.html.eex:85
msgid "Copy Contract Byte Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:76
msgid "Displaying the init data provided of the creating transaction."
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Explorer.Chain.InternalTransaction.Result do
{key, to_string(hash)}
end

defp entry_to_raw({"code", _} = entry), do: entry
defp entry_to_raw({"code", code}), do: {"code", Data.to_string(code)}

defp entry_to_raw({key, decimal}) when key in ~w(gasUsed) do
integer =
Expand Down
Loading

0 comments on commit 6c85f8b

Please sign in to comment.