mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-06 14:19:59 -05:00
Add HashWriter without ser-type and ser-version
The moved parts can be reviewed with "--color-moved=dimmed-zebra".
This commit is contained in:
parent
1eedde157f
commit
faa5425629
1 changed files with 21 additions and 9 deletions
30
src/hash.h
30
src/hash.h
|
@ -96,20 +96,12 @@ inline uint160 Hash160(const T1& in1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A writer stream (for serialization) that computes a 256-bit hash. */
|
/** A writer stream (for serialization) that computes a 256-bit hash. */
|
||||||
class CHashWriter
|
class HashWriter
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CSHA256 ctx;
|
CSHA256 ctx;
|
||||||
|
|
||||||
const int nType;
|
|
||||||
const int nVersion;
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {}
|
|
||||||
|
|
||||||
int GetType() const { return nType; }
|
|
||||||
int GetVersion() const { return nVersion; }
|
|
||||||
|
|
||||||
void write(Span<const std::byte> src)
|
void write(Span<const std::byte> src)
|
||||||
{
|
{
|
||||||
ctx.Write(UCharCast(src.data()), src.size());
|
ctx.Write(UCharCast(src.data()), src.size());
|
||||||
|
@ -144,6 +136,26 @@ public:
|
||||||
return ReadLE64(result.begin());
|
return ReadLE64(result.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
HashWriter& operator<<(const T& obj)
|
||||||
|
{
|
||||||
|
::Serialize(*this, obj);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CHashWriter : public HashWriter
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
const int nType;
|
||||||
|
const int nVersion;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {}
|
||||||
|
|
||||||
|
int GetType() const { return nType; }
|
||||||
|
int GetVersion() const { return nVersion; }
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
CHashWriter& operator<<(const T& obj) {
|
CHashWriter& operator<<(const T& obj) {
|
||||||
// Serialize to this stream
|
// Serialize to this stream
|
||||||
|
|
Loading…
Add table
Reference in a new issue