From 2d99be0aea06e81c0ee84dacf213f70663d3966f Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Fri, 10 Jun 2022 10:39:44 +0200 Subject: [PATCH] partial bitcoin#25331: Add HashWriter without ser-type and ser-version includes: - faa5425629d35708326b255570c51139aef0c8c4 --- src/hash.h | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/hash.h b/src/hash.h index 8c491ef3bc..f207744f0d 100644 --- a/src/hash.h +++ b/src/hash.h @@ -110,20 +110,12 @@ inline uint160 Hash160(const T1& in1) } /** A writer stream (for serialization) that computes a 256-bit hash. */ -class CHashWriter +class HashWriter { private: CSHA256 ctx; - 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; } - void write(Span src) { ctx.Write(UCharCast(src.data()), src.size()); @@ -158,6 +150,26 @@ public: return ReadLE64(result.begin()); } + template + 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 CHashWriter& operator<<(const T& obj) { // Serialize to this stream