@@ -84,11 +84,17 @@ TxSize CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *walle
84
84
return CalculateMaximumSignedTxSize (tx, wallet, txouts, coin_control);
85
85
}
86
86
87
- void AvailableCoins (const CWallet& wallet, std::vector<COutput>& vCoins, const CCoinControl* coinControl, std::optional<CFeeRate> feerate, const CAmount& nMinimumAmount, const CAmount& nMaximumAmount, const CAmount& nMinimumSumAmount, const uint64_t nMaximumCount)
87
+ CoinsResult AvailableCoins (const CWallet& wallet,
88
+ const CCoinControl* coinControl,
89
+ std::optional<CFeeRate> feerate,
90
+ const CAmount& nMinimumAmount,
91
+ const CAmount& nMaximumAmount,
92
+ const CAmount& nMinimumSumAmount,
93
+ const uint64_t nMaximumCount)
88
94
{
89
95
AssertLockHeld (wallet.cs_wallet );
90
96
91
- vCoins. clear () ;
97
+ CoinsResult result ;
92
98
CAmount nTotal = 0 ;
93
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
94
100
// a coin control object is provided, and has the avoid address reuse flag set to false, do we allow already used addresses
@@ -191,39 +197,38 @@ void AvailableCoins(const CWallet& wallet, std::vector<COutput>& vCoins, const C
191
197
bool solvable = provider ? IsSolvable (*provider, wtx.tx ->vout [i].scriptPubKey ) : false ;
192
198
bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable));
193
199
int input_bytes = GetTxSpendSize (wallet, wtx, i, (coinControl && coinControl->fAllowWatchOnly ));
194
-
195
- vCoins.emplace_back (COutPoint (wtx.GetHash (), i), wtx.tx ->vout .at (i), nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime (), tx_from_me, feerate);
200
+ result.coins .emplace_back (COutPoint (wtx.GetHash (), i), wtx.tx ->vout .at (i), nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime (), tx_from_me, feerate);
196
201
197
202
// Checks the sum amount of all UTXO's.
198
203
if (nMinimumSumAmount != MAX_MONEY) {
199
204
nTotal += wtx.tx ->vout [i].nValue ;
200
205
201
206
if (nTotal >= nMinimumSumAmount) {
202
- return ;
207
+ return result ;
203
208
}
204
209
}
205
210
206
211
// Checks the maximum number of UTXO's.
207
- if (nMaximumCount > 0 && vCoins .size () >= nMaximumCount) {
208
- return ;
212
+ if (nMaximumCount > 0 && result. coins .size () >= nMaximumCount) {
213
+ return result ;
209
214
}
210
215
}
211
216
}
217
+
218
+ return result;
212
219
}
213
220
214
- void AvailableCoinsListUnspent (const CWallet& wallet, std::vector<COutput>& vCoins , const CCoinControl* coinControl, const CAmount& nMinimumAmount, const CAmount& nMaximumAmount, const CAmount& nMinimumSumAmount, const uint64_t nMaximumCount)
221
+ CoinsResult AvailableCoinsListUnspent (const CWallet& wallet, const CCoinControl* coinControl, const CAmount& nMinimumAmount, const CAmount& nMaximumAmount, const CAmount& nMinimumSumAmount, const uint64_t nMaximumCount)
215
222
{
216
- AvailableCoins (wallet, vCoins , coinControl, /* feerate=*/ std::nullopt, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount);
223
+ return AvailableCoins (wallet, coinControl, /* feerate=*/ std::nullopt, nMinimumAmount, nMaximumAmount, nMinimumSumAmount, nMaximumCount);
217
224
}
218
225
219
226
CAmount GetAvailableBalance (const CWallet& wallet, const CCoinControl* coinControl)
220
227
{
221
228
LOCK (wallet.cs_wallet );
222
229
223
230
CAmount balance = 0 ;
224
- std::vector<COutput> vCoins;
225
- AvailableCoinsListUnspent (wallet, vCoins, coinControl);
226
- for (const COutput& out : vCoins) {
231
+ for (const COutput& out : AvailableCoinsListUnspent (wallet, coinControl).coins ) {
227
232
if (out.spendable ) {
228
233
balance += out.txout .nValue ;
229
234
}
@@ -260,11 +265,8 @@ std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
260
265
AssertLockHeld (wallet.cs_wallet );
261
266
262
267
std::map<CTxDestination, std::vector<COutput>> result;
263
- std::vector<COutput> availableCoins;
264
-
265
- AvailableCoinsListUnspent (wallet, availableCoins);
266
268
267
- for (const COutput& coin : availableCoins ) {
269
+ for (const COutput& coin : AvailableCoinsListUnspent (wallet). coins ) {
268
270
CTxDestination address;
269
271
if ((coin.spendable || (wallet.IsWalletFlagSet (WALLET_FLAG_DISABLE_PRIVATE_KEYS) && coin.solvable )) &&
270
272
ExtractDestination (FindNonChangeParentOutput (wallet, coin.outpoint ).scriptPubKey , address)) {
@@ -791,11 +793,10 @@ static std::optional<CreatedTransactionResult> CreateTransactionInternal(
791
793
CAmount selection_target = recipients_sum + not_input_fees;
792
794
793
795
// Get available coins
794
- std::vector<COutput> vAvailableCoins;
795
- AvailableCoins (wallet, vAvailableCoins, &coin_control, coin_selection_params.m_effective_feerate , 1 , MAX_MONEY, MAX_MONEY, 0 );
796
+ auto res_available_coins = AvailableCoins (wallet, &coin_control, coin_selection_params.m_effective_feerate , 1 , MAX_MONEY, MAX_MONEY, 0 );
796
797
797
798
// Choose coins to use
798
- std::optional<SelectionResult> result = SelectCoins (wallet, vAvailableCoins , /* nTargetValue=*/ selection_target, coin_control, coin_selection_params);
799
+ std::optional<SelectionResult> result = SelectCoins (wallet, res_available_coins. coins , /* nTargetValue=*/ selection_target, coin_control, coin_selection_params);
799
800
if (!result) {
800
801
error = _ (" Insufficient funds" );
801
802
return std::nullopt;
0 commit comments