diff options
Diffstat (limited to 'src/primitives')
-rw-r--r-- | src/primitives/transaction.cpp | 9 | ||||
-rw-r--r-- | src/primitives/transaction.h | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 28c145f71d..e6183cf2f4 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2018 The Bitcoin Core developers +// Copyright (c) 2009-2020 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -9,6 +9,8 @@ #include <tinyformat.h> #include <util/strencodings.h> +#include <assert.h> + std::string COutPoint::ToString() const { return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10), n); @@ -84,10 +86,11 @@ CAmount CTransaction::GetValueOut() const { CAmount nValueOut = 0; 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; } diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index d080cf876b..4514db578a 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -305,8 +305,6 @@ public: // Return sum of txouts. CAmount GetValueOut() const; - // GetValueIn() is a method on CCoinsViewCache, because - // inputs must be known to compute value in. /** * Get the total transaction size in bytes, including witness data. |