Merge pull request #1838 from poanetwork/block_counter_fix

Block counter calculates only consensus blocks
pull/1848/head
Victor Baranov 6 years ago committed by GitHub
commit 251f076fbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex
  3. 15
      apps/explorer/lib/explorer/chain.ex

@ -10,6 +10,7 @@
- [#1829](https://github.com/poanetwork/blockscout/pull/1829) - Handle nil quantities in block decoding routine - [#1829](https://github.com/poanetwork/blockscout/pull/1829) - Handle nil quantities in block decoding routine
- [#1830](https://github.com/poanetwork/blockscout/pull/1830) - Make block size field nullable - [#1830](https://github.com/poanetwork/blockscout/pull/1830) - Make block size field nullable
- [#1838](https://github.com/poanetwork/blockscout/pull/1838) - Block counter calculates only consensus blocks
### Chore ### Chore

@ -11,7 +11,7 @@ defmodule BlockScoutWeb.ChainController do
def show(conn, _params) do def show(conn, _params) do
transaction_estimated_count = Chain.transaction_estimated_count() transaction_estimated_count = Chain.transaction_estimated_count()
block_count = Chain.block_count() block_count = Chain.block_consensus_count()
exchange_rate = Market.get_exchange_rate(Explorer.coin()) || Token.null() exchange_rate = Market.get_exchange_rate(Explorer.coin()) || Token.null()

@ -329,6 +329,21 @@ defmodule Explorer.Chain do
Repo.aggregate(Block, :count, :hash) Repo.aggregate(Block, :count, :hash)
end end
@doc """
The number of consensus blocks.
iex> insert(:block, consensus: true)
iex> insert(:block, consensus: false)
iex> Explorer.Chain.block_consensus_count()
1
"""
def block_consensus_count do
Block
|> where(consensus: true)
|> Repo.aggregate(:count, :hash)
end
@doc """ @doc """
Reward for mining a block. Reward for mining a block.

Loading…
Cancel
Save