Browse Source

CTransaction, GetValueOut(bool fExcludeKeva)

0.16.3-insta
Jianping Wu 6 years ago
parent
commit
024cba1f2e
  1. 5
      src/primitives/transaction.cpp
  2. 2
      src/primitives/transaction.h

5
src/primitives/transaction.cpp

@ -6,6 +6,7 @@
#include <primitives/transaction.h> #include <primitives/transaction.h>
#include <hash.h> #include <hash.h>
#include <script/keva.h>
#include <tinyformat.h> #include <tinyformat.h>
#include <utilstrencodings.h> #include <utilstrencodings.h>
@ -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(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()) {} 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; CAmount nValueOut = 0;
for (const auto& tx_out : vout) { for (const auto& tx_out : vout) {
if (!fExcludeKeva || !CKevaScript::isKevaScript(tx_out.scriptPubKey)) {
nValueOut += tx_out.nValue; nValueOut += tx_out.nValue;
}
if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut)) if (!MoneyRange(tx_out.nValue) || !MoneyRange(nValueOut))
throw std::runtime_error(std::string(__func__) + ": value out of range"); throw std::runtime_error(std::string(__func__) + ": value out of range");
} }

2
src/primitives/transaction.h

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

Loading…
Cancel
Save