diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 899bc290a3..473c2e0e76 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -2738,19 +2738,23 @@ defmodule Explorer.Chain do |> select_repo(options).all() end + @doc """ + Query to return all pending transactions + """ + @spec pending_transactions_query(Ecto.Queryable.t()) :: Ecto.Queryable.t() def pending_transactions_query(query) do from(transaction in query, where: is_nil(transaction.block_hash) and (is_nil(transaction.error) or transaction.error != "dropped/replaced") ) end + @doc """ + Returns pending transactions list from the DB + """ + @spec pending_transactions_list() :: Ecto.Schema.t() | term() def pending_transactions_list do - query = - from(transaction in Transaction, - where: is_nil(transaction.block_hash) and (is_nil(transaction.error) or transaction.error != "dropped/replaced") - ) - - query + Transaction + |> pending_transactions_query() |> Repo.all(timeout: :infinity) end @@ -3877,13 +3881,17 @@ defmodule Explorer.Chain do |> Enum.uniq() if Enum.empty?(filters) do - {:ok, []} + {0, []} else query = filters |> Enum.reduce(Transaction, fn {nonce, from_address}, query -> from(t in query, - or_where: t.nonce == ^nonce and t.from_address_hash == ^from_address and is_nil(t.block_hash) + or_where: + t.nonce == ^nonce and + t.from_address_hash == ^from_address and + is_nil(t.block_hash) and + (is_nil(t.error) or t.error != "dropped/replaced") ) end) # Enforce Transaction ShareLocks order (see docs: sharelocks.md)