Implement basic Sapling v4 transaction parser

Details of Sapling datatypes will be filled in later; for now, they are treated
as binary blobs.

Includes code cherry-picked from upstream commit:
    7030d9eb47254499bba14f1c00abc6bf493efd91
    BIP144: Serialization, hashes, relay (sender side)
This commit is contained in:
Jack Grigg
2018-04-15 08:53:40 -06:00
parent 987b8ee60e
commit b7e75b17af
6 changed files with 257 additions and 31 deletions

View File

@@ -22,6 +22,53 @@
#include <utility>
#include <vector>
template<typename Stream>
class OverrideStream
{
Stream* stream;
const int nType;
const int nVersion;
public:
OverrideStream(Stream* stream_, int nType_, int nVersion_) : stream(stream_), nType(nType_), nVersion(nVersion_) {}
template<typename T>
OverrideStream<Stream>& operator<<(const T& obj)
{
// Serialize to this stream
::Serialize(*this, obj);
return (*this);
}
template<typename T>
OverrideStream<Stream>& operator>>(T&& obj)
{
// Unserialize from this stream
::Unserialize(*this, obj);
return (*this);
}
void write(const char* pch, size_t nSize)
{
stream->write(pch, nSize);
}
void read(char* pch, size_t nSize)
{
stream->read(pch, nSize);
}
int GetVersion() const { return nVersion; }
int GetType() const { return nType; }
};
template<typename S>
OverrideStream<S> WithVersion(S* s, int nVersion)
{
return OverrideStream<S>(s, s->GetType(), nVersion);
}
/** Double ended buffer combining vector and stream-like interfaces.
*
* >> and << read and write unformatted data using the above serialization templates.