mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
partial bitcoin#25331: Add HashWriter without ser-type and ser-version
includes: - faa5425629d35708326b255570c51139aef0c8c4
This commit is contained in:
parent
96685be685
commit
2d99be0aea
30
src/hash.h
30
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<const std::byte> src)
|
||||
{
|
||||
ctx.Write(UCharCast(src.data()), src.size());
|
||||
@ -158,6 +150,26 @@ public:
|
||||
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>
|
||||
CHashWriter& operator<<(const T& obj) {
|
||||
// Serialize to this stream
|
||||
|
Loading…
Reference in New Issue
Block a user