15
15
#include < util/transaction_identifier.h>
16
16
#include < version.h>
17
17
18
+ #include < algorithm>
18
19
#include < cassert>
19
20
#include < stdexcept>
20
21
@@ -71,6 +72,13 @@ Txid CMutableTransaction::GetHash() const
71
72
return Txid::FromUint256 ((CHashWriter{SERIALIZE_TRANSACTION_NO_WITNESS} << *this ).GetHash ());
72
73
}
73
74
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
+
74
82
Txid CTransaction::ComputeHash () const
75
83
{
76
84
return Txid::FromUint256 ((CHashWriter{SERIALIZE_TRANSACTION_NO_WITNESS} << *this ).GetHash ());
@@ -85,8 +93,8 @@ Wtxid CTransaction::ComputeWitnessHash() const
85
93
return Wtxid::FromUint256 ((CHashWriter{0 } << *this ).GetHash ());
86
94
}
87
95
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 ()} {}
90
98
91
99
CAmount CTransaction::GetValueOut () const
92
100
{
0 commit comments