|
|
|
@ -555,6 +555,23 @@ defmodule Explorer.Chain do |
|
|
|
|
{:actual, fee} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Checks to see if the chain is down indexing based on the transaction from the oldest block having |
|
|
|
|
an `internal_transactions_indexed_at` date. |
|
|
|
|
""" |
|
|
|
|
@spec finished_indexing?() :: boolean() |
|
|
|
|
def finished_indexing? do |
|
|
|
|
min_block_number_transaction = Repo.aggregate(Transaction, :min, :block_number) |
|
|
|
|
Transaction |
|
|
|
|
|> where([t], t.block_number == ^min_block_number_transaction and is_nil(t.internal_transactions_indexed_at)) |
|
|
|
|
|> limit(1) |
|
|
|
|
|> Repo.one() |
|
|
|
|
|> case do |
|
|
|
|
nil -> true |
|
|
|
|
_ -> false |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
The `t:Explorer.Chain.Transaction.t/0` `gas_price` of the `transaction` in `unit`. |
|
|
|
|
""" |
|
|
|
@ -822,31 +839,6 @@ defmodule Explorer.Chain do |
|
|
|
|
Repo.aggregate(InternalTransaction, :count, :id) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Finds block with greatest number. |
|
|
|
|
|
|
|
|
|
iex> insert(:block, number: 2) |
|
|
|
|
iex> insert(:block, number: 1) |
|
|
|
|
iex> {:ok, %Explorer.Chain.Block{number: number}} = Explorer.Chain.max_numbered_block() |
|
|
|
|
iex> number |
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
If there are no blocks `{:error, :not_found}` is returned. |
|
|
|
|
|
|
|
|
|
iex> Explorer.Chain.max_numbered_block() |
|
|
|
|
{:error, :not_found} |
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
@spec max_numbered_block() :: {:ok, Block.t()} | {:error, :not_found} |
|
|
|
|
def max_numbered_block do |
|
|
|
|
query = from(block in Block, order_by: [desc: block.number], limit: 1) |
|
|
|
|
|
|
|
|
|
case Repo.one(query) do |
|
|
|
|
nil -> {:error, :not_found} |
|
|
|
|
block -> {:ok, block} |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Finds all `t:Explorer.Chain.Transaction.t/0` in the `t:Explorer.Chain.Block.t/0`. |
|
|
|
|
|
|
|
|
@ -1142,6 +1134,30 @@ defmodule Explorer.Chain do |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
The minimum `t:Explorer.Chain.Block.t/0` `number` (used to show loading status while indexing) |
|
|
|
|
|
|
|
|
|
If blocks are skipped and inserted out of number order, the min number is still returned |
|
|
|
|
|
|
|
|
|
iex> insert(:block, number: 2) |
|
|
|
|
iex> insert(:block, number: 1) |
|
|
|
|
iex> Explorer.Chain.min_block_number() |
|
|
|
|
{:ok, 1} |
|
|
|
|
|
|
|
|
|
If there are no blocks, `{:error, :not_found}` is returned |
|
|
|
|
|
|
|
|
|
iex> Explorer.Chain.min_block_number() |
|
|
|
|
{:error, :not_found} |
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
@spec min_block_number() :: {:ok, Block.block_number()} | {:error, :not_found} |
|
|
|
|
def min_block_number do |
|
|
|
|
case Repo.aggregate(Block, :min, :number) do |
|
|
|
|
nil -> {:error, :not_found} |
|
|
|
|
number -> {:ok, number} |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Calculates the ranges of missing consensus blocks in `range`. |
|
|
|
|
|
|
|
|
|