diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -9,6 +9,8 @@ #include #include +#include + std::string COutPoint::ToString() const { return strprintf("COutPoint(%s, %u)", txid.ToString().substr(0, 10), n); } @@ -74,12 +76,14 @@ Amount CTransaction::GetValueOut() const { Amount nValueOut = Amount::zero(); for (const auto &tx_out : vout) { - nValueOut += tx_out.nValue; - if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut)) { + if (!MoneyRange(tx_out.nValue) || + !MoneyRange(nValueOut + tx_out.nValue)) { throw std::runtime_error(std::string(__func__) + ": value out of range"); } + nValueOut += tx_out.nValue; } + assert(MoneyRange(nValueOut)); return nValueOut; }