aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wallet/spend.cpp22
-rw-r--r--src/wallet/spend.h2
2 files changed, 12 insertions, 12 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index 63e04c7a9b..1428a8e217 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -96,7 +96,6 @@ CoinsResult AvailableCoins(const CWallet& wallet,
AssertLockHeld(wallet.cs_wallet);
CoinsResult result;
- CAmount nTotal = 0;
// 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
// a coin control object is provided, and has the avoid address reuse flag set to false, do we allow already used addresses
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,
int input_bytes = GetTxSpendSize(wallet, wtx, i, (coinControl && coinControl->fAllowWatchOnly));
result.coins.emplace_back(outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, feerate);
+ result.total_amount += output.nValue;
// Checks the sum amount of all UTXO's.
if (nMinimumSumAmount != MAX_MONEY) {
- nTotal += output.nValue;
-
- if (nTotal >= nMinimumSumAmount) {
+ if (result.total_amount >= nMinimumSumAmount) {
return result;
}
}
@@ -234,14 +232,14 @@ CoinsResult AvailableCoinsListUnspent(const CWallet& wallet, const CCoinControl*
CAmount GetAvailableBalance(const CWallet& wallet, const CCoinControl* coinControl)
{
LOCK(wallet.cs_wallet);
-
- CAmount balance = 0;
- for (const COutput& out : AvailableCoinsListUnspent(wallet, coinControl).coins) {
- if (out.spendable) {
- balance += out.txout.nValue;
- }
- }
- return balance;
+ return AvailableCoins(wallet,
+ coinControl,
+ std::nullopt, /*feerate=*/
+ 1, /*nMinimumAmount*/
+ MAX_MONEY, /*nMaximumAmount*/
+ MAX_MONEY, /*nMinimumSumAmount*/
+ 0 /*nMaximumCount*/
+ ).total_amount;
}
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const CTransaction& tx, int output)
diff --git a/src/wallet/spend.h b/src/wallet/spend.h
index 84628517b0..cba42d6fae 100644
--- a/src/wallet/spend.h
+++ b/src/wallet/spend.h
@@ -36,6 +36,8 @@ TxSize CalculateMaximumSignedTxSize(const CTransaction& tx, const CWallet* walle
struct CoinsResult {
std::vector<COutput> coins;
+ // Sum of all the coins amounts
+ CAmount total_amount{0};
};
/**
* Return vector of available COutputs.