14
14
#include < util/strencodings.h>
15
15
#include < util/transaction_identifier.h>
16
16
17
+ #include < algorithm>
17
18
#include < cassert>
18
19
#include < stdexcept>
19
20
@@ -70,6 +71,13 @@ Txid CMutableTransaction::GetHash() const
70
71
return Txid::FromUint256 ((HashWriter{} << TX_NO_WITNESS (*this )).GetHash ());
71
72
}
72
73
74
+ bool CTransaction::ComputeHasWitness () const
75
+ {
76
+ return std::any_of (vin.begin (), vin.end (), [](const auto & input) {
77
+ return !input.scriptWitness .IsNull ();
78
+ });
79
+ }
80
+
73
81
Txid CTransaction::ComputeHash () const
74
82
{
75
83
return Txid::FromUint256 ((HashWriter{} << TX_NO_WITNESS (*this )).GetHash ());
@@ -84,8 +92,8 @@ Wtxid CTransaction::ComputeWitnessHash() const
84
92
return Wtxid::FromUint256 ((HashWriter{} << TX_WITH_WITNESS (*this )).GetHash ());
85
93
}
86
94
87
- CTransaction::CTransaction (const CMutableTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash{ComputeHash ()}, m_witness_hash{ComputeWitnessHash ()} {}
88
- 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 ()} {}
95
+ 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 ()} {}
96
+ 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 ()} {}
89
97
90
98
CAmount CTransaction::GetValueOut () const
91
99
{
0 commit comments