message: Refactor: Abstract out the spendable tx check.
diff: @@ -2002,6 +2002,26 @@ void CWallet::GetAvailableP2CSCoins(std::vector<COutput>& vCoins) const {
  }
  +/**
  + * Test if the transaction is spendable.
  + */
  +bool CheckTXAvailability(const CWalletTx* pcoin, bool fOnlyConfirmed, bool fUseIX, int& nDepth)
  +{
  + if (!CheckFinalTx(*pcoin)) return false;
  + if (fOnlyConfirmed && !pcoin->IsTrusted()) return false;
  + if (pcoin->GetBlocksToMaturity() > 0) return false;
  +
  + nDepth = pcoin->GetDepthInMainChain(false);
  + // do not use IX for inputs that have less then 6 blockchain confirmations
  + if (fUseIX && nDepth < 6) return false;
  +
  + // We should not consider coins which aren't at least in our mempool
  + // It's possible for these to be conflicted via ancestors which we may never be able to detect
  + if (nDepth == 0 && !pcoin->InMempool()) return false;
  +
  + return true;
  +}
  +
  /**
  * populate vCoins with vector of available COutputs.
  */
  @@ -2028,17 +2048,10 @@ bool CWallet::AvailableCoins(std::vector<COutput>* pCoins, // --> populates
  const uint256& wtxid = it->first;
  const CWalletTx* pcoin = &(*it).second;
  - if (!CheckFinalTx(*pcoin)) continue;
  - if (fOnlyConfirmed && !pcoin->IsTrusted()) continue;
  - if (pcoin->GetBlocksToMaturity() > 0) continue;
  -
  - int nDepth = pcoin->GetDepthInMainChain(false);
  - // do not use IX for inputs that have less then 6 blockchain confirmations
  - if (fUseIX && nDepth < 6) continue;
  -
  - // We should not consider coins which aren't at least in our mempool
  - // It's possible for these to be conflicted via ancestors which we may never be able to detect
  - if (nDepth == 0 && !pcoin->InMempool()) continue;
  + // Check if the tx is selectable
  + int nDepth;
  + if (!CheckTXAvailability(pcoin, fOnlyConfirmed, fUseIX, nDepth))
  + continue;
  // Check min depth requirement for stake inputs
  if (nCoinType == STAKEABLE_COINS && nDepth < Params().GetConsensus().nStakeMinDepth) continue;
  