Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show only the last decompiled contract #2118

Merged
merged 6 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

### Chore
- [#2127](https://github.com/poanetwork/blockscout/pull/2127) - use previouse chromedriver version
- [#2118](https://github.com/poanetwork/blockscout/pull/2118) - show only the last decompiled contract

### Chore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<%= render BlockScoutWeb.AddressView, "overview.html", assigns %>
<div class="card">
<%= render BlockScoutWeb.AddressView, "_tabs.html", assigns %>
<%= for contract <- sort_contracts_by_version(@address.decompiled_smart_contracts) do %>
<% contract = last_decompiled_contract_version(@address.decompiled_smart_contracts) %>
<%= if contract do %>
<div class="card-body">
<h3><%= gettext "Decompiler version" %></h3>
<div class="tile tile-muted">
Expand All @@ -21,6 +22,10 @@
</div>
</section>
</div>
<% else %>
<div class="tile tile-muted text-center">
<%= gettext "There is no decompilded contracts for this address." %>
</div>
<% end %>
</div>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ defmodule BlockScoutWeb.AddressDecompiledContractView do
end)
end

def sort_contracts_by_version(decompiled_contracts) do
decompiled_contracts
|> Enum.sort_by(& &1.decompiler_version)
|> Enum.reverse()
def last_decompiled_contract_version(decompiled_contracts) do
Enum.max_by(decompiled_contracts, & &1.decompiler_version)
end

defp add_line_numbers(code) do
Expand Down
11 changes: 8 additions & 3 deletions apps/block_scout_web/priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ msgid "EVM Version"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:16
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:17
msgid "Copy Decompiled Contract Code"
msgstr ""

Expand All @@ -1505,12 +1505,12 @@ msgid "Decompiled code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:14
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:15
msgid "Decompiled contract code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:7
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:8
msgid "Decompiler version"
msgstr ""

Expand Down Expand Up @@ -1697,3 +1697,8 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/overview.html.eex:178
msgid " Token Transfer"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27
msgid "There is no decompilded contracts for this address."
msgstr ""
13 changes: 9 additions & 4 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ msgid "EVM Version"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:16
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:17
msgid "Copy Decompiled Contract Code"
msgstr ""

Expand All @@ -1505,12 +1505,12 @@ msgid "Decompiled code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:14
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:15
msgid "Decompiled contract code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:7
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:8
msgid "Decompiler version"
msgstr ""

Expand Down Expand Up @@ -1693,7 +1693,12 @@ msgstr ""
msgid "New Smart Contract Verification"
msgstr ""

#, elixir-format, fuzzy
#, elixir-format
#: lib/block_scout_web/templates/transaction/overview.html.eex:178
msgid " Token Transfer"
msgstr ""

#, elixir-format, fuzzy
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27
msgid "There is no decompilded contracts for this address."
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ defmodule BlockScoutWeb.AddressDecompiledContractViewTest do
end
end

describe "sort_contracts_by_version/1" do
test "sorts contracts in lexicographical order" do
describe "last_decompiled_contract_version/1" do
test "returns last version" do
contract2 = insert(:decompiled_smart_contract, decompiler_version: "v2")
contract1 = insert(:decompiled_smart_contract, decompiler_version: "v1")
contract3 = insert(:decompiled_smart_contract, decompiler_version: "v3")

result = AddressDecompiledContractView.sort_contracts_by_version([contract2, contract1, contract3])
result = AddressDecompiledContractView.last_decompiled_contract_version([contract2, contract1, contract3])

assert result == [contract3, contract2, contract1]
assert result == contract3
end
end
end