wallet: introduce GetAppropriateTotal() in CoinsResult
What changed, and why it matters
This is a small, clean code refactor inside the Bitcoin Core wallet. It moves an existing calculation into a new helper function and makes a few methods 'const' (read-only). There is no change to behavior, no bug fix, and no security issue visible in the diff.
No action required. Treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adds CoinsResult::GetAppropriateTotal(bool subtract_fee_outputs), which returns total_amount when SFFO (subtract fee from outputs) is enabled and total_effective_amount otherwise. It also marks GetTotalAmount() and GetEffectiveTotalAmount() as const. The logic previously existed inside PreSelectedInputs::Insert(); this change merely centralizes it and returns an std::optional to force callers to handle the unset effective-amount case. No logic or security boundary changes are present.
Changed components
src/wallet/spend.hInspect captured patch +6 / −2
diff --git a/src/wallet/spend.h b/src/wallet/spend.h
index debe7d29..c1657087 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<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 */
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.