Skip to content

Commit ce7435c

Browse files
committed
Move output eligibility to a separate function
1 parent 0185939 commit ce7435c

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/wallet/wallet.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,6 +2484,20 @@ static void ApproximateBestSubset(const std::vector<CInputCoin>& vValue, const C
24842484
}
24852485
}
24862486

2487+
bool CWallet::OutputEligibleForSpending(const COutput& output, const int nConfMine, const int nConfTheirs, const uint64_t nMaxAncestors) const
2488+
{
2489+
if (!output.fSpendable)
2490+
return false;
2491+
2492+
if (output.nDepth < (output.tx->IsFromMe(ISMINE_ALL) ? nConfMine : nConfTheirs))
2493+
return false;
2494+
2495+
if (!mempool.TransactionWithinChainLimit(output.tx->GetHash(), nMaxAncestors))
2496+
return false;
2497+
2498+
return true;
2499+
}
2500+
24872501
bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMine, const int nConfTheirs, const uint64_t nMaxAncestors, std::vector<COutput> vCoins,
24882502
std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet) const
24892503
{
@@ -2499,20 +2513,10 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
24992513

25002514
for (const COutput &output : vCoins)
25012515
{
2502-
if (!output.fSpendable)
2503-
continue;
2504-
2505-
const CWalletTx *pcoin = output.tx;
2506-
2507-
if (output.nDepth < (pcoin->IsFromMe(ISMINE_ALL) ? nConfMine : nConfTheirs))
2508-
continue;
2509-
2510-
if (!mempool.TransactionWithinChainLimit(pcoin->GetHash(), nMaxAncestors))
2516+
if (!OutputEligibleForSpending(output, nConfMine, nConfTheirs, nMaxAncestors))
25112517
continue;
25122518

2513-
int i = output.i;
2514-
2515-
CInputCoin coin = CInputCoin(pcoin, i);
2519+
CInputCoin coin = CInputCoin(output.tx, output.i);
25162520

25172521
if (coin.txout.nValue == nTargetValue)
25182522
{

src/wallet/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,9 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
11901190
* This function will automatically add the necessary scripts to the wallet.
11911191
*/
11921192
CTxDestination AddAndGetDestinationForScript(const CScript& script, OutputType);
1193+
1194+
/** Whether a given output is spendable by this wallet */
1195+
bool OutputEligibleForSpending(const COutput& output, const int nConfMine, const int nConfTheirs, const uint64_t nMaxAncestors) const;
11931196
};
11941197

11951198
/** A key allocated from the key pool. */

0 commit comments

Comments
 (0)