exclude replaced transaction from pending transactions list

pull/1370/head
Ayrat Badykov 6 years ago
parent 944e953351
commit fb597cd6e3
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 12
      apps/explorer/lib/explorer/chain.ex

@ -1164,7 +1164,7 @@ defmodule Explorer.Chain do
query = query =
from( from(
t in Transaction, t in Transaction,
# exclude pending transactions # exclude pending transactions and replaced transactions
where: not is_nil(t.block_hash) and is_nil(t.internal_transactions_indexed_at), where: not is_nil(t.block_hash) and is_nil(t.internal_transactions_indexed_at),
select: ^fields select: ^fields
) )
@ -1474,7 +1474,7 @@ defmodule Explorer.Chain do
@spec pending_transaction_count() :: non_neg_integer() @spec pending_transaction_count() :: non_neg_integer()
def pending_transaction_count do def pending_transaction_count do
Transaction Transaction
|> where([transaction], is_nil(transaction.block_hash)) |> pending_transactions_query()
|> Repo.aggregate(:count, :hash) |> Repo.aggregate(:count, :hash)
end end
@ -1547,13 +1547,19 @@ defmodule Explorer.Chain do
Transaction Transaction
|> page_pending_transaction(paging_options) |> page_pending_transaction(paging_options)
|> limit(^paging_options.page_size) |> limit(^paging_options.page_size)
|> where([transaction], is_nil(transaction.block_hash)) |> pending_transactions_query()
|> order_by([transaction], desc: transaction.inserted_at, desc: transaction.hash) |> order_by([transaction], desc: transaction.inserted_at, desc: transaction.hash)
|> join_associations(necessity_by_association) |> join_associations(necessity_by_association)
|> preload([{:token_transfers, [:token, :from_address, :to_address]}]) |> preload([{:token_transfers, [:token, :from_address, :to_address]}])
|> Repo.all() |> Repo.all()
end end
defp pending_transactions_query(query) do
from(transaction in query,
where: is_nil(transaction.block_hash) and is_nil(transaction.error)
)
end
@doc """ @doc """
The `string` must start with `0x`, then is converted to an integer and then to `t:Explorer.Chain.Hash.Address.t/0`. The `string` must start with `0x`, then is converted to an integer and then to `t:Explorer.Chain.Hash.Address.t/0`.

Loading…
Cancel
Save