Merge remote-tracking branch 'origin/master' into allowed-evm-versions

pull/1964/head
Victor Baranov 6 years ago
commit 25905adf97
  1. 2
      CHANGELOG.md
  2. 32
      apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex
  3. 13
      apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex
  4. 53
      apps/block_scout_web/priv/gettext/default.pot
  5. 53
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  6. 18
      apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex
  7. 2
      apps/explorer/lib/explorer/chain/internal_transaction/result.ex
  8. 86
      apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs
  9. 4
      apps/explorer/test/explorer/chain/internal_transaction_test.exs
  10. 20
      apps/explorer/test/support/factory.ex

@ -22,9 +22,11 @@
- [#1920](https://github.com/poanetwork/blockscout/pull/1920) - fix: remove source code fields from list endpoint - [#1920](https://github.com/poanetwork/blockscout/pull/1920) - fix: remove source code fields from list endpoint
- [#1876](https://github.com/poanetwork/blockscout/pull/1876) - async calculate a count of blocks - [#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 - [#1941](https://github.com/poanetwork/blockscout/pull/1941) - feat: add on demand fetching and stale attr to rpc
- [#1957](https://github.com/poanetwork/blockscout/pull/1957) - Calculate stakes ratio before insert pools
- [#1956](https://github.com/poanetwork/blockscout/pull/1956) - add logs tab to address - [#1956](https://github.com/poanetwork/blockscout/pull/1956) - add logs tab to address
- [#1933](https://github.com/poanetwork/blockscout/pull/1933) - add eth_BlockNumber json rpc method - [#1933](https://github.com/poanetwork/blockscout/pull/1933) - add eth_BlockNumber json rpc method
- [#1952](https://github.com/poanetwork/blockscout/pull/1952) - feat: exclude empty contracts by default - [#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 ### Fixes

@ -1,9 +1,16 @@
<% contract_creation_code = contract_creation_code(@address) %>
<section class="container"> <section class="container">
<%= render BlockScoutWeb.AddressView, "overview.html", assigns %> <%= render BlockScoutWeb.AddressView, "overview.html", assigns %>
<div class="card"> <div class="card">
<%= render BlockScoutWeb.AddressView, "_tabs.html", assigns %> <%= render BlockScoutWeb.AddressView, "_tabs.html", assigns %>
<div class="card-body"> <div class="card-body">
<%= 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 %> <%= if !BlockScoutWeb.AddressView.smart_contract_verified?(@address) do %>
<%= link( <%= link(
gettext("Verify & Publish"), gettext("Verify & Publish"),
@ -12,7 +19,7 @@
"data-test": "verify_and_publish" "data-test": "verify_and_publish"
) %> ) %>
<% end %> <% end %>
<% end %>
<%= if BlockScoutWeb.AddressView.smart_contract_verified?(@address) do %> <%= if BlockScoutWeb.AddressView.smart_contract_verified?(@address) do %>
<div class="mb-4"> <div class="mb-4">
<dl class="row"> <dl class="row">
@ -56,15 +63,32 @@
<% end %> <% end %>
<section> <section>
<%= case contract_creation_code do %>
<% {:selfdestructed, transaction_init} -> %>
<div class="d-flex justify-content-between align-items-baseline"> <div class="d-flex justify-content-between align-items-baseline">
<h3><%= gettext "Contract creation code" %></h3> <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"> <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" %> <%= gettext "Copy Contract Creation Code" %>
</button> </button>
</div> </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"> <div class="tile tile-muted">
<pre class="pre-wrap pre-scrollable"><code class="nohighlight"><%= @address.contract_code %></code></pre> <pre class="pre-wrap pre-scrollable"><code class="nohighlight"><%= transaction_init %></code></pre>
</div> </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> </section>
</div> </div>

@ -1,6 +1,8 @@
defmodule BlockScoutWeb.AddressContractView do defmodule BlockScoutWeb.AddressContractView do
use BlockScoutWeb, :view use BlockScoutWeb, :view
alias Explorer.Chain.{Address, Data, InternalTransaction}
def render("scripts.html", %{conn: conn}) do def render("scripts.html", %{conn: conn}) do
render_scripts(conn, "address_contract/code_highlighting.js") render_scripts(conn, "address_contract/code_highlighting.js")
end end
@ -34,4 +36,15 @@ defmodule BlockScoutWeb.AddressContractView do
{value, String.pad_leading(to_string(line), max_digits, " ")} {value, String.pad_leading(to_string(line), max_digits, " ")}
end) end)
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 end

@ -228,7 +228,7 @@ msgid "Compiler"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Compiler version"
msgstr "" msgstr ""
@ -256,7 +256,7 @@ msgid "Connection Lost, click to load newer validations"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Contract ABI"
msgstr "" msgstr ""
@ -289,17 +289,12 @@ msgid "Contract Name"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:60 #: lib/block_scout_web/templates/address_contract/index.html.eex:26
msgid "Contract creation code"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:19
msgid "Contract name:" msgid "Contract name:"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Contract source code"
msgstr "" msgstr ""
@ -625,7 +620,7 @@ msgid "Older"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Optimization enabled"
msgstr "" msgstr ""
@ -988,7 +983,8 @@ msgid "Value"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Verify & Publish"
msgstr "" msgstr ""
@ -1053,7 +1049,7 @@ msgid "at"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/address_contract_view.ex:20 #: lib/block_scout_web/views/address_contract_view.ex:22
msgid "false" msgid "false"
msgstr "" msgstr ""
@ -1071,7 +1067,7 @@ msgid "string"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/address_contract_view.ex:19 #: lib/block_scout_web/views/address_contract_view.ex:21
msgid "true" msgid "true"
msgstr "" msgstr ""
@ -1515,17 +1511,17 @@ msgid "Support"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Copy ABI"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Copy Contract Creation Code"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Copy Source Code"
msgstr "" msgstr ""
@ -1752,6 +1748,31 @@ msgstr ""
msgid "of" msgid "of"
msgstr "" 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 ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address_logs/index.html.eex:77 #: lib/block_scout_web/templates/address_logs/index.html.eex:77
msgid "There are no logs for this address." msgid "There are no logs for this address."

@ -228,7 +228,7 @@ msgid "Compiler"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Compiler version"
msgstr "" msgstr ""
@ -256,7 +256,7 @@ msgid "Connection Lost, click to load newer validations"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Contract ABI"
msgstr "" msgstr ""
@ -289,17 +289,12 @@ msgid "Contract Name"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:60 #: lib/block_scout_web/templates/address_contract/index.html.eex:26
msgid "Contract creation code"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address_contract/index.html.eex:19
msgid "Contract name:" msgid "Contract name:"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Contract source code"
msgstr "" msgstr ""
@ -625,7 +620,7 @@ msgid "Older"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Optimization enabled"
msgstr "" msgstr ""
@ -988,7 +983,8 @@ msgid "Value"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Verify & Publish"
msgstr "" msgstr ""
@ -1053,7 +1049,7 @@ msgid "at"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/address_contract_view.ex:20 #: lib/block_scout_web/views/address_contract_view.ex:22
msgid "false" msgid "false"
msgstr "" msgstr ""
@ -1071,7 +1067,7 @@ msgid "string"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/views/address_contract_view.ex:19 #: lib/block_scout_web/views/address_contract_view.ex:21
msgid "true" msgid "true"
msgstr "" msgstr ""
@ -1515,17 +1511,17 @@ msgid "Support"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Copy ABI"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Copy Contract Creation Code"
msgstr "" msgstr ""
#, elixir-format #, 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" msgid "Copy Source Code"
msgstr "" msgstr ""
@ -1752,6 +1748,31 @@ msgstr ""
msgid "of" msgid "of"
msgstr "" 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 ""
#, elixir-format, fuzzy #, elixir-format, fuzzy
#: lib/block_scout_web/templates/address_logs/index.html.eex:77 #: lib/block_scout_web/templates/address_logs/index.html.eex:77
msgid "There are no logs for this address." msgid "There are no logs for this address."

@ -91,7 +91,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do
{:ok, _} = {:ok, _} =
Import.insert_changes_list( Import.insert_changes_list(
repo, repo,
changes_list, stakes_ratio(changes_list),
conflict_target: {:unsafe_fragment, "(address_hash) where \"primary\" = true"}, conflict_target: {:unsafe_fragment, "(address_hash) where \"primary\" = true"},
on_conflict: on_conflict, on_conflict: on_conflict,
for: Address.Name, for: Address.Name,
@ -114,4 +114,20 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do
] ]
) )
end end
# Calculates staked ratio for each pool
defp stakes_ratio(pools) do
active_pools = Enum.filter(pools, & &1.metadata[:is_active])
stakes_total =
Enum.reduce(pools, 0, fn pool, acc ->
acc + pool.metadata[:staked_amount]
end)
Enum.map(active_pools, fn pool ->
staked_ratio = if stakes_total > 0, do: pool.metadata[:staked_amount] / stakes_total, else: 0
put_in(pool, [:metadata, :staked_ratio], staked_ratio)
end)
end
end end

@ -19,7 +19,7 @@ defmodule Explorer.Chain.InternalTransaction.Result do
{key, to_string(hash)} {key, to_string(hash)}
end 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 defp entry_to_raw({key, decimal}) when key in ~w(gasUsed) do
integer = integer =

@ -1,85 +1,29 @@
defmodule Explorer.Chain.Import.Runner.StakingPoolsTest do defmodule Explorer.Chain.Import.Runner.StakingPoolsTest do
use Explorer.DataCase use Explorer.DataCase
import Explorer.Factory
alias Ecto.Multi alias Ecto.Multi
alias Explorer.Chain.Import.Runner.StakingPools alias Explorer.Chain.Import.Runner.StakingPools
describe "run/1" do describe "run/1" do
test "insert new pools list" do test "insert new pools list" do
pools = [ pools = [pool1, pool2, pool3, pool4] = build_list(4, :staking_pool)
%{
address_hash: %Explorer.Chain.Hash{
byte_count: 20,
bytes: <<11, 47, 94, 47, 60, 189, 134, 78, 170, 44, 100, 46, 55, 105, 193, 88, 35, 97, 202, 246>>
},
metadata: %{
banned_unitil: 0,
delegators_count: 0,
is_active: true,
is_banned: false,
is_validator: true,
mining_address: %Explorer.Chain.Hash{
byte_count: 20,
bytes: <<187, 202, 168, 212, 130, 137, 187, 31, 252, 249, 128, 141, 154, 164, 177, 210, 21, 5, 76, 120>>
},
retries_count: 1,
staked_amount: 0,
was_banned_count: 0,
was_validator_count: 1
},
name: "anonymous",
primary: true
},
%{
address_hash: %Explorer.Chain.Hash{
byte_count: 20,
bytes: <<170, 148, 182, 135, 211, 249, 85, 42, 69, 59, 129, 178, 131, 76, 165, 55, 120, 152, 13, 192>>
},
metadata: %{
banned_unitil: 0,
delegators_count: 0,
is_active: true,
is_banned: false,
is_validator: true,
mining_address: %Explorer.Chain.Hash{
byte_count: 20,
bytes: <<117, 223, 66, 56, 58, 254, 107, 245, 25, 74, 168, 250, 14, 155, 61, 95, 158, 134, 148, 65>>
},
retries_count: 1,
staked_amount: 0,
was_banned_count: 0,
was_validator_count: 1
},
name: "anonymous",
primary: true
},
%{
address_hash: %Explorer.Chain.Hash{
byte_count: 20,
bytes: <<49, 44, 35, 14, 125, 109, 176, 82, 36, 246, 2, 8, 166, 86, 227, 84, 28, 92, 66, 186>>
},
metadata: %{
banned_unitil: 0,
delegators_count: 0,
is_active: true,
is_banned: false,
is_validator: true,
mining_address: %Explorer.Chain.Hash{
byte_count: 20,
bytes: <<82, 45, 243, 150, 174, 112, 160, 88, 189, 105, 119, 132, 8, 99, 15, 219, 2, 51, 137, 178>>
},
retries_count: 1,
staked_amount: 0,
was_banned_count: 0,
was_validator_count: 1
},
name: "anonymous",
primary: true
}
]
assert {:ok, %{insert_staking_pools: list}} = run_changes(pools) assert {:ok, %{insert_staking_pools: list}} = run_changes(pools)
assert Enum.count(list) == Enum.count(pools) assert Enum.count(list) == Enum.count(pools)
saved_list =
Explorer.Chain.Address.Name
|> Repo.all()
|> Enum.reduce(%{}, fn pool, acc ->
Map.put(acc, pool.address_hash, pool)
end)
assert saved_list[pool1.address_hash].metadata["staked_ratio"] == 0.25
assert saved_list[pool2.address_hash].metadata["staked_ratio"] == 0.25
assert saved_list[pool3.address_hash].metadata["staked_ratio"] == 0.25
assert saved_list[pool4.address_hash].metadata["staked_ratio"] == 0.25
end end
end end

@ -1,7 +1,7 @@
defmodule Explorer.Chain.InternalTransactionTest do defmodule Explorer.Chain.InternalTransactionTest do
use Explorer.DataCase use Explorer.DataCase
alias Explorer.Chain.{InternalTransaction, Wei} alias Explorer.Chain.{Data, InternalTransaction, Wei}
alias Explorer.Factory alias Explorer.Factory
import EthereumJSONRPC, only: [integer_to_quantity: 1] import EthereumJSONRPC, only: [integer_to_quantity: 1]
@ -173,7 +173,7 @@ defmodule Explorer.Chain.InternalTransactionTest do
end end
test "it correctly formats a create" do test "it correctly formats a create" do
contract_code = Factory.contract_code_info().bytecode {:ok, contract_code} = Data.cast(Factory.contract_code_info().bytecode)
contract_address = Factory.address_hash() contract_address = Factory.address_hash()
from = Factory.address_hash() from = Factory.address_hash()
gas = 50_000 gas = 50_000

@ -609,4 +609,24 @@ defmodule Explorer.Factory do
user: build(:user) user: build(:user)
} }
end end
def staking_pool_factory do
%{
address_hash: address_hash(),
metadata: %{
banned_unitil: 0,
delegators_count: 0,
is_active: true,
is_banned: false,
is_validator: true,
mining_address: address_hash(),
retries_count: 1,
staked_amount: 25,
was_banned_count: 0,
was_validator_count: 1
},
name: "anonymous",
primary: true
}
end
end end

Loading…
Cancel
Save