| 493 | } |
| 494 | |
| 495 | CAmount 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: |
| 523 | CAmount GetSelectionWaste(const std::set<CInputCoin>& inputs, CAmount change_cost, const CAmountMap& target_map, bool use_effective_value) |