1515#include < util/transaction_identifier.h>
1616#include < version.h>
1717
18+ #include < algorithm>
1819#include < cassert>
1920#include < stdexcept>
2021
@@ -71,6 +72,13 @@ Txid CMutableTransaction::GetHash() const
7172 return Txid::FromUint256 ((CHashWriter{SERIALIZE_TRANSACTION_NO_WITNESS} << *this ).GetHash ());
7273}
7374
75+ bool CTransaction::ComputeHasWitness () const
76+ {
77+ return std::any_of (vin.begin (), vin.end (), [](const auto & input) {
78+ return !input.scriptWitness .IsNull ();
79+ });
80+ }
81+
7482Txid CTransaction::ComputeHash () const
7583{
7684 return Txid::FromUint256 ((CHashWriter{SERIALIZE_TRANSACTION_NO_WITNESS} << *this ).GetHash ());
@@ -85,8 +93,8 @@ Wtxid CTransaction::ComputeWitnessHash() const
8593 return Wtxid::FromUint256 ((CHashWriter{0 } << *this ).GetHash ());
8694}
8795
88- CTransaction::CTransaction (const CMutableTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash{ComputeHash ()}, m_witness_hash{ComputeWitnessHash ()} {}
89- CTransaction::CTransaction (CMutableTransaction&& tx) : vin(std::move(tx.vin)), vout(std::move(tx.vout)), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash{ComputeHash ()}, m_witness_hash{ComputeWitnessHash ()} {}
96+ CTransaction::CTransaction (const CMutableTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime), m_has_witness{ ComputeHasWitness ()}, hash{ComputeHash ()}, m_witness_hash{ComputeWitnessHash ()} {}
97+ CTransaction::CTransaction (CMutableTransaction&& tx) : vin(std::move(tx.vin)), vout(std::move(tx.vout)), nVersion(tx.nVersion), nLockTime(tx.nLockTime), m_has_witness{ ComputeHasWitness ()}, hash{ComputeHash ()}, m_witness_hash{ComputeWitnessHash ()} {}
9098
9199CAmount CTransaction::GetValueOut () const
92100{
0 commit comments