Skip to content

Commit

Permalink
Move output eligibility to a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Mar 13, 2018
1 parent 0185939 commit ce7435c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/wallet/wallet.cpp
Expand Up @@ -2484,6 +2484,20 @@ static void ApproximateBestSubset(const std::vector<CInputCoin>& vValue, const C
}
}

bool CWallet::OutputEligibleForSpending(const COutput& output, const int nConfMine, const int nConfTheirs, const uint64_t nMaxAncestors) const
{
if (!output.fSpendable)
return false;

if (output.nDepth < (output.tx->IsFromMe(ISMINE_ALL) ? nConfMine : nConfTheirs))
return false;

if (!mempool.TransactionWithinChainLimit(output.tx->GetHash(), nMaxAncestors))
return false;

return true;
}

bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMine, const int nConfTheirs, const uint64_t nMaxAncestors, std::vector<COutput> vCoins,
std::set<CInputCoin>& setCoinsRet, CAmount& nValueRet) const
{
Expand All @@ -2499,20 +2513,10 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin

for (const COutput &output : vCoins)
{
if (!output.fSpendable)
continue;

const CWalletTx *pcoin = output.tx;

if (output.nDepth < (pcoin->IsFromMe(ISMINE_ALL) ? nConfMine : nConfTheirs))
continue;

if (!mempool.TransactionWithinChainLimit(pcoin->GetHash(), nMaxAncestors))
if (!OutputEligibleForSpending(output, nConfMine, nConfTheirs, nMaxAncestors))
continue;

int i = output.i;

CInputCoin coin = CInputCoin(pcoin, i);
CInputCoin coin = CInputCoin(output.tx, output.i);

if (coin.txout.nValue == nTargetValue)
{
Expand Down
3 changes: 3 additions & 0 deletions src/wallet/wallet.h
Expand Up @@ -1190,6 +1190,9 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
* This function will automatically add the necessary scripts to the wallet.
*/
CTxDestination AddAndGetDestinationForScript(const CScript& script, OutputType);

/** Whether a given output is spendable by this wallet */
bool OutputEligibleForSpending(const COutput& output, const int nConfMine, const int nConfTheirs, const uint64_t nMaxAncestors) const;
};

/** A key allocated from the key pool. */
Expand Down

0 comments on commit ce7435c

Please sign in to comment.