Merge branch 'master' into gs-block-internal-transactions

pull/1543/head
Victor Baranov 6 years ago committed by GitHub
commit f7385d821f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex
  2. 6
      apps/block_scout_web/lib/block_scout_web/views/address_view.ex
  3. 40
      apps/block_scout_web/priv/gettext/default.pot
  4. 40
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  5. 20
      apps/explorer/lib/explorer/chain.ex
  6. 7
      apps/explorer/priv/repo/migrations/20190314084907_add_index_to_to_address_hash.exs
  7. 14
      apps/explorer/test/explorer/chain_test.exs

@ -35,10 +35,18 @@
<% end %> <% end %>
<span> <span>
<span class="address-detail-item"> <span class="address-detail-item">
<%= if contract?(@address) do %>
<%= gettext(">=") %>
<span data-selector="transaction-count">
<%= incoming_transaction_count(@address) %>
</span>
<%= gettext("Incoming Transactions") %>
<% else %>
<span data-selector="transaction-count"> <span data-selector="transaction-count">
<%= Cldr.Number.to_string!(@transaction_count, format: "#,###") %> <%= Cldr.Number.to_string!(@transaction_count, format: "#,###") %>
</span> </span>
<%= gettext("Transactions Sent") %> <%= gettext("Transactions Sent") %>
<% end %>
</span> </span>
<span class="address-detail-item"> <span class="address-detail-item">
<%= gettext("Last Balance Update: Block #") %><span data-selector="fetched-coin-balance-block-number"><%= @address.fetched_coin_balance_block_number %></span> <%= gettext("Last Balance Update: Block #") %><span data-selector="fetched-coin-balance-block-number"><%= @address.fetched_coin_balance_block_number %></span>

@ -213,6 +213,12 @@ defmodule BlockScoutWeb.AddressView do
def token_title(%Token{name: name, symbol: symbol}), do: "#{name} (#{symbol})" def token_title(%Token{name: name, symbol: symbol}), do: "#{name} (#{symbol})"
def incoming_transaction_count(%Address{} = address) do
count = Chain.address_to_incoming_transaction_count(address)
Cldr.Number.to_string!(count, format: "#,###")
end
def trimmed_hash(%Hash{} = hash) do def trimmed_hash(%Hash{} = hash) do
string_hash = to_string(hash) string_hash = to_string(hash)
"#{String.slice(string_hash, 0..5)}#{String.slice(string_hash, -6..-1)}" "#{String.slice(string_hash, 0..5)}#{String.slice(string_hash, -6..-1)}"

@ -189,10 +189,10 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:40 #: lib/block_scout_web/templates/address/_tabs.html.eex:40
#: lib/block_scout_web/templates/address/_tabs.html.eex:103 #: lib/block_scout_web/templates/address/_tabs.html.eex:103
#: lib/block_scout_web/templates/address/overview.html.eex:51 #: lib/block_scout_web/templates/address/overview.html.eex:59
#: lib/block_scout_web/templates/address_validation/index.html.eex:30 #: lib/block_scout_web/templates/address_validation/index.html.eex:30
#: lib/block_scout_web/templates/address_validation/index.html.eex:57 #: lib/block_scout_web/templates/address_validation/index.html.eex:57
#: lib/block_scout_web/views/address_view.ex:287 #: lib/block_scout_web/views/address_view.ex:293
msgid "Blocks Validated" msgid "Blocks Validated"
msgstr "" msgstr ""
@ -209,8 +209,8 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/_validator_metadata_modal.html.eex:37 #: lib/block_scout_web/templates/address/_validator_metadata_modal.html.eex:37
#: lib/block_scout_web/templates/address/overview.html.eex:95
#: lib/block_scout_web/templates/address/overview.html.eex:103 #: lib/block_scout_web/templates/address/overview.html.eex:103
#: lib/block_scout_web/templates/address/overview.html.eex:111
#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:91 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:91
#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:99 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:99
msgid "Close" msgid "Close"
@ -222,7 +222,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_validation/index.html.eex:39 #: lib/block_scout_web/templates/address_validation/index.html.eex:39
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:119 #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:119
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:141 #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:141
#: lib/block_scout_web/views/address_view.ex:284 #: lib/block_scout_web/views/address_view.ex:290
msgid "Code" msgid "Code"
msgstr "" msgstr ""
@ -328,7 +328,7 @@ msgid "Copy Txn Hash"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:61 #: lib/block_scout_web/templates/address/overview.html.eex:69
msgid "Created by" msgid "Created by"
msgstr "" msgstr ""
@ -494,7 +494,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:14 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:14
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:43 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:43
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:10 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:10
#: lib/block_scout_web/views/address_view.ex:283 #: lib/block_scout_web/views/address_view.ex:289
#: lib/block_scout_web/views/transaction_view.ex:258 #: lib/block_scout_web/views/transaction_view.ex:258
msgid "Internal Transactions" msgid "Internal Transactions"
msgstr "" msgstr ""
@ -685,7 +685,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:13 #: lib/block_scout_web/templates/address/overview.html.eex:13
#: lib/block_scout_web/templates/address/overview.html.eex:94 #: lib/block_scout_web/templates/address/overview.html.eex:102
#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:13 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:13
#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:13 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:13
#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:90 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:90
@ -702,7 +702,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:122 #: lib/block_scout_web/templates/address/_tabs.html.eex:122
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:33 #: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:33
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:75 #: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:75
#: lib/block_scout_web/views/address_view.ex:285 #: lib/block_scout_web/views/address_view.ex:291
#: lib/block_scout_web/views/tokens/overview_view.ex:37 #: lib/block_scout_web/views/tokens/overview_view.ex:37
msgid "Read Contract" msgid "Read Contract"
msgstr "" msgstr ""
@ -901,7 +901,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:12 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:12
#: lib/block_scout_web/templates/address_validation/index.html.eex:11 #: lib/block_scout_web/templates/address_validation/index.html.eex:11
#: lib/block_scout_web/templates/address_validation/index.html.eex:19 #: lib/block_scout_web/templates/address_validation/index.html.eex:19
#: lib/block_scout_web/views/address_view.ex:281 #: lib/block_scout_web/views/address_view.ex:287
msgid "Tokens" msgid "Tokens"
msgstr "" msgstr ""
@ -962,7 +962,7 @@ msgstr ""
#: lib/block_scout_web/templates/block_transaction/index.html.eex:35 #: lib/block_scout_web/templates/block_transaction/index.html.eex:35
#: lib/block_scout_web/templates/chain/show.html.eex:93 #: lib/block_scout_web/templates/chain/show.html.eex:93
#: lib/block_scout_web/templates/layout/_topnav.html.eex:35 #: lib/block_scout_web/templates/layout/_topnav.html.eex:35
#: lib/block_scout_web/views/address_view.ex:282 #: lib/block_scout_web/views/address_view.ex:288
msgid "Transactions" msgid "Transactions"
msgstr "" msgstr ""
@ -1094,7 +1094,7 @@ msgid "Yes"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:67 #: lib/block_scout_web/templates/address/overview.html.eex:75
msgid "at" msgid "at"
msgstr "" msgstr ""
@ -1405,7 +1405,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:30 #: lib/block_scout_web/templates/address/_tabs.html.eex:30
#: lib/block_scout_web/templates/address/_tabs.html.eex:96 #: lib/block_scout_web/templates/address/_tabs.html.eex:96
#: lib/block_scout_web/views/address_view.ex:286 #: lib/block_scout_web/views/address_view.ex:292
msgid "Coin Balance History" msgid "Coin Balance History"
msgstr "" msgstr ""
@ -1647,12 +1647,12 @@ msgid "Enter contructor arguments if the contract had any"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:44 #: lib/block_scout_web/templates/address/overview.html.eex:52
msgid "Last Balance Update: Block #" msgid "Last Balance Update: Block #"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:41 #: lib/block_scout_web/templates/address/overview.html.eex:48
msgid "Transactions Sent" msgid "Transactions Sent"
msgstr "" msgstr ""
@ -1688,6 +1688,16 @@ msgid "EVM Vesion"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:75 #: lib/block_scout_web/templates/address/overview.html.eex:39
msgid ">="
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:43
msgid "Incoming Transactions"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:83
msgid "Error: Could not determine contract creator." msgid "Error: Could not determine contract creator."
msgstr "" msgstr ""

@ -189,10 +189,10 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:40 #: lib/block_scout_web/templates/address/_tabs.html.eex:40
#: lib/block_scout_web/templates/address/_tabs.html.eex:103 #: lib/block_scout_web/templates/address/_tabs.html.eex:103
#: lib/block_scout_web/templates/address/overview.html.eex:51 #: lib/block_scout_web/templates/address/overview.html.eex:59
#: lib/block_scout_web/templates/address_validation/index.html.eex:30 #: lib/block_scout_web/templates/address_validation/index.html.eex:30
#: lib/block_scout_web/templates/address_validation/index.html.eex:57 #: lib/block_scout_web/templates/address_validation/index.html.eex:57
#: lib/block_scout_web/views/address_view.ex:287 #: lib/block_scout_web/views/address_view.ex:293
msgid "Blocks Validated" msgid "Blocks Validated"
msgstr "" msgstr ""
@ -209,8 +209,8 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/_validator_metadata_modal.html.eex:37 #: lib/block_scout_web/templates/address/_validator_metadata_modal.html.eex:37
#: lib/block_scout_web/templates/address/overview.html.eex:95
#: lib/block_scout_web/templates/address/overview.html.eex:103 #: lib/block_scout_web/templates/address/overview.html.eex:103
#: lib/block_scout_web/templates/address/overview.html.eex:111
#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:91 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:91
#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:99 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:99
msgid "Close" msgid "Close"
@ -222,7 +222,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_validation/index.html.eex:39 #: lib/block_scout_web/templates/address_validation/index.html.eex:39
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:119 #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:119
#: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:141 #: lib/block_scout_web/templates/api_docs/_action_tile.html.eex:141
#: lib/block_scout_web/views/address_view.ex:284 #: lib/block_scout_web/views/address_view.ex:290
msgid "Code" msgid "Code"
msgstr "" msgstr ""
@ -328,7 +328,7 @@ msgid "Copy Txn Hash"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:61 #: lib/block_scout_web/templates/address/overview.html.eex:69
msgid "Created by" msgid "Created by"
msgstr "" msgstr ""
@ -494,7 +494,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:14 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:14
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:43 #: lib/block_scout_web/templates/transaction/_tabs.html.eex:43
#: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:10 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:10
#: lib/block_scout_web/views/address_view.ex:283 #: lib/block_scout_web/views/address_view.ex:289
#: lib/block_scout_web/views/transaction_view.ex:258 #: lib/block_scout_web/views/transaction_view.ex:258
msgid "Internal Transactions" msgid "Internal Transactions"
msgstr "" msgstr ""
@ -685,7 +685,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:13 #: lib/block_scout_web/templates/address/overview.html.eex:13
#: lib/block_scout_web/templates/address/overview.html.eex:94 #: lib/block_scout_web/templates/address/overview.html.eex:102
#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:13 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:13
#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:13 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:13
#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:90 #: lib/block_scout_web/templates/tokens/overview/_details.html.eex:90
@ -702,7 +702,7 @@ msgstr ""
#: lib/block_scout_web/templates/address/_tabs.html.eex:122 #: lib/block_scout_web/templates/address/_tabs.html.eex:122
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:33 #: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:33
#: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:75 #: lib/block_scout_web/templates/tokens/overview/_tabs.html.eex:75
#: lib/block_scout_web/views/address_view.ex:285 #: lib/block_scout_web/views/address_view.ex:291
#: lib/block_scout_web/views/tokens/overview_view.ex:37 #: lib/block_scout_web/views/tokens/overview_view.ex:37
msgid "Read Contract" msgid "Read Contract"
msgstr "" msgstr ""
@ -901,7 +901,7 @@ msgstr ""
#: lib/block_scout_web/templates/address_token_transfer/index.html.eex:12 #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:12
#: lib/block_scout_web/templates/address_validation/index.html.eex:11 #: lib/block_scout_web/templates/address_validation/index.html.eex:11
#: lib/block_scout_web/templates/address_validation/index.html.eex:19 #: lib/block_scout_web/templates/address_validation/index.html.eex:19
#: lib/block_scout_web/views/address_view.ex:281 #: lib/block_scout_web/views/address_view.ex:287
msgid "Tokens" msgid "Tokens"
msgstr "" msgstr ""
@ -962,7 +962,7 @@ msgstr ""
#: lib/block_scout_web/templates/block_transaction/index.html.eex:35 #: lib/block_scout_web/templates/block_transaction/index.html.eex:35
#: lib/block_scout_web/templates/chain/show.html.eex:93 #: lib/block_scout_web/templates/chain/show.html.eex:93
#: lib/block_scout_web/templates/layout/_topnav.html.eex:35 #: lib/block_scout_web/templates/layout/_topnav.html.eex:35
#: lib/block_scout_web/views/address_view.ex:282 #: lib/block_scout_web/views/address_view.ex:288
msgid "Transactions" msgid "Transactions"
msgstr "" msgstr ""
@ -1094,7 +1094,7 @@ msgid "Yes"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:67 #: lib/block_scout_web/templates/address/overview.html.eex:75
msgid "at" msgid "at"
msgstr "" msgstr ""
@ -1405,7 +1405,7 @@ msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:30 #: lib/block_scout_web/templates/address/_tabs.html.eex:30
#: lib/block_scout_web/templates/address/_tabs.html.eex:96 #: lib/block_scout_web/templates/address/_tabs.html.eex:96
#: lib/block_scout_web/views/address_view.ex:286 #: lib/block_scout_web/views/address_view.ex:292
msgid "Coin Balance History" msgid "Coin Balance History"
msgstr "" msgstr ""
@ -1647,12 +1647,12 @@ msgid "Enter contructor arguments if the contract had any"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:44 #: lib/block_scout_web/templates/address/overview.html.eex:52
msgid "Last Balance Update: Block #" msgid "Last Balance Update: Block #"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:41 #: lib/block_scout_web/templates/address/overview.html.eex:48
msgid "Transactions Sent" msgid "Transactions Sent"
msgstr "" msgstr ""
@ -1688,6 +1688,16 @@ msgid "EVM Vesion"
msgstr "" msgstr ""
#, elixir-format #, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:75 #: lib/block_scout_web/templates/address/overview.html.eex:39
msgid ">="
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:43
msgid "Incoming Transactions"
msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/overview.html.eex:83
msgid "Error: Could not determine contract creator." msgid "Error: Could not determine contract creator."
msgstr "" msgstr ""

@ -51,6 +51,8 @@ defmodule Explorer.Chain do
@default_paging_options %PagingOptions{page_size: 50} @default_paging_options %PagingOptions{page_size: 50}
@max_incoming_transactions_count 10_000
@typedoc """ @typedoc """
The name of an association on the `t:Ecto.Schema.t/0` The name of an association on the `t:Ecto.Schema.t/0`
""" """
@ -417,6 +419,24 @@ defmodule Explorer.Chain do
Repo.aggregate(query, :count, :hash) Repo.aggregate(query, :count, :hash)
end end
@spec address_to_incoming_transaction_count(Address.t()) :: non_neg_integer()
def address_to_incoming_transaction_count(%Address{hash: address_hash}) do
paging_options = %PagingOptions{page_size: @max_incoming_transactions_count}
base_query =
paging_options
|> fetch_transactions()
to_address_query =
base_query
|> where([t], t.to_address_hash == ^address_hash)
Repo.aggregate(to_address_query, :count, :hash, timeout: :infinity)
end
@spec max_incoming_transactions_count() :: non_neg_integer()
def max_incoming_transactions_count, do: @max_incoming_transactions_count
@doc """ @doc """
How many blocks have confirmed `block` based on the current `max_block_number` How many blocks have confirmed `block` based on the current `max_block_number`

@ -0,0 +1,7 @@
defmodule Explorer.Repo.Migrations.AddIndexToToAddressHash do
use Ecto.Migration
def change do
create(index(:transactions, [:to_address_hash]))
end
end

@ -597,6 +597,20 @@ defmodule Explorer.ChainTest do
end end
end end
describe "address_to_incoming_transaction_count/1" do
test "without transactions" do
address = insert(:address)
assert Chain.address_to_incoming_transaction_count(address) == 0
end
test "with transactions" do
%Transaction{to_address: to_address} = insert(:transaction)
assert Chain.address_to_incoming_transaction_count(to_address) == 1
end
end
describe "confirmations/1" do describe "confirmations/1" do
test "with block.number == block_height " do test "with block.number == block_height " do
block = insert(:block) block = insert(:block)

Loading…
Cancel
Save