Skip to content

Commit bb16c88

Browse files
author
João Barbosa
committed
Prevent multiple calls to CWallet::AvailableCoins
1 parent c946a15 commit bb16c88

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/wallet/wallet.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,10 +1841,9 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int
18411841
return true;
18421842
}
18431843

1844-
bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl* coinControl) const
1844+
bool CWallet::SelectCoins(const vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl* coinControl) const
18451845
{
1846-
vector<COutput> vCoins;
1847-
AvailableCoins(vCoins, true, coinControl);
1846+
vector<COutput> vCoins(vAvailableCoins);
18481847

18491848
// coin control -> return all selected outputs (we want all selected to go into the transaction for sure)
18501849
if (coinControl && coinControl->HasSelected() && !coinControl->fAllowOtherInputs)
@@ -2010,6 +2009,9 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
20102009
{
20112010
LOCK2(cs_main, cs_wallet);
20122011
{
2012+
std::vector<COutput> vAvailableCoins;
2013+
AvailableCoins(vAvailableCoins, true, coinControl);
2014+
20132015
nFeeRet = 0;
20142016
// Start with no fee and loop until there is enough fee
20152017
while (true)
@@ -2059,7 +2061,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
20592061
// Choose coins to use
20602062
set<pair<const CWalletTx*,unsigned int> > setCoins;
20612063
CAmount nValueIn = 0;
2062-
if (!SelectCoins(nValueToSelect, setCoins, nValueIn, coinControl))
2064+
if (!SelectCoins(vAvailableCoins, nValueToSelect, setCoins, nValueIn, coinControl))
20632065
{
20642066
strFailReason = _("Insufficient funds");
20652067
return false;

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
544544
* all coins from coinControl are selected; Never select unconfirmed coins
545545
* if they are not ours
546546
*/
547-
bool SelectCoins(const CAmount& nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl *coinControl = NULL) const;
547+
bool SelectCoins(const std::vector<COutput>& vAvailableCoins, const CAmount& nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl *coinControl = NULL) const;
548548

549549
CWalletDB *pwalletdbEncryption;
550550

0 commit comments

Comments
 (0)