Cache witness hash in CTransaction
This commit is contained in:
parent
faab55fbb1
commit
fac1223a56
2 changed files with 9 additions and 11 deletions
src/primitives
|
@ -67,18 +67,18 @@ uint256 CTransaction::ComputeHash() const
|
||||||
return SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS);
|
return SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 CTransaction::GetWitnessHash() const
|
uint256 CTransaction::ComputeWitnessHash() const
|
||||||
{
|
{
|
||||||
if (!HasWitness()) {
|
if (!HasWitness()) {
|
||||||
return GetHash();
|
return hash;
|
||||||
}
|
}
|
||||||
return SerializeHash(*this, SER_GETHASH, 0);
|
return SerializeHash(*this, SER_GETHASH, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For backward compatibility, the hash is initialized to 0. TODO: remove the need for this default constructor entirely. */
|
/* For backward compatibility, the hash is initialized to 0. TODO: remove the need for this default constructor entirely. */
|
||||||
CTransaction::CTransaction() : vin(), vout(), nVersion(CTransaction::CURRENT_VERSION), nLockTime(0), hash() {}
|
CTransaction::CTransaction() : vin(), vout(), nVersion(CTransaction::CURRENT_VERSION), nLockTime(0), hash{}, m_witness_hash{} {}
|
||||||
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()}, m_witness_hash{ComputeWitnessHash()} {}
|
||||||
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()}, m_witness_hash{ComputeWitnessHash()} {}
|
||||||
|
|
||||||
CAmount CTransaction::GetValueOut() const
|
CAmount CTransaction::GetValueOut() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -286,8 +286,10 @@ public:
|
||||||
private:
|
private:
|
||||||
/** Memory only. */
|
/** Memory only. */
|
||||||
const uint256 hash;
|
const uint256 hash;
|
||||||
|
const uint256 m_witness_hash;
|
||||||
|
|
||||||
uint256 ComputeHash() const;
|
uint256 ComputeHash() const;
|
||||||
|
uint256 ComputeWitnessHash() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Construct a CTransaction that qualifies as IsNull() */
|
/** Construct a CTransaction that qualifies as IsNull() */
|
||||||
|
@ -311,12 +313,8 @@ public:
|
||||||
return vin.empty() && vout.empty();
|
return vin.empty() && vout.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint256& GetHash() const {
|
const uint256& GetHash() const { return hash; }
|
||||||
return hash;
|
const uint256& GetWitnessHash() const { return m_witness_hash; };
|
||||||
}
|
|
||||||
|
|
||||||
// Compute a hash that includes both transaction and witness data
|
|
||||||
uint256 GetWitnessHash() const;
|
|
||||||
|
|
||||||
// Return sum of txouts.
|
// Return sum of txouts.
|
||||||
CAmount GetValueOut() const;
|
CAmount GetValueOut() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue