Skip to content

Commit faa5425

Browse files
author
MacroFake
committed
Add HashWriter without ser-type and ser-version
The moved parts can be reviewed with "--color-moved=dimmed-zebra".
1 parent 1eedde1 commit faa5425

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/hash.h

+21-9
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,12 @@ inline uint160 Hash160(const T1& in1)
9696
}
9797

9898
/** A writer stream (for serialization) that computes a 256-bit hash. */
99-
class CHashWriter
99+
class HashWriter
100100
{
101101
private:
102102
CSHA256 ctx;
103103

104-
const int nType;
105-
const int nVersion;
106104
public:
107-
108-
CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {}
109-
110-
int GetType() const { return nType; }
111-
int GetVersion() const { return nVersion; }
112-
113105
void write(Span<const std::byte> src)
114106
{
115107
ctx.Write(UCharCast(src.data()), src.size());
@@ -144,6 +136,26 @@ class CHashWriter
144136
return ReadLE64(result.begin());
145137
}
146138

139+
template <typename T>
140+
HashWriter& operator<<(const T& obj)
141+
{
142+
::Serialize(*this, obj);
143+
return *this;
144+
}
145+
};
146+
147+
class CHashWriter : public HashWriter
148+
{
149+
private:
150+
const int nType;
151+
const int nVersion;
152+
153+
public:
154+
CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {}
155+
156+
int GetType() const { return nType; }
157+
int GetVersion() const { return nVersion; }
158+
147159
template<typename T>
148160
CHashWriter& operator<<(const T& obj) {
149161
// Serialize to this stream

0 commit comments

Comments
 (0)