From 0c61d26c6a2ebda7cb1f2a7b1cfc543ed1ca2afa Mon Sep 17 00:00:00 2001 From: saneery Date: Tue, 23 Apr 2019 14:13:22 +0300 Subject: [PATCH 1/8] add block count to chain show view --- .../controllers/chain_controller.ex | 4 ++- .../templates/chain/show.html.eex | 8 ++++++ apps/block_scout_web/priv/gettext/default.pot | 25 +++++++++++-------- .../priv/gettext/en/LC_MESSAGES/default.po | 25 +++++++++++-------- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex index e84b0a3438..e49e499250 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex @@ -11,6 +11,7 @@ defmodule BlockScoutWeb.ChainController do def show(conn, _params) do transaction_estimated_count = Chain.transaction_estimated_count() + block_count = Chain.block_count() exchange_rate = Market.get_exchange_rate(Explorer.coin()) || Token.null() @@ -22,7 +23,8 @@ defmodule BlockScoutWeb.ChainController do exchange_rate: exchange_rate, chart_data_path: market_history_chart_path(conn, :show), transaction_estimated_count: transaction_estimated_count, - transactions_path: recent_transactions_path(conn, :index) + transactions_path: recent_transactions_path(conn, :index), + block_count: block_count ) end diff --git a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex index aa1621622a..dacbcb477b 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex @@ -53,6 +53,14 @@ <%= Cldr.Number.to_string!(@transaction_estimated_count, format: "#,###") %> +
+ + <%= gettext "Total blocks" %> + + + <%= Cldr.Number.to_string!(@block_count, format: "#,###") %> + +
<%= gettext "Wallet addresses" %> diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index c4d03d82ec..395792d02a 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -175,7 +175,7 @@ msgid "BlockScout provides analytics data, API, and Smart Contract tools for the msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:72 +#: lib/block_scout_web/templates/chain/show.html.eex:80 #: lib/block_scout_web/templates/layout/_topnav.html.eex:16 #: lib/block_scout_web/templates/layout/_topnav.html.eex:20 msgid "Blocks" @@ -560,7 +560,7 @@ msgid "More internal transactions have come in" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:96 +#: lib/block_scout_web/templates/chain/show.html.eex:104 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:14 #: lib/block_scout_web/templates/transaction/index.html.eex:14 msgid "More transactions have come in" @@ -957,7 +957,7 @@ msgstr "" #: lib/block_scout_web/templates/block_transaction/index.html.eex:23 #: lib/block_scout_web/templates/block_transaction/index.html.eex:26 #: 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:101 #: lib/block_scout_web/templates/layout/_topnav.html.eex:35 #: lib/block_scout_web/views/address_view.ex:294 msgid "Transactions" @@ -1031,12 +1031,12 @@ msgid "Verify & publish" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:71 +#: lib/block_scout_web/templates/chain/show.html.eex:79 msgid "View All Blocks →" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:92 +#: lib/block_scout_web/templates/chain/show.html.eex:100 msgid "View All Transactions →" msgstr "" @@ -1076,7 +1076,7 @@ msgid "WEI" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:58 +#: lib/block_scout_web/templates/chain/show.html.eex:66 msgid "Wallet addresses" msgstr "" @@ -1160,8 +1160,8 @@ msgstr "" #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:19 #: lib/block_scout_web/templates/address_validation/index.html.eex:63 #: lib/block_scout_web/templates/address_validation/index.html.eex:82 -#: lib/block_scout_web/templates/chain/show.html.eex:84 -#: lib/block_scout_web/templates/chain/show.html.eex:110 +#: lib/block_scout_web/templates/chain/show.html.eex:92 +#: lib/block_scout_web/templates/chain/show.html.eex:118 #: lib/block_scout_web/templates/tokens/read_contract/index.html.eex:24 msgid "Loading..." msgstr "" @@ -1371,7 +1371,7 @@ msgstr "" #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:26 #: lib/block_scout_web/templates/address_transaction/index.html.eex:55 #: lib/block_scout_web/templates/address_validation/index.html.eex:70 -#: lib/block_scout_web/templates/chain/show.html.eex:76 +#: lib/block_scout_web/templates/chain/show.html.eex:84 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:23 #: lib/block_scout_web/templates/tokens/holder/index.html.eex:22 #: lib/block_scout_web/templates/tokens/transfer/index.html.eex:20 @@ -1514,7 +1514,7 @@ msgid "Emission Contract" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:102 +#: lib/block_scout_web/templates/chain/show.html.eex:110 msgid "Something went wrong, click to retry." msgstr "" @@ -1744,3 +1744,8 @@ msgstr "" #: lib/block_scout_web/templates/transaction/overview.html.eex:165 msgid "ERC-721" msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/chain/show.html.eex:58 +msgid "Total blocks" +msgstr "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index 26503607c4..b894c828fd 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -175,7 +175,7 @@ msgid "BlockScout provides analytics data, API, and Smart Contract tools for the msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:72 +#: lib/block_scout_web/templates/chain/show.html.eex:80 #: lib/block_scout_web/templates/layout/_topnav.html.eex:16 #: lib/block_scout_web/templates/layout/_topnav.html.eex:20 msgid "Blocks" @@ -560,7 +560,7 @@ msgid "More internal transactions have come in" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:96 +#: lib/block_scout_web/templates/chain/show.html.eex:104 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:14 #: lib/block_scout_web/templates/transaction/index.html.eex:14 msgid "More transactions have come in" @@ -957,7 +957,7 @@ msgstr "" #: lib/block_scout_web/templates/block_transaction/index.html.eex:23 #: lib/block_scout_web/templates/block_transaction/index.html.eex:26 #: 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:101 #: lib/block_scout_web/templates/layout/_topnav.html.eex:35 #: lib/block_scout_web/views/address_view.ex:294 msgid "Transactions" @@ -1031,12 +1031,12 @@ msgid "Verify & publish" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:71 +#: lib/block_scout_web/templates/chain/show.html.eex:79 msgid "View All Blocks →" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:92 +#: lib/block_scout_web/templates/chain/show.html.eex:100 msgid "View All Transactions →" msgstr "" @@ -1076,7 +1076,7 @@ msgid "WEI" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:58 +#: lib/block_scout_web/templates/chain/show.html.eex:66 msgid "Wallet addresses" msgstr "" @@ -1160,8 +1160,8 @@ msgstr "" #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:19 #: lib/block_scout_web/templates/address_validation/index.html.eex:63 #: lib/block_scout_web/templates/address_validation/index.html.eex:82 -#: lib/block_scout_web/templates/chain/show.html.eex:84 -#: lib/block_scout_web/templates/chain/show.html.eex:110 +#: lib/block_scout_web/templates/chain/show.html.eex:92 +#: lib/block_scout_web/templates/chain/show.html.eex:118 #: lib/block_scout_web/templates/tokens/read_contract/index.html.eex:24 msgid "Loading..." msgstr "" @@ -1371,7 +1371,7 @@ msgstr "" #: lib/block_scout_web/templates/address_token_transfer/index.html.eex:26 #: lib/block_scout_web/templates/address_transaction/index.html.eex:55 #: lib/block_scout_web/templates/address_validation/index.html.eex:70 -#: lib/block_scout_web/templates/chain/show.html.eex:76 +#: lib/block_scout_web/templates/chain/show.html.eex:84 #: lib/block_scout_web/templates/pending_transaction/index.html.eex:23 #: lib/block_scout_web/templates/tokens/holder/index.html.eex:22 #: lib/block_scout_web/templates/tokens/transfer/index.html.eex:20 @@ -1514,7 +1514,7 @@ msgid "Emission Contract" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/chain/show.html.eex:102 +#: lib/block_scout_web/templates/chain/show.html.eex:110 msgid "Something went wrong, click to retry." msgstr "" @@ -1744,3 +1744,8 @@ msgstr "" #: lib/block_scout_web/templates/transaction/overview.html.eex:165 msgid "ERC-721" msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/chain/show.html.eex:58 +msgid "Total blocks" +msgstr "" From d72d226a5b4946ee15c3ba2358e40ea376ac6667 Mon Sep 17 00:00:00 2001 From: saneery Date: Tue, 23 Apr 2019 14:13:57 +0300 Subject: [PATCH 2/8] add block count updater --- apps/block_scout_web/assets/js/pages/chain.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/chain.js b/apps/block_scout_web/assets/js/pages/chain.js index 910d228cf6..d18160d097 100644 --- a/apps/block_scout_web/assets/js/pages/chain.js +++ b/apps/block_scout_web/assets/js/pages/chain.js @@ -24,7 +24,8 @@ export const initialState = { transactionsError: false, transactionsLoading: true, transactionCount: null, - usdMarketCap: null + usdMarketCap: null, + blockCount: null } export const reducer = withMissingBlocks(baseReducer) @@ -46,11 +47,13 @@ function baseReducer (state = initialState, action) { blocks: [ action.msg, ...state.blocks.slice(0, -1) - ] + ], + blockCount: action.msg.blockNumber + 1 }) } else { return Object.assign({}, state, { - blocks: state.blocks.map((block) => block.blockNumber === action.msg.blockNumber ? action.msg : block) + blocks: state.blocks.map((block) => block.blockNumber === action.msg.blockNumber ? action.msg : block), + blockCount: action.msg.blockNumber + 1 }) } } @@ -152,6 +155,15 @@ const elements = { $el.empty().append(numeral(state.transactionCount).format()) } }, + '[data-selector="block-count"]': { + load ($el) { + return { blockCount: numeral($el.text()).value() } + }, + render ($el, state, oldState) { + if (oldState.blockCount === state.blockCount) return + $el.empty().append(numeral(state.blockCount).format()) + } + }, '[data-selector="address-count"]': { render ($el, state, oldState) { if (oldState.addressCount === state.addressCount) return From 0881fd8dd10f77ef1aa99cca62ad6485fe298368 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Tue, 23 Apr 2019 14:17:37 +0300 Subject: [PATCH 3/8] Clear build script --- rel/commands/clear_build.sh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 rel/commands/clear_build.sh diff --git a/rel/commands/clear_build.sh b/rel/commands/clear_build.sh new file mode 100755 index 0000000000..66ede0039b --- /dev/null +++ b/rel/commands/clear_build.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +rm -rf ./_build +rm -rf ./deps +rm -rf ./logs/dev +rm -rf ./apps/explorer/node_modules +rm -rf ./apps/block_scout_web/assets/node_modules \ No newline at end of file From c2ac900973cb94999dd462e79d4d2aa617b6eead Mon Sep 17 00:00:00 2001 From: saneery Date: Tue, 23 Apr 2019 14:20:49 +0300 Subject: [PATCH 4/8] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f88ff0a14..ac45bbe435 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Features +- [#1813](https://github.com/poanetwork/blockscout/pull/1813) - add total blocks counter to the main page + ### Fixes ### Chore From ee870fb1defaf84f73028585812339ee0d0ad3d8 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Tue, 23 Apr 2019 14:32:01 +0300 Subject: [PATCH 5/8] UPDATE CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f88ff0a14..5073e0e74d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Chore +- [#1814](https://github.com/poanetwork/blockscout/pull/1814) - Clear build artefacts script ## 1.3.10-beta From 7d0fe0eed653ef41ce2f123a7b3327014faa2624 Mon Sep 17 00:00:00 2001 From: saneery Date: Tue, 23 Apr 2019 15:31:38 +0300 Subject: [PATCH 6/8] able to search without prefix "0x" --- .../lib/block_scout_web/chain.ex | 18 +++++++++------ .../controllers/chain_controller_test.exs | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/chain.ex b/apps/block_scout_web/lib/block_scout_web/chain.ex index ebe196739c..8f6cff3866 100644 --- a/apps/block_scout_web/lib/block_scout_web/chain.ex +++ b/apps/block_scout_web/lib/block_scout_web/chain.ex @@ -60,13 +60,17 @@ defmodule BlockScoutWeb.Chain do @spec from_param(String.t()) :: {:ok, Address.t() | Block.t() | Transaction.t()} | {:error, :not_found} def from_param(param) - def from_param("0x" <> number_string = param) do - case String.length(number_string) do - 40 -> address_from_param(param) - 64 -> block_or_transaction_from_param(param) - _ -> {:error, :not_found} - end - end + def from_param("0x" <> number_string = param) when byte_size(number_string) == 40, + do: address_from_param(param) + + def from_param("0x" <> number_string = param) when byte_size(number_string) == 64, + do: block_or_transaction_from_param(param) + + def from_param(param) when byte_size(param) == 40, + do: address_from_param("0x" <> param) + + def from_param(param) when byte_size(param) == 64, + do: block_or_transaction_from_param("0x" <> param) def from_param(string) when is_binary(string) do case param_to_block_number(string) do diff --git a/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs index bc3a4a4e90..652d0a7355 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs @@ -121,6 +121,19 @@ defmodule BlockScoutWeb.ChainControllerTest do assert redirected_to(conn) == transaction_path(conn, :show, transaction) end + test "finds a transaction by hash when there are not 0x prefix", %{conn: conn} do + transaction = + :transaction + |> insert() + |> with_block() + + "0x" <> non_prefix_hash = to_string(transaction.hash) + + conn = get(conn, "search?q=#{to_string(non_prefix_hash)}") + + assert redirected_to(conn) == transaction_path(conn, :show, transaction) + end + test "finds an address by hash", %{conn: conn} do address = insert(:address) conn = get(conn, "search?q=#{to_string(address.hash)}") @@ -135,6 +148,15 @@ defmodule BlockScoutWeb.ChainControllerTest do assert redirected_to(conn) == address_path(conn, :show, address) end + test "finds an address by hash when there are not 0x prefix", %{conn: conn} do + address = insert(:address) + "0x" <> non_prefix_hash = to_string(address.hash) + + conn = get(conn, "search?q=#{to_string(non_prefix_hash)}") + + assert redirected_to(conn) == address_path(conn, :show, address) + end + test "redirects to 404 when it finds nothing", %{conn: conn} do conn = get(conn, "search?q=zaphod") assert conn.status == 404 From 4495a9b06c21db0e0ce2ef05adde76971934c195 Mon Sep 17 00:00:00 2001 From: saneery Date: Tue, 23 Apr 2019 15:34:23 +0300 Subject: [PATCH 7/8] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f88ff0a14..df561a6db2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Features +- [#1815](https://github.com/poanetwork/blockscout/pull/1815) - able to search without prefix "0x" + ### Fixes ### Chore From 967d14ecd56eb38250224ff63d5b3f85242d985a Mon Sep 17 00:00:00 2001 From: saneery Date: Wed, 24 Apr 2019 09:47:52 +0300 Subject: [PATCH 8/8] define hash len as constant in module --- apps/block_scout_web/lib/block_scout_web/chain.ex | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/chain.ex b/apps/block_scout_web/lib/block_scout_web/chain.ex index 8f6cff3866..0aa33b5ffd 100644 --- a/apps/block_scout_web/lib/block_scout_web/chain.ex +++ b/apps/block_scout_web/lib/block_scout_web/chain.ex @@ -32,6 +32,8 @@ defmodule BlockScoutWeb.Chain do @page_size 50 @default_paging_options %PagingOptions{page_size: @page_size + 1} + @address_hash_len 40 + @tx_block_hash_len 64 def default_paging_options do @default_paging_options @@ -60,16 +62,16 @@ defmodule BlockScoutWeb.Chain do @spec from_param(String.t()) :: {:ok, Address.t() | Block.t() | Transaction.t()} | {:error, :not_found} def from_param(param) - def from_param("0x" <> number_string = param) when byte_size(number_string) == 40, + def from_param("0x" <> number_string = param) when byte_size(number_string) == @address_hash_len, do: address_from_param(param) - def from_param("0x" <> number_string = param) when byte_size(number_string) == 64, + def from_param("0x" <> number_string = param) when byte_size(number_string) == @tx_block_hash_len, do: block_or_transaction_from_param(param) - def from_param(param) when byte_size(param) == 40, + def from_param(param) when byte_size(param) == @address_hash_len, do: address_from_param("0x" <> param) - def from_param(param) when byte_size(param) == 64, + def from_param(param) when byte_size(param) == @tx_block_hash_len, do: block_or_transaction_from_param("0x" <> param) def from_param(string) when is_binary(string) do