5
5
#include < wallet/coinselection.h>
6
6
7
7
#include < optional.h>
8
+ #include < policy/feerate.h>
8
9
#include < util/system.h>
9
10
#include < util/moneystr.h>
10
11
@@ -311,7 +312,9 @@ void OutputGroup::Insert(const CInputCoin& output, int depth, bool from_me, size
311
312
// descendants is the count as seen from the top ancestor, not the descendants as seen from the
312
313
// coin itself; thus, this value is counted as the max, not the sum
313
314
m_descendants = std::max (m_descendants, descendants);
314
- effective_value = m_value;
315
+ effective_value += output.effective_value ;
316
+ fee += output.m_fee ;
317
+ long_term_fee += output.m_long_term_fee ;
315
318
}
316
319
317
320
std::vector<CInputCoin>::iterator OutputGroup::Discard (const CInputCoin& output) {
@@ -320,6 +323,8 @@ std::vector<CInputCoin>::iterator OutputGroup::Discard(const CInputCoin& output)
320
323
if (it == m_outputs.end ()) return it;
321
324
m_value -= output.txout .nValue ;
322
325
effective_value -= output.effective_value ;
326
+ fee -= output.m_fee ;
327
+ long_term_fee -= output.m_long_term_fee ;
323
328
return m_outputs.erase (it);
324
329
}
325
330
@@ -329,3 +334,35 @@ bool OutputGroup::EligibleForSpending(const CoinEligibilityFilter& eligibility_f
329
334
&& m_ancestors <= eligibility_filter.max_ancestors
330
335
&& m_descendants <= eligibility_filter.max_descendants ;
331
336
}
337
+
338
+ void OutputGroup::SetFees (const CFeeRate effective_feerate, const CFeeRate long_term_feerate)
339
+ {
340
+ fee = 0 ;
341
+ long_term_fee = 0 ;
342
+ effective_value = 0 ;
343
+ for (CInputCoin& coin : m_outputs) {
344
+ coin.m_fee = coin.m_input_bytes < 0 ? 0 : effective_feerate.GetFee (coin.m_input_bytes );
345
+ fee += coin.m_fee ;
346
+
347
+ coin.m_long_term_fee = coin.m_input_bytes < 0 ? 0 : long_term_feerate.GetFee (coin.m_input_bytes );
348
+ long_term_fee += coin.m_long_term_fee ;
349
+
350
+ coin.effective_value = coin.txout .nValue - coin.m_fee ;
351
+ effective_value += coin.effective_value ;
352
+ }
353
+ }
354
+
355
+ OutputGroup OutputGroup::GetPositiveOnlyGroup ()
356
+ {
357
+ OutputGroup group (*this );
358
+ for (auto it = group.m_outputs .begin (); it != group.m_outputs .end (); ) {
359
+ const CInputCoin& coin = *it;
360
+ // Only include outputs that are positive effective value (i.e. not dust)
361
+ if (coin.effective_value <= 0 ) {
362
+ it = group.Discard (coin);
363
+ } else {
364
+ ++it;
365
+ }
366
+ }
367
+ return group;
368
+ }
0 commit comments