diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5d2f27e072d0..9fc76ac6c6b1 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2421,7 +2421,7 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const } static void ApproximateBestSubset(vector > >vValue, const CAmount& nTotalLower, const CAmount& nTargetValue, - vector& vfBest, CAmount& nBest, int iterations = 1000) + vector& vfBest, CAmount& nBest, int iterations = 1000, bool fUseInstantSend = false) { vector vfIncluded; @@ -2439,6 +2439,9 @@ static void ApproximateBestSubset(vector sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE)) { + continue; + } //The solver here uses a randomized algorithm, //the randomness serves no real security purpose but is just //needed to prevent degenerate behavior and it is important @@ -2493,14 +2496,16 @@ bool less_then_denom (const COutput& out1, const COutput& out2) } bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector vCoins, - set >& setCoinsRet, CAmount& nValueRet) const + set >& setCoinsRet, CAmount& nValueRet, bool fUseInstantSend) const { setCoinsRet.clear(); nValueRet = 0; // List of values less than target pair > coinLowestLarger; - coinLowestLarger.first = std::numeric_limits::max(); + coinLowestLarger.first = fUseInstantSend + ? sporkManager.GetSporkValue(SPORK_5_INSTANTSEND_MAX_VALUE) + : std::numeric_limits::max(); coinLowestLarger.second.first = NULL; vector > > vValue; CAmount nTotalLower = 0; @@ -2586,9 +2591,9 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int vector vfBest; CAmount nBest; - ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest); + ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest, fUseInstantSend); if (nBest != nTargetValue && nTotalLower >= nTargetValue + MIN_CHANGE) - ApproximateBestSubset(vValue, nTotalLower, nTargetValue + MIN_CHANGE, vfBest, nBest); + ApproximateBestSubset(vValue, nTotalLower, nTargetValue + MIN_CHANGE, vfBest, nBest, fUseInstantSend); // If we have a bigger coin and (either the stochastic approximation didn't find a good solution, // or the next bigger coin is closer), return the bigger coin @@ -2697,9 +2702,9 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set vCoins, std::set >& setCoinsRet, CAmount& nValueRet) const; + bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, CAmount& nValueRet, bool fUseInstantSend = false) const; bool SelectCoinsByDenominations(int nDenom, CAmount nValueMin, CAmount nValueMax, std::vector& vecTxInRet, std::vector& vCoinsRet, CAmount& nValueRet, int nPrivateSendRoundsMin, int nPrivateSendRoundsMax); bool GetCollateralTxIn(CTxIn& txinRet, CAmount& nValueRet) const;