Build enough information into the leaf nodes so that they can be parsed

without knowledge of the objects they contain. This will allow new
transaction or account formats to be added (possibly with larger data sizes)
without breaking the ability to parse the hash trees. It also simplifies
the operation-specific tree code (since it doesn't have to parse the raw
leaf data).
This commit is contained in:
JoelKatz
2011-11-28 13:59:34 -08:00
parent e87a027df2
commit ebb9a9c255
6 changed files with 94 additions and 28 deletions

View File

@@ -4,6 +4,17 @@
#include <openssl/ripemd.h>
#include <openssl/sha.h>
int Serializer::add16(uint16 i)
{
int ret=mData.size();
for(int j=0; j<sizeof(i); j++)
{
mData.push_back((unsigned char) (i&0xff));
i>>=8;
}
return ret;
}
int Serializer::add32(uint32 i)
{
int ret=mData.size();
@@ -47,8 +58,21 @@ int Serializer::addRaw(const std::vector<unsigned char> &vector)
return ret;
}
bool Serializer::get16(uint16& o, int offset) const
{
o=0;
if((offset+sizeof(o))>mData.size()) return false;
for(int i=0, o=0; i<sizeof(o); i++)
{
o<<=8;
o|=mData.at(offset++);
}
return true;
}
bool Serializer::get32(uint32& o, int offset) const
{
o=0;
if((offset+sizeof(o))>mData.size()) return false;
for(int i=0, o=0; i<sizeof(o); i++)
{
@@ -60,6 +84,7 @@ bool Serializer::get32(uint32& o, int offset) const
bool Serializer::get64(uint64& o, int offset) const
{
o=0;
if((offset+sizeof(o))>mData.size()) return false;
for(int i=0, o=0; i<sizeof(o); i++)
{