@@ -2374,7 +2374,6 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
2374
2374
nValueRet = 0 ;
2375
2375
2376
2376
if (coin_selection_params.use_bnb ) {
2377
- std::vector<OutputGroup> utxo_pool;
2378
2377
// Get long term estimate
2379
2378
FeeCalculation feeCalc;
2380
2379
CCoinControl temp;
@@ -2388,22 +2387,17 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const CoinEligibil
2388
2387
effective_feerate = coin_selection_params.effective_fee ;
2389
2388
}
2390
2389
2391
- std::vector<OutputGroup> groups = GroupOutputs (coins, !coin_selection_params.m_avoid_partial_spends , eligibility_filter.max_ancestors , effective_feerate, long_term_feerate, eligibility_filter);
2390
+ std::vector<OutputGroup> groups = GroupOutputs (coins, !coin_selection_params.m_avoid_partial_spends , eligibility_filter.max_ancestors , effective_feerate, long_term_feerate, eligibility_filter, true /* positive_only */ );
2392
2391
2393
2392
// Calculate cost of change
2394
2393
CAmount cost_of_change = GetDiscardRate (*this ).GetFee (coin_selection_params.change_spend_size ) + coin_selection_params.effective_fee .GetFee (coin_selection_params.change_output_size );
2395
2394
2396
- // Filter by the min conf specs and add to utxo_pool and calculate effective value
2397
- for (OutputGroup& group : groups) {
2398
- OutputGroup pos_group = group.GetPositiveOnlyGroup ();
2399
- if (pos_group.effective_value > 0 ) utxo_pool.push_back (pos_group);
2400
- }
2401
2395
// Calculate the fees for things that aren't inputs
2402
2396
CAmount not_input_fees = coin_selection_params.effective_fee .GetFee (coin_selection_params.tx_noinputs_size );
2403
2397
bnb_used = true ;
2404
- return SelectCoinsBnB (utxo_pool , nTargetValue, cost_of_change, setCoinsRet, nValueRet, not_input_fees);
2398
+ return SelectCoinsBnB (groups , nTargetValue, cost_of_change, setCoinsRet, nValueRet, not_input_fees);
2405
2399
} else {
2406
- std::vector<OutputGroup> groups = GroupOutputs (coins, !coin_selection_params.m_avoid_partial_spends , eligibility_filter.max_ancestors , CFeeRate (0 ), CFeeRate (0 ), eligibility_filter);
2400
+ std::vector<OutputGroup> groups = GroupOutputs (coins, !coin_selection_params.m_avoid_partial_spends , eligibility_filter.max_ancestors , CFeeRate (0 ), CFeeRate (0 ), eligibility_filter, false /* positive_only */ );
2407
2401
2408
2402
bnb_used = false ;
2409
2403
return KnapsackSolver (nTargetValue, groups, setCoinsRet, nValueRet);
@@ -4199,7 +4193,7 @@ bool CWalletTx::IsImmatureCoinBase() const
4199
4193
return GetBlocksToMaturity () > 0 ;
4200
4194
}
4201
4195
4202
- std::vector<OutputGroup> CWallet::GroupOutputs (const std::vector<COutput>& outputs, bool single_coin, const size_t max_ancestors, const CFeeRate& effective_feerate, const CFeeRate& long_term_feerate, const CoinEligibilityFilter& filter) const {
4196
+ std::vector<OutputGroup> CWallet::GroupOutputs (const std::vector<COutput>& outputs, bool single_coin, const size_t max_ancestors, const CFeeRate& effective_feerate, const CFeeRate& long_term_feerate, const CoinEligibilityFilter& filter, bool positive_only ) const {
4203
4197
std::vector<OutputGroup> groups;
4204
4198
std::map<CTxDestination, OutputGroup> gmap;
4205
4199
std::set<CTxDestination> full_groups;
@@ -4224,16 +4218,17 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
4224
4218
it->second = OutputGroup{effective_feerate, long_term_feerate};
4225
4219
full_groups.insert (dst);
4226
4220
}
4227
- it->second .Insert (input_coin, output.nDepth , output.tx ->IsFromMe (ISMINE_ALL), ancestors, descendants);
4221
+ it->second .Insert (input_coin, output.nDepth , output.tx ->IsFromMe (ISMINE_ALL), ancestors, descendants, positive_only );
4228
4222
} else {
4229
4223
auto ins = gmap.emplace (dst, OutputGroup{effective_feerate, long_term_feerate});
4230
- ins.first ->second .Insert (input_coin, output.nDepth , output.tx ->IsFromMe (ISMINE_ALL), ancestors, descendants);
4224
+ ins.first ->second .Insert (input_coin, output.nDepth , output.tx ->IsFromMe (ISMINE_ALL), ancestors, descendants, positive_only );
4231
4225
}
4232
4226
} else {
4233
4227
// This is for if each output gets it's own OutputGroup
4234
4228
OutputGroup coin (effective_feerate, long_term_feerate);
4235
- coin.Insert (input_coin, output.nDepth , output.tx ->IsFromMe (ISMINE_ALL), ancestors, descendants);
4236
- if (coin.EligibleForSpending (filter)) groups.push_back (coin);
4229
+ coin.Insert (input_coin, output.nDepth , output.tx ->IsFromMe (ISMINE_ALL), ancestors, descendants, positive_only);
4230
+ if (positive_only && coin.effective_value <= 0 ) continue ;
4231
+ if (coin.m_outputs .size () > 0 && coin.EligibleForSpending (filter)) groups.push_back (coin);
4237
4232
}
4238
4233
}
4239
4234
}
@@ -4245,7 +4240,8 @@ std::vector<OutputGroup> CWallet::GroupOutputs(const std::vector<COutput>& outpu
4245
4240
group.m_ancestors = max_ancestors - 1 ;
4246
4241
}
4247
4242
// If the OutputGroup is not eligible, don't add it
4248
- if (group.EligibleForSpending (filter)) groups.push_back (group);
4243
+ if (positive_only && group.effective_value <= 0 ) continue ;
4244
+ if (group.m_outputs .size () > 0 && group.EligibleForSpending (filter)) groups.push_back (group);
4249
4245
}
4250
4246
}
4251
4247
return groups;
0 commit comments