mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
Remove CHashWriter type
The type is only ever set, but never read via GetType(), so remove it. Also, remove SerializeHash to avoid silent merge conflicts and use the already existing GetHash() boilerplate consistently.
This commit is contained in:
parent
fa4a9c0f43
commit
fa72f09d6f
6 changed files with 8 additions and 19 deletions
13
src/hash.h
13
src/hash.h
|
@ -149,13 +149,11 @@ public:
|
|||
class CHashWriter : public HashWriter
|
||||
{
|
||||
private:
|
||||
const int nType;
|
||||
const int nVersion;
|
||||
|
||||
public:
|
||||
CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {}
|
||||
CHashWriter(int nVersionIn) : nVersion{nVersionIn} {}
|
||||
|
||||
int GetType() const { return nType; }
|
||||
int GetVersion() const { return nVersion; }
|
||||
|
||||
template<typename T>
|
||||
|
@ -223,15 +221,6 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/** Compute the 256-bit hash of an object's serialization. */
|
||||
template<typename T>
|
||||
uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
|
||||
{
|
||||
CHashWriter ss(nType, nVersion);
|
||||
ss << obj;
|
||||
return ss.GetHash();
|
||||
}
|
||||
|
||||
/** Single-SHA256 a 32-byte input (represented as uint256). */
|
||||
[[nodiscard]] uint256 SHA256Uint256(const uint256& input);
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
uint256 CBlockHeader::GetHash() const
|
||||
{
|
||||
return SerializeHash(*this);
|
||||
return (CHashWriter{PROTOCOL_VERSION} << *this).GetHash();
|
||||
}
|
||||
|
||||
std::string CBlock::ToString() const
|
||||
|
|
|
@ -67,12 +67,12 @@ CMutableTransaction::CMutableTransaction(const CTransaction& tx) : vin(tx.vin),
|
|||
|
||||
uint256 CMutableTransaction::GetHash() const
|
||||
{
|
||||
return SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS);
|
||||
return (CHashWriter{SERIALIZE_TRANSACTION_NO_WITNESS} << *this).GetHash();
|
||||
}
|
||||
|
||||
uint256 CTransaction::ComputeHash() const
|
||||
{
|
||||
return SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS);
|
||||
return (CHashWriter{SERIALIZE_TRANSACTION_NO_WITNESS} << *this).GetHash();
|
||||
}
|
||||
|
||||
uint256 CTransaction::ComputeWitnessHash() const
|
||||
|
@ -80,7 +80,7 @@ uint256 CTransaction::ComputeWitnessHash() const
|
|||
if (!HasWitness()) {
|
||||
return hash;
|
||||
}
|
||||
return SerializeHash(*this, SER_GETHASH, 0);
|
||||
return (CHashWriter{0} << *this).GetHash();
|
||||
}
|
||||
|
||||
CTransaction::CTransaction(const CMutableTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {}
|
||||
|
|
|
@ -122,7 +122,7 @@ BOOST_AUTO_TEST_CASE(siphash)
|
|||
(uint64_t(x+4)<<32)|(uint64_t(x+5)<<40)|(uint64_t(x+6)<<48)|(uint64_t(x+7)<<56));
|
||||
}
|
||||
|
||||
CHashWriter ss(SER_DISK, CLIENT_VERSION);
|
||||
CHashWriter ss{CLIENT_VERSION};
|
||||
CMutableTransaction tx;
|
||||
// Note these tests were originally written with tx.nVersion=1
|
||||
// and the test would be affected by default tx version bumps if not fixed.
|
||||
|
|
|
@ -176,7 +176,7 @@ BOOST_AUTO_TEST_CASE(vector_bool)
|
|||
std::vector<bool> vec2{1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1};
|
||||
|
||||
BOOST_CHECK(vec1 == std::vector<uint8_t>(vec2.begin(), vec2.end()));
|
||||
BOOST_CHECK(SerializeHash(vec1) == SerializeHash(vec2));
|
||||
BOOST_CHECK((HashWriter{} << vec1).GetHash() == (HashWriter{} << vec2).GetHash());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(noncanonical)
|
||||
|
|
|
@ -78,7 +78,7 @@ uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, un
|
|||
}
|
||||
|
||||
// Serialize and hash
|
||||
CHashWriter ss(SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS);
|
||||
CHashWriter ss{SERIALIZE_TRANSACTION_NO_WITNESS};
|
||||
ss << txTmp << nHashType;
|
||||
return ss.GetHash();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue