diff --git a/apps/block_scout_web/assets/js/pages/address.js b/apps/block_scout_web/assets/js/pages/address.js index c1ab083b36..c7aecc7b55 100644 --- a/apps/block_scout_web/assets/js/pages/address.js +++ b/apps/block_scout_web/assets/js/pages/address.js @@ -93,6 +93,14 @@ export function reducer (state = initialState, action) { }) } } + case 'RECEIVED_NEW_BLOCK': { + if (state.channelDisconnected || state.beyondPageOne) return state + + return Object.assign({}, state, { + newBlock: action.msg.blockHtml, + minerHash: action.msg.blockMinerHash + }) + } default: return state } @@ -116,6 +124,12 @@ if ($addressDetailsPage.length) { addressChannel.onError(() => store.dispatch({ type: 'CHANNEL_DISCONNECTED' })) addressChannel.on('balance', (msg) => store.dispatch({ type: 'RECEIVED_UPDATED_BALANCE', msg })) if (!state.beyondPageOne) { + const blocksChannel = socket.channel(`blocks:new_block`, {}) + blocksChannel.join() + blocksChannel.onError(() => store.dispatch({ type: 'CHANNEL_DISCONNECTED' })) + blocksChannel.on('new_block', (msg) => { + store.dispatch({ type: 'RECEIVED_NEW_BLOCK', msg: humps.camelizeKeys(msg) }) + }) addressChannel.on('transaction', batchChannel((msgs) => store.dispatch({ type: 'RECEIVED_NEW_TRANSACTION_BATCH', msgs }) )) @@ -135,6 +149,7 @@ if ($addressDetailsPage.length) { const $internalTransactionsList = $('[data-selector="internal-transactions-list"]') const $transactionCount = $('[data-selector="transaction-count"]') const $transactionsList = $('[data-selector="transactions-list"]') + const $validationsList = $('[data-selector="validations-list"]') if ($emptyInternalTransactionsList.length && state.newInternalTransactions.length) window.location.reload() if ($emptyTransactionsList.length && state.newTransactions.length) window.location.reload() @@ -159,6 +174,15 @@ if ($addressDetailsPage.length) { prependWithClingBottom($transactionsList, state.newTransactions.slice(oldState.newTransactions.length).reverse().join('')) updateAllAges() } + if (oldState.newBlock !== state.newBlock && state.minerHash === state.addressHash) { + const len = $validationsList.children().length + $validationsList + .children() + .slice(len - 1, len) + .remove() + + $validationsList.prepend(state.newBlock) + } } }) } diff --git a/apps/block_scout_web/lib/block_scout_web/channels/block_channel.ex b/apps/block_scout_web/lib/block_scout_web/channels/block_channel.ex index 3a78b40dfd..c499ae4a4a 100644 --- a/apps/block_scout_web/lib/block_scout_web/channels/block_channel.ex +++ b/apps/block_scout_web/lib/block_scout_web/channels/block_channel.ex @@ -34,7 +34,8 @@ defmodule BlockScoutWeb.BlockChannel do average_block_time: Timex.format_duration(average_block_time, :humanized), chain_block_html: rendered_chain_block, block_html: rendered_block, - block_number: block.number + block_number: block.number, + block_miner_hash: to_string(block.miner_hash) }) {:noreply, socket} diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex index 377be35b3c..4e694397e0 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.AddressContractController do use BlockScoutWeb, :controller - import BlockScoutWeb.AddressController, only: [transaction_count: 1] + import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1] alias Explorer.{Chain, Market} alias Explorer.ExchangeRates.Token @@ -14,7 +14,8 @@ defmodule BlockScoutWeb.AddressContractController do "index.html", address: address, exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), - transaction_count: transaction_count(address) + transaction_count: transaction_count(address), + validation_count: validation_count(address) ) else :error -> diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex index 2753dc8720..93ea2a688e 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex @@ -20,4 +20,8 @@ defmodule BlockScoutWeb.AddressController do def transaction_count(%Address{} = address) do Chain.address_to_transactions_estimated_count(address) end + + def validation_count(%Address{} = address) do + Chain.address_to_validation_count(address) + end end diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_internal_transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_internal_transaction_controller.ex index b7e6079997..36c32740e7 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_internal_transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_internal_transaction_controller.ex @@ -5,7 +5,7 @@ defmodule BlockScoutWeb.AddressInternalTransactionController do use BlockScoutWeb, :controller - import BlockScoutWeb.AddressController, only: [transaction_count: 1] + import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1] import BlockScoutWeb.Chain, only: [current_filter: 1, paging_options: 1, next_page_params: 3, split_list_by_page: 1] alias Explorer.{Chain, Market} @@ -26,7 +26,6 @@ defmodule BlockScoutWeb.AddressInternalTransactionController do |> Keyword.merge(current_filter(params)) internal_transactions_plus_one = Chain.address_to_internal_transactions(address, full_options) - {internal_transactions, next_page} = split_list_by_page(internal_transactions_plus_one) render( @@ -37,7 +36,8 @@ defmodule BlockScoutWeb.AddressInternalTransactionController do exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), filter: params["filter"], internal_transactions: internal_transactions, - transaction_count: transaction_count(address) + transaction_count: transaction_count(address), + validation_count: validation_count(address) ) else :error -> diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex index 1100fa3c8c..76c5147d2f 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex @@ -11,7 +11,7 @@ defmodule BlockScoutWeb.AddressReadContractController do alias Explorer.{Chain, Market} alias Explorer.ExchangeRates.Token - import BlockScoutWeb.AddressController, only: [transaction_count: 1] + import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1] def index(conn, %{"address_id" => address_hash_string}) do with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), @@ -21,7 +21,8 @@ defmodule BlockScoutWeb.AddressReadContractController do "index.html", address: address, exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), - transaction_count: transaction_count(address) + transaction_count: transaction_count(address), + validation_count: validation_count(address) ) else :error -> diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_token_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_token_controller.ex index c2c7bea561..d5b77bd470 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_token_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_token_controller.ex @@ -4,7 +4,7 @@ defmodule BlockScoutWeb.AddressTokenController do alias Explorer.{Chain, Market} alias Explorer.ExchangeRates.Token - import BlockScoutWeb.AddressController, only: [transaction_count: 1] + import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1] import BlockScoutWeb.Chain, only: [next_page_params: 3, paging_options: 1, split_list_by_page: 1] def index(conn, %{"address_id" => address_hash_string} = params) do @@ -19,6 +19,7 @@ defmodule BlockScoutWeb.AddressTokenController do address: address, exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), transaction_count: transaction_count(address), + validation_count: validation_count(address), next_page_params: next_page_params(next_page, tokens, params), tokens: tokens ) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex index 8b598673e9..cfad37b3dd 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_token_transfer_controller.ex @@ -4,7 +4,7 @@ defmodule BlockScoutWeb.AddressTokenTransferController do alias Explorer.{Chain, Market} alias Explorer.ExchangeRates.Token - import BlockScoutWeb.AddressController, only: [transaction_count: 1] + import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1] import BlockScoutWeb.Chain, only: [next_page_params: 3, paging_options: 1, split_list_by_page: 1] @@ -34,7 +34,8 @@ defmodule BlockScoutWeb.AddressTokenTransferController do next_page_params: next_page_params(next_page, transactions_paginated, params), token: token, transaction_count: transaction_count(address), - transactions: transactions_paginated + transactions: transactions_paginated, + validation_count: validation_count(address) ) else :error -> diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex index 5bad1ddbae..584d28efba 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex @@ -5,7 +5,7 @@ defmodule BlockScoutWeb.AddressTransactionController do use BlockScoutWeb, :controller - import BlockScoutWeb.AddressController, only: [transaction_count: 1] + import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1] import BlockScoutWeb.Chain, only: [current_filter: 1, paging_options: 1, next_page_params: 3, split_list_by_page: 1] alias Explorer.{Chain, Market} @@ -37,7 +37,8 @@ defmodule BlockScoutWeb.AddressTransactionController do exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), filter: params["filter"], transactions: transactions, - transaction_count: transaction_count(address) + transaction_count: transaction_count(address), + validation_count: validation_count(address) ) else :error -> diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_validation_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_validation_controller.ex new file mode 100644 index 0000000000..f16fefc516 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_validation_controller.ex @@ -0,0 +1,43 @@ +defmodule BlockScoutWeb.AddressValidationController do + @moduledoc """ + Display all the blocks that this address validates. + """ + use BlockScoutWeb, :controller + + import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1] + import BlockScoutWeb.Chain, only: [paging_options: 1, next_page_params: 3, split_list_by_page: 1] + + alias Explorer.{Chain, Market} + alias Explorer.ExchangeRates.Token + + def index(conn, %{"address_id" => address_hash_string} = params) do + with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), + {:ok, address} <- Chain.hash_to_address(address_hash) do + full_options = + Keyword.merge( + [necessity_by_association: %{miner: :required, transactions: :optional}], + paging_options(params) + ) + + blocks_plus_one = Chain.get_blocks_validated_by_address(full_options, address) + {blocks, next_page} = split_list_by_page(blocks_plus_one) + + render( + conn, + "index.html", + address: address, + blocks: blocks, + transaction_count: transaction_count(address), + validation_count: validation_count(address), + exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), + next_page_params: next_page_params(next_page, blocks, params) + ) + else + :error -> + unprocessable_entity(conn) + + {:error, :not_found} -> + not_found(conn) + end + end +end diff --git a/apps/block_scout_web/lib/block_scout_web/router.ex b/apps/block_scout_web/lib/block_scout_web/router.ex index 44e2b90bd3..7dedf9d87c 100644 --- a/apps/block_scout_web/lib/block_scout_web/router.ex +++ b/apps/block_scout_web/lib/block_scout_web/router.ex @@ -78,6 +78,13 @@ defmodule BlockScoutWeb.Router do as: :internal_transaction ) + resources( + "/validations", + AddressValidationController, + only: [:index], + as: :validation + ) + resources( "/contracts", AddressContractController, diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex index ef8b5cd66c..ad5f4c4ec9 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/overview.html.eex @@ -17,15 +17,19 @@

<%= address_title(@address) %> <%= gettext "Details" %>

<%= @address.hash %>

-
<%= if address_name = primary_name(@address) do %> <%= address_name %> <% end %> - <%= Cldr.Number.to_string!(@transaction_count, format: "#,###") %> - - <%= gettext "Transactions" %> + + <%= Cldr.Number.to_string!(@transaction_count, format: "#,###") %> + <%= gettext("Transactions") %> + <%= if validator?(@validation_count) do %> + + <%= Cldr.Number.to_string!(@validation_count, format: "#,###") %> + <%= gettext("Blocks Validated") %> + <% end %> <%= if @address.token do %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex index f8378f477d..04a39a421a 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex @@ -9,26 +9,36 @@ @@ -77,6 +88,14 @@ "data-test": "internal_transactions_tab_link", to: address_internal_transaction_path(@conn, :index, @address.hash) ) %> + <%= if BlockScoutWeb.AddressView.validator?(@validation_count) do %> + <%= link( + gettext("Blocks Validated"), + class: "dropdown-item", + "data-test": "validations_tab_link", + to: address_validation_path(@conn, :index, @address.hash) + ) %> + <% end %> <%= link( to: address_contract_path(@conn, :index, @address.hash), class: "dropdown-item active") do %> @@ -155,7 +174,6 @@
- <% end %>
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_internal_transaction/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_internal_transaction/index.html.eex index 94cc54863f..d677c803ed 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_internal_transaction/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_internal_transaction/index.html.eex @@ -10,26 +10,36 @@
-
+ -
+
-
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_read_contract/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_read_contract/index.html.eex index 50d9a24acc..d4f9a41868 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_read_contract/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_read_contract/index.html.eex @@ -9,26 +9,36 @@ diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_token/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_token/index.html.eex index e2e85d28b7..ccc19245bc 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_token/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_token/index.html.eex @@ -8,28 +8,36 @@