4
4
5
5
#include < wallet/coinselection.h>
6
6
7
+ #include < policy/feerate.h>
7
8
#include < util/system.h>
8
9
#include < util/moneystr.h>
9
10
@@ -365,7 +366,7 @@ bool KnapsackSolver(const CAmount& nTargetValue, std::vector<OutputGroup>& group
365
366
void OutputGroup::Insert (const CInputCoin& output, int depth, bool from_me, size_t ancestors, size_t descendants) {
366
367
m_outputs.push_back (output);
367
368
m_from_me &= from_me;
368
- m_value += output.effective_value ;
369
+ m_value += output.txout . nValue ;
369
370
m_depth = std::min (m_depth, depth);
370
371
// ancestors here express the number of ancestors the new coin will end up having, which is
371
372
// the sum, rather than the max; this will overestimate in the cases where multiple inputs
@@ -374,15 +375,19 @@ void OutputGroup::Insert(const CInputCoin& output, int depth, bool from_me, size
374
375
// descendants is the count as seen from the top ancestor, not the descendants as seen from the
375
376
// coin itself; thus, this value is counted as the max, not the sum
376
377
m_descendants = std::max (m_descendants, descendants);
377
- effective_value = m_value;
378
+ effective_value += output.effective_value ;
379
+ fee += output.m_fee ;
380
+ long_term_fee += output.m_long_term_fee ;
378
381
}
379
382
380
383
std::vector<CInputCoin>::iterator OutputGroup::Discard (const CInputCoin& output) {
381
384
auto it = m_outputs.begin ();
382
385
while (it != m_outputs.end () && it->outpoint != output.outpoint ) ++it;
383
386
if (it == m_outputs.end ()) return it;
384
- m_value -= output.effective_value ;
387
+ m_value -= output.txout . nValue ;
385
388
effective_value -= output.effective_value ;
389
+ fee -= output.m_fee ;
390
+ long_term_fee -= output.m_long_term_fee ;
386
391
return m_outputs.erase (it);
387
392
}
388
393
@@ -401,3 +406,35 @@ bool OutputGroup::EligibleForSpending(const CoinEligibilityFilter& eligibility_f
401
406
&& m_ancestors <= eligibility_filter.max_ancestors
402
407
&& m_descendants <= eligibility_filter.max_descendants ;
403
408
}
409
+
410
+ void OutputGroup::SetFees (const CFeeRate effective_feerate, const CFeeRate long_term_feerate)
411
+ {
412
+ fee = 0 ;
413
+ long_term_fee = 0 ;
414
+ effective_value = 0 ;
415
+ for (CInputCoin& coin : m_outputs) {
416
+ coin.m_fee = coin.m_input_bytes < 0 ? 0 : effective_feerate.GetFee (coin.m_input_bytes );
417
+ fee += coin.m_fee ;
418
+
419
+ coin.m_long_term_fee = coin.m_input_bytes < 0 ? 0 : long_term_feerate.GetFee (coin.m_input_bytes );
420
+ long_term_fee += coin.m_long_term_fee ;
421
+
422
+ coin.effective_value = coin.txout .nValue - coin.m_fee ;
423
+ effective_value += coin.effective_value ;
424
+ }
425
+ }
426
+
427
+ OutputGroup OutputGroup::GetPositiveOnlyGroup ()
428
+ {
429
+ OutputGroup group (*this );
430
+ for (auto it = group.m_outputs .begin (); it != group.m_outputs .end (); ) {
431
+ const CInputCoin& coin = *it;
432
+ // Only include outputs that are positive effective value (i.e. not dust)
433
+ if (coin.effective_value <= 0 ) {
434
+ it = group.Discard (coin);
435
+ } else {
436
+ ++it;
437
+ }
438
+ }
439
+ return group;
440
+ }
0 commit comments