From c1a84f108e320bd44c172a4dd3bb486ab777ff69 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Mon, 5 Dec 2022 14:33:35 -0500 Subject: [PATCH] wallet: Move fee underpayment check to after fee setting It doesn't make sense to be checking whether the fee paid is underpaying before we've finished setting the fees. So do that after we have done the reduction for SFFO and change adjustment for fee overpayment. --- src/primitives/transaction.h | 7 +++++++ src/wallet/spend.cpp | 27 ++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index f496ea022e6..6b4a6335a1a 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -280,6 +281,12 @@ inline void SerializeTransaction(const TxType& tx, Stream& s) { s << tx.nLockTime; } +template +inline CAmount CalculateOutputValue(const TxType& tx) +{ + return std::accumulate(tx.vout.cbegin(), tx.vout.cend(), CAmount{0}, [](CAmount sum, const auto& txout) { return sum + txout.nValue; }); +} + /** The basic transaction that is broadcasted on the network and contained in * blocks. A transaction can contain multiple inputs and outputs. diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index d92fd52ead1..a1a98381e5a 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include