@@ -96,7 +96,6 @@ CoinsResult AvailableCoins(const CWallet& wallet,
96
96
AssertLockHeld (wallet.cs_wallet );
97
97
98
98
CoinsResult result;
99
- CAmount nTotal = 0 ;
100
99
// Either the WALLET_FLAG_AVOID_REUSE flag is not set (in which case we always allow), or we default to avoiding, and only in the case where
101
100
// a coin control object is provided, and has the avoid address reuse flag set to false, do we allow already used addresses
102
101
bool allow_used_addresses = !wallet.IsWalletFlagSet (WALLET_FLAG_AVOID_REUSE) || (coinControl && !coinControl->m_avoid_address_reuse );
@@ -206,12 +205,11 @@ CoinsResult AvailableCoins(const CWallet& wallet,
206
205
207
206
int input_bytes = GetTxSpendSize (wallet, wtx, i, (coinControl && coinControl->fAllowWatchOnly ));
208
207
result.coins .emplace_back (outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime (), tx_from_me, feerate);
208
+ result.total_amount += output.nValue ;
209
209
210
210
// Checks the sum amount of all UTXO's.
211
211
if (nMinimumSumAmount != MAX_MONEY) {
212
- nTotal += output.nValue ;
213
-
214
- if (nTotal >= nMinimumSumAmount) {
212
+ if (result.total_amount >= nMinimumSumAmount) {
215
213
return result;
216
214
}
217
215
}
@@ -234,14 +232,14 @@ CoinsResult AvailableCoinsListUnspent(const CWallet& wallet, const CCoinControl*
234
232
CAmount GetAvailableBalance (const CWallet& wallet, const CCoinControl* coinControl)
235
233
{
236
234
LOCK (wallet.cs_wallet );
237
-
238
- CAmount balance = 0 ;
239
- for ( const COutput& out : AvailableCoinsListUnspent (wallet, coinControl). coins ) {
240
- if (out. spendable ) {
241
- balance += out. txout . nValue ;
242
- }
243
- }
244
- return balance ;
235
+ return AvailableCoins (wallet,
236
+ coinControl,
237
+ std::nullopt, /* feerate= */
238
+ 1 , /* nMinimumAmount */
239
+ MAX_MONEY, /* nMaximumAmount */
240
+ MAX_MONEY, /* nMinimumSumAmount */
241
+ 0 /* nMaximumCount */
242
+ ). total_amount ;
245
243
}
246
244
247
245
const CTxOut& FindNonChangeParentOutput (const CWallet& wallet, const CTransaction& tx, int output)
0 commit comments