Browse Source

CTransaction, GetValueOut(bool fExcludeKeva)

cn
Jianping Wu 6 years ago
parent
commit
29eb41121d
  1. 7
      src/primitives/transaction.cpp
  2. 2
      src/primitives/transaction.h

7
src/primitives/transaction.cpp

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
#include <primitives/transaction.h>
#include <hash.h>
#include <script/keva.h>
#include <tinyformat.h>
#include <utilstrencodings.h>
@ -86,11 +87,13 @@ CTransaction::CTransaction() : vin(), vout(), nVersion(CTransaction::CURRENT_VER @@ -86,11 +87,13 @@ CTransaction::CTransaction() : vin(), vout(), nVersion(CTransaction::CURRENT_VER
CTransaction::CTransaction(const CMutableTransaction &tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash(ComputeHash()) {}
CTransaction::CTransaction(CMutableTransaction &&tx) : vin(std::move(tx.vin)), vout(std::move(tx.vout)), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash(ComputeHash()) {}
CAmount CTransaction::GetValueOut() const
CAmount CTransaction::GetValueOut(bool fExcludeKeva) const
{
CAmount nValueOut = 0;
for (const auto& tx_out : vout) {
nValueOut += tx_out.nValue;
if (!fExcludeKeva || !CKevaScript::isKevaScript(tx_out.scriptPubKey)) {
nValueOut += tx_out.nValue;
}
if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut))
throw std::runtime_error(std::string(__func__) + ": value out of range");
}

2
src/primitives/transaction.h

@ -320,7 +320,7 @@ public: @@ -320,7 +320,7 @@ public:
uint256 GetWitnessHash() const;
// Return sum of txouts.
CAmount GetValueOut() const;
CAmount GetValueOut(bool fExcludeKeva = false) const;
// GetValueIn() is a method on CCoinsViewCache, because
// inputs must be known to compute value in.

Loading…
Cancel
Save