MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetSelectionWaste

Function GetSelectionWaste

src/wallet/coinselection.cpp:495–520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493}
494
495CAmount GetSelectionWaste(const std::set<CInputCoin>& inputs, CAmount change_cost, CAmount target, bool use_effective_value)
496{
497 // This function should not be called with empty inputs as that would mean the selection failed
498 assert(!inputs.empty());
499
500 // Always consider the cost of spending an input now vs in the future.
501 CAmount waste = 0;
502 CAmount selected_effective_value = 0;
503 for (const CInputCoin& coin : inputs) {
504 waste += coin.m_fee - coin.m_long_term_fee;
505 selected_effective_value += use_effective_value ? coin.effective_value : coin.value;
506 }
507
508 if (change_cost) {
509 // Consider the cost of making change and spending it in the future
510 // If we aren't making change, the caller should've set change_cost to 0
511 assert(change_cost > 0);
512 waste += change_cost;
513 } else {
514 // When we are not making change (change_cost == 0), consider the excess we are throwing away to fees
515 assert(selected_effective_value >= target);
516 waste += selected_effective_value - target;
517 }
518
519 return waste;
520}
521
522// ELEMENTS:
523CAmount GetSelectionWaste(const std::set<CInputCoin>& inputs, CAmount change_cost, const CAmountMap& target_map, bool use_effective_value)

Callers 2

ComputeAndSetWasteMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 5

findMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68