From fb597cd6e39f4551a4db4cb609573d6f11ae0080 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Wed, 23 Jan 2019 09:49:24 +0300 Subject: [PATCH] exclude replaced transaction from pending transactions list --- apps/explorer/lib/explorer/chain.ex | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 116662c12b..93effe494d 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -1164,7 +1164,7 @@ defmodule Explorer.Chain do query = from( 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), select: ^fields ) @@ -1474,7 +1474,7 @@ defmodule Explorer.Chain do @spec pending_transaction_count() :: non_neg_integer() def pending_transaction_count do Transaction - |> where([transaction], is_nil(transaction.block_hash)) + |> pending_transactions_query() |> Repo.aggregate(:count, :hash) end @@ -1547,13 +1547,19 @@ defmodule Explorer.Chain do Transaction |> page_pending_transaction(paging_options) |> 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) |> join_associations(necessity_by_association) |> preload([{:token_transfers, [:token, :from_address, :to_address]}]) |> Repo.all() end + defp pending_transactions_query(query) do + from(transaction in query, + where: is_nil(transaction.block_hash) and is_nil(transaction.error) + ) + end + @doc """ The `string` must start with `0x`, then is converted to an integer and then to `t:Explorer.Chain.Hash.Address.t/0`.