wallet: introduce GetAppropriateTotal() in CoinsResult

returns the total amount (if SFFO), otherwise the effective amount.
previously, this was the logic in calculating
PreSelectedInputs::total_amount when PreSelectedInputs::Insert()
was called.

return optional to force callers to explicitly handle the case
when effective amount optional is not set.
This commit is contained in:
stratospher
2026-01-29 14:59:22 +05:30
parent d8ea921d01
commit e5474079f1

View File

@@ -58,8 +58,12 @@ struct CoinsResult {
void Shuffle(FastRandomContext& rng_fast);
void Add(OutputType type, const COutput& out);
CAmount GetTotalAmount() { return total_amount; }
std::optional<CAmount> GetEffectiveTotalAmount() { return total_effective_amount; }
CAmount GetTotalAmount() const { return total_amount; }
std::optional<CAmount> GetEffectiveTotalAmount() const { return total_effective_amount; }
// Returns the appropriate total based on whether fees are being subtracted from outputs
std::optional<CAmount> GetAppropriateTotal(bool subtract_fee_outputs) const {
return subtract_fee_outputs ? total_amount : total_effective_amount;
}
private:
/** Sum of all available coins raw value */