From e5474079f179c5637b6c5f2077a1c5223ea357e1 Mon Sep 17 00:00:00 2001 From: stratospher <44024636+stratospher@users.noreply.github.com> Date: Thu, 29 Jan 2026 14:59:22 +0530 Subject: [PATCH] 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. --- src/wallet/spend.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/wallet/spend.h b/src/wallet/spend.h index debe7d294cc..c1657087e73 100644 --- a/src/wallet/spend.h +++ b/src/wallet/spend.h @@ -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 GetEffectiveTotalAmount() { return total_effective_amount; } + CAmount GetTotalAmount() const { return total_amount; } + std::optional GetEffectiveTotalAmount() const { return total_effective_amount; } + // Returns the appropriate total based on whether fees are being subtracted from outputs + std::optional GetAppropriateTotal(bool subtract_fee_outputs) const { + return subtract_fee_outputs ? total_amount : total_effective_amount; + } private: /** Sum of all available coins raw value */