mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Parts of the new serialization code. Does not compile yet.
This commit is contained in:
@@ -298,7 +298,7 @@ void STAmount::add(Serializer& s) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STAmount::STAmount(const char* name, int64 value) : SerializedType(name), mOffset(0), mIsNative(true)
|
STAmount::STAmount(FieldName* name, int64 value) : SerializedType(name), mOffset(0), mIsNative(true)
|
||||||
{
|
{
|
||||||
if (value >= 0)
|
if (value >= 0)
|
||||||
{
|
{
|
||||||
@@ -330,7 +330,7 @@ uint64 STAmount::toUInt64() const
|
|||||||
return mValue | (static_cast<uint64>(mOffset + 256 + 97) << (64 - 10));
|
return mValue | (static_cast<uint64>(mOffset + 256 + 97) << (64 - 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
STAmount* STAmount::construct(SerializerIterator& sit, const char *name)
|
STAmount* STAmount::construct(SerializerIterator& sit, FieldName* name)
|
||||||
{
|
{
|
||||||
uint64 value = sit.get64();
|
uint64 value = sit.get64();
|
||||||
|
|
||||||
@@ -883,7 +883,7 @@ uint64 STAmount::convertToDisplayAmount(const STAmount& internalAmount, uint64 t
|
|||||||
}
|
}
|
||||||
|
|
||||||
STAmount STAmount::convertToInternalAmount(uint64 displayAmount, uint64 totalNow, uint64 totalInit,
|
STAmount STAmount::convertToInternalAmount(uint64 displayAmount, uint64 totalNow, uint64 totalInit,
|
||||||
const char *name)
|
FieldName* name)
|
||||||
{ // Convert a display/request currency amount to an internal amount
|
{ // Convert a display/request currency amount to an internal amount
|
||||||
return STAmount(name, muldiv(displayAmount, totalNow, totalInit));
|
return STAmount(name, muldiv(displayAmount, totalNow, totalInit));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,53 @@
|
|||||||
|
|
||||||
#include "FieldNames.h"
|
#include "FieldNames.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <boost/thread/mutex.hpp>
|
||||||
|
|
||||||
#define FIELD(name, type, index) { sf##name, #name, STI_##type, index },
|
#define FIELD(name, type, index) { sf##name, #name, STI_##type, index },
|
||||||
#define TYPE(name, type, index)
|
#define TYPE(name, type, index)
|
||||||
|
|
||||||
FieldName FieldNames[]=
|
FieldName FieldNames[]=
|
||||||
{
|
{
|
||||||
#include "SerializeProto.h"
|
#include "SerializeProto.h"
|
||||||
|
|
||||||
|
{ sfInvalid, 0, STI_DONE, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef FIELD
|
#undef FIELD
|
||||||
#undef TYPE
|
#undef TYPE
|
||||||
|
|
||||||
|
static std::map<int, FieldName*> unknownFieldMap;
|
||||||
|
static boost::mutex unknownFieldMutex;
|
||||||
|
|
||||||
|
FieldName* getFieldName(SOE_Field f)
|
||||||
|
{ // OPTIMIZEME
|
||||||
|
for (FieldName* n = FieldNames; n->fieldName != 0; ++n)
|
||||||
|
if (n->field == f)
|
||||||
|
return n;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
FieldName* getFieldName(int type, int field)
|
||||||
|
{ // OPTIMIZEME
|
||||||
|
int f = (type << 16) | field;
|
||||||
|
for (FieldName* n = FieldNames; n->fieldName != 0; ++n)
|
||||||
|
if (n->field == f)
|
||||||
|
return n;
|
||||||
|
if ((type <= 0) || (type >= 256) || (field <= 0) || (field >= 256
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
boost::mutex::scoped_lock sl(unknownFieldMutex);
|
||||||
|
std::map<int, FieldName*> it = unknownFieldMap.Find(f);
|
||||||
|
if (it != unknownFieldMap.end())
|
||||||
|
return it->second;
|
||||||
|
|
||||||
|
FieldName* n = new FieldName();
|
||||||
|
n->field = f;
|
||||||
|
n->fieldName = "unknown";
|
||||||
|
n->fieldType = static_cast<SerializedTypeID>(type);
|
||||||
|
n->fieldNum = field;
|
||||||
|
unknownFieldMap[f] = n;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,16 +1,56 @@
|
|||||||
#ifndef __FIELDNAMES__
|
#ifndef __FIELDNAMES__
|
||||||
#define __FIELDNAMES__
|
#define __FIELDNAMES__
|
||||||
|
|
||||||
#include "SerializedTypes.h"
|
enum SerializedTypeID
|
||||||
#include "SerializedObject.h"
|
{
|
||||||
|
// special types
|
||||||
|
STI_DONE = -1,
|
||||||
|
STI_NOTPRESENT = 0,
|
||||||
|
|
||||||
|
#define TYPE(name, field, value) STI_##field = value,
|
||||||
|
#define FIELD(name, field, value)
|
||||||
|
#include "SerializeProto.h"
|
||||||
|
#undef TYPE
|
||||||
|
#undef FIELD
|
||||||
|
|
||||||
|
// high level types
|
||||||
|
STI_TRANSACTION = 100001,
|
||||||
|
STI_LEDGERENTRY = 100002,
|
||||||
|
STI_VALIDATION = 100003,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum SOE_Flags
|
||||||
|
{
|
||||||
|
SOE_END = -1, // marks end of object
|
||||||
|
SOE_REQUIRED = 0, // required
|
||||||
|
SOE_OPTIONAL = 1, // optional
|
||||||
|
};
|
||||||
|
|
||||||
|
enum SOE_Field
|
||||||
|
{
|
||||||
|
sfInvalid = -1,
|
||||||
|
sfGeneric = 0,
|
||||||
|
|
||||||
|
#define FIELD(name, type, index) sf##name = (STI_##type << 16) | index,
|
||||||
|
#define TYPE(name, type, index)
|
||||||
|
#include "SerializeProto.h"
|
||||||
|
#undef FIELD
|
||||||
|
#undef TYPE
|
||||||
|
|
||||||
|
// test fields
|
||||||
|
sfTest1=100000, sfTest2, sfTest3, sfTest4
|
||||||
|
};
|
||||||
|
|
||||||
struct FieldName
|
struct FieldName
|
||||||
{
|
{
|
||||||
SOE_Field field;
|
SOE_Field field;
|
||||||
const char *fieldName;
|
const char *fieldName;
|
||||||
SerializedTypeID fieldType;
|
SerializedTypeID fieldType;
|
||||||
int fieldValue;
|
int fieldNum;
|
||||||
int fieldID;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern FieldName FieldNames[];
|
||||||
|
extern FieldName* getFieldName(SOE_Field);
|
||||||
|
extern FieldName* getFieldName(int type, int field);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,89 +1,87 @@
|
|||||||
|
|
||||||
#include "LedgerFormats.h"
|
#include "LedgerFormats.h"
|
||||||
|
|
||||||
#define S_FIELD(x) sf##x, #x
|
|
||||||
|
|
||||||
LedgerEntryFormat LedgerFormats[]=
|
LedgerEntryFormat LedgerFormats[]=
|
||||||
{
|
{
|
||||||
{ "AccountRoot", ltACCOUNT_ROOT, {
|
{ "AccountRoot", ltACCOUNT_ROOT, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Account), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfAccount, SOE_REQUIRED },
|
||||||
{ S_FIELD(Sequence), STI_UINT32, SOE_REQUIRED, 0 },
|
{ sfSequence, SOE_REQUIRED },
|
||||||
{ S_FIELD(Balance), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfBalance, SOE_REQUIRED },
|
||||||
{ S_FIELD(LastTxnID), STI_HASH256, SOE_REQUIRED, 0 },
|
{ sfLastTxnID, SOE_REQUIRED },
|
||||||
{ S_FIELD(LastTxnSeq), STI_UINT32, SOE_REQUIRED, 0 },
|
{ sfLastTxnSeq, SOE_REQUIRED },
|
||||||
{ S_FIELD(AuthorizedKey), STI_ACCOUNT, SOE_IFFLAG, 1 },
|
{ sfAuthorizedKey, SOE_OPTIONAL },
|
||||||
{ S_FIELD(EmailHash), STI_HASH128, SOE_IFFLAG, 2 },
|
{ sfEmailHash, SOE_OPTIONAL },
|
||||||
{ S_FIELD(WalletLocator), STI_HASH256, SOE_IFFLAG, 4 },
|
{ sfWalletLocator, SOE_OPTIONAL },
|
||||||
{ S_FIELD(MessageKey), STI_VL, SOE_IFFLAG, 8 },
|
{ sfMessageKey, SOE_OPTIONAL },
|
||||||
{ S_FIELD(TransferRate), STI_UINT32, SOE_IFFLAG, 16 },
|
{ sfTransferRate, SOE_OPTIONAL },
|
||||||
{ S_FIELD(Domain), STI_VL, SOE_IFFLAG, 32 },
|
{ sfDomain, SOE_OPTIONAL },
|
||||||
{ S_FIELD(PublishHash), STI_HASH256, SOE_IFFLAG, 64 },
|
{ sfPublishHash, SOE_OPTIONAL },
|
||||||
{ S_FIELD(PublishSize), STI_UINT32, SOE_IFFLAG, 128 },
|
{ sfPublishSize, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "Contract", ltCONTRACT, {
|
{ "Contract", ltCONTRACT, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Account), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfAccount, SOE_REQUIRED },
|
||||||
{ S_FIELD(Balance), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfBalance, SOE_REQUIRED },
|
||||||
{ S_FIELD(LastTxnID), STI_HASH256, SOE_REQUIRED, 0 },
|
{ sfLastTxnID, SOE_REQUIRED },
|
||||||
{ S_FIELD(LastTxnSeq), STI_UINT32, SOE_REQUIRED, 0 },
|
{ sfLastTxnSeq, SOE_REQUIRED },
|
||||||
{ S_FIELD(Issuer), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfIssuer, SOE_REQUIRED },
|
||||||
{ S_FIELD(Owner), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfOwner, SOE_REQUIRED },
|
||||||
{ S_FIELD(Expiration), STI_UINT32, SOE_REQUIRED, 0 },
|
{ sfExpiration, SOE_REQUIRED },
|
||||||
{ S_FIELD(BondAmount), STI_UINT32, SOE_REQUIRED, 0 },
|
{ sfBondAmount, SOE_REQUIRED },
|
||||||
{ S_FIELD(CreateCode), STI_VL, SOE_REQUIRED, 0 },
|
{ sfCreateCode, SOE_REQUIRED },
|
||||||
{ S_FIELD(FundCode), STI_VL, SOE_REQUIRED, 0 },
|
{ sfFundCode, SOE_REQUIRED },
|
||||||
{ S_FIELD(RemoveCode), STI_VL, SOE_REQUIRED, 0 },
|
{ sfRemoveCode, SOE_REQUIRED },
|
||||||
{ S_FIELD(ExpireCode), STI_VL, SOE_REQUIRED, 0 },
|
{ sfExpireCode, SOE_REQUIRED },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "DirectoryNode", ltDIR_NODE, {
|
{ "DirectoryNode", ltDIR_NODE, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Indexes), STI_VECTOR256, SOE_REQUIRED, 0 },
|
{ sfIndexes, SOE_REQUIRED },
|
||||||
{ S_FIELD(IndexNext), STI_UINT64, SOE_IFFLAG, 1 },
|
{ sfIndexNext, SOE_OPTIONAL },
|
||||||
{ S_FIELD(IndexPrevious), STI_UINT64, SOE_IFFLAG, 2 },
|
{ sfIndexPrevious, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "GeneratorMap", ltGENERATOR_MAP, {
|
{ "GeneratorMap", ltGENERATOR_MAP, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Generator), STI_VL, SOE_REQUIRED, 0 },
|
{ sfGenerator, SOE_REQUIRED },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "Nickname", ltNICKNAME, {
|
{ "Nickname", ltNICKNAME, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Account), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfAccount, SOE_REQUIRED },
|
||||||
{ S_FIELD(MinimumOffer), STI_AMOUNT, SOE_IFFLAG, 1 },
|
{ sfMinimumOffer, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "Offer", ltOFFER, {
|
{ "Offer", ltOFFER, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Account), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfAccount, SOE_REQUIRED },
|
||||||
{ S_FIELD(Sequence), STI_UINT32, SOE_REQUIRED, 0 },
|
{ sfSequence, SOE_REQUIRED },
|
||||||
{ S_FIELD(TakerPays), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfTakerPays, SOE_REQUIRED },
|
||||||
{ S_FIELD(TakerGets), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfTakerGets, SOE_REQUIRED },
|
||||||
{ S_FIELD(BookDirectory), STI_HASH256, SOE_REQUIRED, 0 },
|
{ sfBookDirectory, SOE_REQUIRED },
|
||||||
{ S_FIELD(BookNode), STI_UINT64, SOE_REQUIRED, 0 },
|
{ sfBookNode, SOE_REQUIRED },
|
||||||
{ S_FIELD(OwnerNode), STI_UINT64, SOE_REQUIRED, 0 },
|
{ sfOwnerNode, SOE_REQUIRED },
|
||||||
{ S_FIELD(LastTxnID), STI_HASH256, SOE_REQUIRED, 0 },
|
{ sfLastTxnID, SOE_REQUIRED },
|
||||||
{ S_FIELD(LastTxnSeq), STI_UINT32, SOE_REQUIRED, 0 },
|
{ sfLastTxnSeq, SOE_REQUIRED },
|
||||||
{ S_FIELD(Expiration), STI_UINT32, SOE_IFFLAG, 1 },
|
{ sfExpiration, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "RippleState", ltRIPPLE_STATE, {
|
{ "RippleState", ltRIPPLE_STATE, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Balance), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfBalance, SOE_REQUIRED },
|
||||||
{ S_FIELD(LowID), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfLowID, SOE_REQUIRED },
|
||||||
{ S_FIELD(LowLimit), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfLowLimit, SOE_REQUIRED },
|
||||||
{ S_FIELD(HighID), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfHighID, SOE_REQUIRED },
|
||||||
{ S_FIELD(HighLimit), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfHighLimit, SOE_REQUIRED },
|
||||||
{ S_FIELD(LastTxnID), STI_HASH256, SOE_REQUIRED, 0 },
|
{ sfLastTxnID, SOE_REQUIRED },
|
||||||
{ S_FIELD(LastTxnSeq), STI_UINT32, SOE_REQUIRED, 0 },
|
{ sfLastTxnSeq, SOE_REQUIRED },
|
||||||
{ S_FIELD(LowQualityIn), STI_UINT32, SOE_IFFLAG, 1 },
|
{ sfLowQualityIn, SOE_OPTIONAL },
|
||||||
{ S_FIELD(LowQualityOut), STI_UINT32, SOE_IFFLAG, 2 },
|
{ sfLowQualityOut, SOE_OPTIONAL },
|
||||||
{ S_FIELD(HighQualityIn), STI_UINT32, SOE_IFFLAG, 4 },
|
{ sfHighQualityIn, SOE_OPTIONAL },
|
||||||
{ S_FIELD(HighQualityOut), STI_UINT32, SOE_IFFLAG, 8 },
|
{ sfHighQualityOut, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ NULL, ltINVALID }
|
{ NULL, ltINVALID }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ enum LedgerSpecificFlags
|
|||||||
|
|
||||||
struct LedgerEntryFormat
|
struct LedgerEntryFormat
|
||||||
{
|
{
|
||||||
const char *t_name;
|
const char * t_name;
|
||||||
LedgerEntryType t_type;
|
LedgerEntryType t_type;
|
||||||
SOElement elements[20];
|
SOElement elements[24];
|
||||||
};
|
};
|
||||||
|
|
||||||
extern LedgerEntryFormat LedgerFormats[];
|
extern LedgerEntryFormat LedgerFormats[];
|
||||||
|
|||||||
@@ -27,17 +27,18 @@
|
|||||||
FIELD(CloseResolution, UINT8, 1)
|
FIELD(CloseResolution, UINT8, 1)
|
||||||
|
|
||||||
// 32-bit integers (common)
|
// 32-bit integers (common)
|
||||||
FIELD(Flags, UINT32, 1)
|
FIELD(ObjectType, UINT32, 1)
|
||||||
FIELD(SourceTag, UINT32, 2)
|
FIELD(Flags, UINT32, 2)
|
||||||
FIELD(Sequence, UINT32, 3)
|
FIELD(SourceTag, UINT32, 3)
|
||||||
FIELD(LastTxnSeq, UINT32, 4)
|
FIELD(Sequence, UINT32, 4)
|
||||||
FIELD(LedgerSequence, UINT32, 5)
|
FIELD(LastTxnSeq, UINT32, 5)
|
||||||
FIELD(CloseTime, UINT32, 6)
|
FIELD(LedgerSequence, UINT32, 6)
|
||||||
FIELD(ParentCloseTime, UINT32, 7)
|
FIELD(CloseTime, UINT32, 7)
|
||||||
FIELD(SigningTime, UINT32, 8)
|
FIELD(ParentCloseTime, UINT32, 8)
|
||||||
FIELD(Expiration, UINT32, 9)
|
FIELD(SigningTime, UINT32, 9)
|
||||||
FIELD(TransferRate, UINT32, 10)
|
FIELD(Expiration, UINT32, 10)
|
||||||
FIELD(PublishSize, UINT32, 11)
|
FIELD(TransferRate, UINT32, 11)
|
||||||
|
FIELD(PublishSize, UINT32, 12)
|
||||||
|
|
||||||
// 32-bit integers (uncommon)
|
// 32-bit integers (uncommon)
|
||||||
FIELD(HighQualityIn, UINT32, 16)
|
FIELD(HighQualityIn, UINT32, 16)
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ public:
|
|||||||
SerializedLedgerEntry(SerializerIterator& sit, const uint256& index);
|
SerializedLedgerEntry(SerializerIterator& sit, const uint256& index);
|
||||||
SerializedLedgerEntry(LedgerEntryType type);
|
SerializedLedgerEntry(LedgerEntryType type);
|
||||||
|
|
||||||
int getLength() const { return mVersion.getLength() + mObject.getLength(); }
|
|
||||||
SerializedTypeID getSType() const { return STI_LEDGERENTRY; }
|
SerializedTypeID getSType() const { return STI_LEDGERENTRY; }
|
||||||
std::string getFullText() const;
|
std::string getFullText() const;
|
||||||
std::string getText() const;
|
std::string getText() const;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
std::auto_ptr<SerializedType> STObject::makeDefaultObject(SerializedTypeID id, const char *name)
|
std::auto_ptr<SerializedType> STObject::makeDefaultObject(SerializedTypeID id, FieldName* name)
|
||||||
{
|
{
|
||||||
switch(id)
|
switch(id)
|
||||||
{
|
{
|
||||||
@@ -53,8 +53,8 @@ std::auto_ptr<SerializedType> STObject::makeDefaultObject(SerializedTypeID id, c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::auto_ptr<SerializedType> STObject::makeDeserializedObject(SerializedTypeID id, const char *name,
|
std::auto_ptr<SerializedType> STObject::makeDeserializedObject(SerializedTypeID id, FieldName* name,
|
||||||
SerializerIterator& sit)
|
SerializerIterator& sit, int depth)
|
||||||
{
|
{
|
||||||
switch(id)
|
switch(id)
|
||||||
{
|
{
|
||||||
@@ -94,6 +94,12 @@ std::auto_ptr<SerializedType> STObject::makeDeserializedObject(SerializedTypeID
|
|||||||
case STI_PATHSET:
|
case STI_PATHSET:
|
||||||
return STPathSet::deserialize(sit, name);
|
return STPathSet::deserialize(sit, name);
|
||||||
|
|
||||||
|
case STI_ARRAY:
|
||||||
|
return STArray::deserialize(sit, name);
|
||||||
|
|
||||||
|
case STI_OBJECT:
|
||||||
|
return STObject::deserialize(sit, name);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw std::runtime_error("Unknown object type");
|
throw std::runtime_error("Unknown object type");
|
||||||
}
|
}
|
||||||
@@ -103,13 +109,11 @@ void STObject::set(const SOElement* elem)
|
|||||||
{
|
{
|
||||||
mData.empty();
|
mData.empty();
|
||||||
mType.empty();
|
mType.empty();
|
||||||
mFlagIdx = -1;
|
|
||||||
|
|
||||||
while (elem->e_id != STI_DONE)
|
while (elem->flags != SOE_END)
|
||||||
{
|
{
|
||||||
if (elem->e_type == SOE_FLAGS) mFlagIdx = mType.size();
|
|
||||||
mType.push_back(elem);
|
mType.push_back(elem);
|
||||||
if (elem->e_type == SOE_IFFLAG)
|
if (elem->flags == SOE_OPTIONAL)
|
||||||
giveObject(makeDefaultObject(STI_NOTPRESENT, elem->e_name));
|
giveObject(makeDefaultObject(STI_NOTPRESENT, elem->e_name));
|
||||||
else
|
else
|
||||||
giveObject(makeDefaultObject(elem->e_id, elem->e_name));
|
giveObject(makeDefaultObject(elem->e_id, elem->e_name));
|
||||||
@@ -117,55 +121,30 @@ void STObject::set(const SOElement* elem)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STObject::STObject(const SOElement* elem, const char *name) : SerializedType(name)
|
STObject::STObject(const SOElement* elem, FieldName* name) : SerializedType(name)
|
||||||
{
|
{
|
||||||
set(elem);
|
set(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void STObject::set(const SOElement* elem, SerializerIterator& sit)
|
void STObject::set(FieldName* name, SerializerIterator& sit, int depth = 0)
|
||||||
{
|
{
|
||||||
mData.empty();
|
mData.empty();
|
||||||
mType.empty();
|
mType.empty();
|
||||||
mFlagIdx = -1;
|
|
||||||
|
|
||||||
int flags = -1;
|
fName = name;
|
||||||
while (elem->e_id != STI_DONE)
|
|
||||||
|
while(1)
|
||||||
{
|
{
|
||||||
mType.push_back(elem);
|
int type, field.
|
||||||
bool done = false;
|
sit.getFieldID(type, field);
|
||||||
if (elem->e_type == SOE_IFFLAG)
|
if ((type == STI_ARRAY) && (field == 1))
|
||||||
{
|
return;
|
||||||
assert(flags >= 0);
|
FieldName* fn = getFieldName(type, field);
|
||||||
if ((flags&elem->e_flags) == 0)
|
giveObject(makeDeserializedObject(static_cast<SerializedTypeID> type, fn, sit, depth + 1);
|
||||||
{
|
|
||||||
done = true;
|
|
||||||
giveObject(makeDefaultObject(STI_NOTPRESENT, elem->e_name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (elem->e_type == SOE_IFNFLAG)
|
|
||||||
{
|
|
||||||
assert(flags >= 0);
|
|
||||||
if ((flags&elem->e_flags) != 0)
|
|
||||||
{
|
|
||||||
done = true;
|
|
||||||
giveObject(makeDefaultObject(elem->e_id, elem->e_name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (elem->e_type == SOE_FLAGS)
|
|
||||||
{
|
|
||||||
assert(elem->e_id == STI_UINT32);
|
|
||||||
flags = sit.get32();
|
|
||||||
mFlagIdx = giveObject(new STUInt32(elem->e_name, flags));
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
if (!done)
|
|
||||||
giveObject(makeDeserializedObject(elem->e_id, elem->e_name, sit));
|
|
||||||
elem++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STObject::STObject(const SOElement* elem, SerializerIterator& sit, const char *name)
|
STObject::STObject(const SOElement* elem, SerializerIterator& sit, FieldName*name) : SerializedType(name)
|
||||||
: SerializedType(name), mFlagIdx(-1)
|
|
||||||
{
|
{
|
||||||
set(elem, sit);
|
set(elem, sit);
|
||||||
}
|
}
|
||||||
@@ -193,14 +172,6 @@ std::string STObject::getFullText() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int STObject::getLength() const
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
BOOST_FOREACH(const SerializedType& it, mData)
|
|
||||||
ret += it.getLength();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void STObject::add(Serializer& s) const
|
void STObject::add(Serializer& s) const
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const SerializedType& it, mData)
|
BOOST_FOREACH(const SerializedType& it, mData)
|
||||||
@@ -295,9 +266,9 @@ bool STObject::isFieldPresent(SOE_Field field) const
|
|||||||
|
|
||||||
bool STObject::setFlag(uint32 f)
|
bool STObject::setFlag(uint32 f)
|
||||||
{
|
{
|
||||||
if (mFlagIdx < 0) return false;
|
STUInt32* t = dynamic_cast<STUInt32*>(getPField(sfFlags));
|
||||||
STUInt32* t = dynamic_cast<STUInt32*>(getPIndex(mFlagIdx));
|
if (!t)
|
||||||
assert(t);
|
return false;
|
||||||
t->setValue(t->getValue() | f);
|
t->setValue(t->getValue() | f);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -305,17 +276,18 @@ bool STObject::setFlag(uint32 f)
|
|||||||
bool STObject::clearFlag(uint32 f)
|
bool STObject::clearFlag(uint32 f)
|
||||||
{
|
{
|
||||||
if (mFlagIdx < 0) return false;
|
if (mFlagIdx < 0) return false;
|
||||||
STUInt32* t = dynamic_cast<STUInt32*>(getPIndex(mFlagIdx));
|
STUInt32* t = dynamic_cast<STUInt32*>(getPField(sfFlags));
|
||||||
assert(t);
|
if (!t)
|
||||||
|
return false;
|
||||||
t->setValue(t->getValue() & ~f);
|
t->setValue(t->getValue() & ~f);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 STObject::getFlags(void) const
|
uint32 STObject::getFlags(void) const
|
||||||
{
|
{
|
||||||
if (mFlagIdx < 0) return 0;
|
const STUInt32* t = dynamic_cast<const STUInt32*>(peekAtPField(mFlagIdx));
|
||||||
const STUInt32* t = dynamic_cast<const STUInt32*>(peekAtPIndex(mFlagIdx));
|
if (!t)
|
||||||
assert(t);
|
return 0;
|
||||||
return t->getValue();
|
return t->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,56 +9,30 @@
|
|||||||
|
|
||||||
#include "SerializedTypes.h"
|
#include "SerializedTypes.h"
|
||||||
|
|
||||||
enum SOE_Type
|
// Serializable object/array types
|
||||||
{
|
|
||||||
SOE_NEVER = -1, // never occurs (marks end of object)
|
|
||||||
SOE_REQUIRED = 0, // required
|
|
||||||
SOE_FLAGS = 1, // flags field
|
|
||||||
SOE_IFFLAG = 2, // present if flag set
|
|
||||||
SOE_IFNFLAG = 3 // present if flag not set
|
|
||||||
};
|
|
||||||
|
|
||||||
enum SOE_Field
|
|
||||||
{
|
|
||||||
sfInvalid = -1,
|
|
||||||
sfGeneric = 0,
|
|
||||||
|
|
||||||
#define FIELD(name, type, index) sf##name,
|
|
||||||
#define TYPE(name, type, index)
|
|
||||||
#include "SerializeProto.h"
|
|
||||||
#undef FIELD
|
|
||||||
#undef TYPE
|
|
||||||
|
|
||||||
// test fields
|
|
||||||
sfTest1, sfTest2, sfTest3, sfTest4
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SOElement
|
struct SOElement
|
||||||
{ // An element in the description of a serialized object
|
{ // An element in the description of a serialized object
|
||||||
SOE_Field e_field;
|
SOE_Field e_field;
|
||||||
const char *e_name;
|
SOE_Flags flags;
|
||||||
SerializedTypeID e_id;
|
|
||||||
SOE_Type e_type;
|
|
||||||
int e_flags;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class STObject : public SerializedType
|
class STObject : public SerializedType
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
int mFlagIdx; // the offset to the flags object, -1 if none
|
|
||||||
boost::ptr_vector<SerializedType> mData;
|
boost::ptr_vector<SerializedType> mData;
|
||||||
std::vector<const SOElement*> mType;
|
std::vector<const SOElement*> mType;
|
||||||
|
|
||||||
STObject* duplicate() const { return new STObject(*this); }
|
STObject* duplicate() const { return new STObject(*this); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
STObject(const char *n = NULL) : SerializedType(n), mFlagIdx(-1) { ; }
|
STObject(FieldName *n = NULL) : SerializedType(n) { ; }
|
||||||
STObject(const SOElement *t, const char *n = NULL);
|
STObject(const SOElement *t, FieldName *n = NULL);
|
||||||
STObject(const SOElement *t, SerializerIterator& u, const char *n = NULL);
|
STObject(const SOElement *t, SerializerIterator& u, FieldName *n = NULL);
|
||||||
virtual ~STObject() { ; }
|
virtual ~STObject() { ; }
|
||||||
|
|
||||||
void set(const SOElement* t);
|
void set(const SOElement* t);
|
||||||
void set(const SOElement* t, SerializerIterator& u);
|
void set(const SOElement* t, SerializerIterator& u, int depth = 0);
|
||||||
|
|
||||||
int getLength() const;
|
int getLength() const;
|
||||||
virtual SerializedTypeID getSType() const { return STI_OBJECT; }
|
virtual SerializedTypeID getSType() const { return STI_OBJECT; }
|
||||||
@@ -133,13 +107,71 @@ public:
|
|||||||
SerializedType* makeFieldPresent(SOE_Field field);
|
SerializedType* makeFieldPresent(SOE_Field field);
|
||||||
void makeFieldAbsent(SOE_Field field);
|
void makeFieldAbsent(SOE_Field field);
|
||||||
|
|
||||||
static std::auto_ptr<SerializedType> makeDefaultObject(SerializedTypeID id, const char *name);
|
static std::auto_ptr<SerializedType> makeDefaultObject(SerializedTypeID id, FieldName *name);
|
||||||
static std::auto_ptr<SerializedType> makeDeserializedObject(SerializedTypeID id, const char *name,
|
static std::auto_ptr<SerializedType> makeDeserializedObject(SerializedTypeID id, FieldName *name,
|
||||||
SerializerIterator&);
|
SerializerIterator&, int depth);
|
||||||
|
|
||||||
static void unitTest();
|
static void unitTest();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class STArray : public SerializedType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef std::vector<STObject> vector;
|
||||||
|
typedef std::vector<STObject>::iterator iterator;
|
||||||
|
typedef std::vector<STObject>::const_iterator const_iterator;
|
||||||
|
typedef std::vector<STObject>::reverse_iterator reverse_iterator;
|
||||||
|
typedef std::vector<STObject>::const_reverse_iterator const_reverse_iterator;
|
||||||
|
typedef std::vector<STObject>::size_type size_type;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
vector value;
|
||||||
|
|
||||||
|
STArray* duplicate() const { return new STArray(fName, value); }
|
||||||
|
static STArray* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
STArray() { ; }
|
||||||
|
STArray(FieldName* f, const vector& v) : SerializedType(f), value(v) { ; }
|
||||||
|
STArray(vector& v) : value(v) { ; }
|
||||||
|
|
||||||
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
|
const vector& getValue() const { return value; }
|
||||||
|
vector& getValue() { return value; }
|
||||||
|
|
||||||
|
// vector-like functions
|
||||||
|
void push_back(const STObject& object) { value.push_back(object); }
|
||||||
|
STObject& operator[](int j) { return value[j]; }
|
||||||
|
const STObject& operator[](int j) const { return value[j]; }
|
||||||
|
iterator begin() { return value.begin(); }
|
||||||
|
const_iterator begin() const { return value.begin(); }
|
||||||
|
iterator end() { return value.end(); }
|
||||||
|
const_iterator end() const { return value.end(); }
|
||||||
|
size_type size() const { return value.size(); }
|
||||||
|
reverse_iterator rbegin() { return value.rbegin(); }
|
||||||
|
const_reverse_iterator rbegin() const { return value.rbegin(); }
|
||||||
|
reverse_iterator rend() { return value.rend(); }
|
||||||
|
const_reverse_iterator rend() const { return value.rend(); }
|
||||||
|
iterator erase(iterator pos) { return value.erase(pos); }
|
||||||
|
void pop_back() { value.pop_back(); }
|
||||||
|
bool empty() const { return value.empty(); }
|
||||||
|
void clear() { value.clear(); }
|
||||||
|
|
||||||
|
virtual std::string getFullText() const;
|
||||||
|
virtual std::string getText() const;
|
||||||
|
virtual Json::Value getJson(int) const;
|
||||||
|
virtual void add(Serializer& s) const;
|
||||||
|
|
||||||
|
bool operator==(const STArray &s) { return value == s.value; }
|
||||||
|
bool operator!=(const STArray &s) { return value != s.value; }
|
||||||
|
|
||||||
|
virtual SerializedTypeID getSType() const { return STI_ARRAY; }
|
||||||
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// vim:ts=4
|
// vim:ts=4
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ std::string SerializedType::getFullText() const
|
|||||||
std::string ret;
|
std::string ret;
|
||||||
if (getSType() != STI_NOTPRESENT)
|
if (getSType() != STI_NOTPRESENT)
|
||||||
{
|
{
|
||||||
if(name != NULL)
|
if(fName != NULL)
|
||||||
{
|
{
|
||||||
ret = name;
|
ret = fName->fieldName;
|
||||||
ret += " = ";
|
ret += " = ";
|
||||||
}
|
}
|
||||||
ret += getText();
|
ret += getText();
|
||||||
@@ -27,7 +27,7 @@ std::string SerializedType::getFullText() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
STUInt8* STUInt8::construct(SerializerIterator& u, const char *name)
|
STUInt8* STUInt8::construct(SerializerIterator& u, FieldName* name)
|
||||||
{
|
{
|
||||||
return new STUInt8(name, u.get8());
|
return new STUInt8(name, u.get8());
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ bool STUInt8::isEquivalent(const SerializedType& t) const
|
|||||||
return v && (value == v->value);
|
return v && (value == v->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
STUInt16* STUInt16::construct(SerializerIterator& u, const char *name)
|
STUInt16* STUInt16::construct(SerializerIterator& u, FieldName* name)
|
||||||
{
|
{
|
||||||
return new STUInt16(name, u.get16());
|
return new STUInt16(name, u.get16());
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ bool STUInt16::isEquivalent(const SerializedType& t) const
|
|||||||
return v && (value == v->value);
|
return v && (value == v->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
STUInt32* STUInt32::construct(SerializerIterator& u, const char *name)
|
STUInt32* STUInt32::construct(SerializerIterator& u, FieldName* name)
|
||||||
{
|
{
|
||||||
return new STUInt32(name, u.get32());
|
return new STUInt32(name, u.get32());
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ bool STUInt32::isEquivalent(const SerializedType& t) const
|
|||||||
return v && (value == v->value);
|
return v && (value == v->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
STUInt64* STUInt64::construct(SerializerIterator& u, const char *name)
|
STUInt64* STUInt64::construct(SerializerIterator& u, FieldName* name)
|
||||||
{
|
{
|
||||||
return new STUInt64(name, u.get64());
|
return new STUInt64(name, u.get64());
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ bool STUInt64::isEquivalent(const SerializedType& t) const
|
|||||||
return v && (value == v->value);
|
return v && (value == v->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
STHash128* STHash128::construct(SerializerIterator& u, const char *name)
|
STHash128* STHash128::construct(SerializerIterator& u, FieldName* name)
|
||||||
{
|
{
|
||||||
return new STHash128(name, u.get128());
|
return new STHash128(name, u.get128());
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ bool STHash128::isEquivalent(const SerializedType& t) const
|
|||||||
return v && (value == v->value);
|
return v && (value == v->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
STHash160* STHash160::construct(SerializerIterator& u, const char *name)
|
STHash160* STHash160::construct(SerializerIterator& u, FieldName* name)
|
||||||
{
|
{
|
||||||
return new STHash160(name, u.get160());
|
return new STHash160(name, u.get160());
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ bool STHash160::isEquivalent(const SerializedType& t) const
|
|||||||
return v && (value == v->value);
|
return v && (value == v->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
STHash256* STHash256::construct(SerializerIterator& u, const char *name)
|
STHash256* STHash256::construct(SerializerIterator& u, FieldName* name)
|
||||||
{
|
{
|
||||||
return new STHash256(name, u.get256());
|
return new STHash256(name, u.get256());
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ bool STHash256::isEquivalent(const SerializedType& t) const
|
|||||||
return v && (value == v->value);
|
return v && (value == v->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
STVariableLength::STVariableLength(SerializerIterator& st, const char *name) : SerializedType(name)
|
STVariableLength::STVariableLength(SerializerIterator& st, FieldName* name) : SerializedType(name)
|
||||||
{
|
{
|
||||||
value = st.getVL();
|
value = st.getVL();
|
||||||
}
|
}
|
||||||
@@ -149,16 +149,11 @@ std::string STVariableLength::getText() const
|
|||||||
return strHex(value);
|
return strHex(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
STVariableLength* STVariableLength::construct(SerializerIterator& u, const char *name)
|
STVariableLength* STVariableLength::construct(SerializerIterator& u, FieldName* name)
|
||||||
{
|
{
|
||||||
return new STVariableLength(name, u.getVL());
|
return new STVariableLength(name, u.getVL());
|
||||||
}
|
}
|
||||||
|
|
||||||
int STVariableLength::getLength() const
|
|
||||||
{
|
|
||||||
return Serializer::encodeLengthLength(value.size()) + value.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool STVariableLength::isEquivalent(const SerializedType& t) const
|
bool STVariableLength::isEquivalent(const SerializedType& t) const
|
||||||
{
|
{
|
||||||
const STVariableLength* v = dynamic_cast<const STVariableLength*>(&t);
|
const STVariableLength* v = dynamic_cast<const STVariableLength*>(&t);
|
||||||
@@ -176,7 +171,7 @@ std::string STAccount::getText() const
|
|||||||
return a.humanAccountID();
|
return a.humanAccountID();
|
||||||
}
|
}
|
||||||
|
|
||||||
STAccount* STAccount::construct(SerializerIterator& u, const char *name)
|
STAccount* STAccount::construct(SerializerIterator& u, FieldName* name)
|
||||||
{
|
{
|
||||||
return new STAccount(name, u.getVL());
|
return new STAccount(name, u.getVL());
|
||||||
}
|
}
|
||||||
@@ -186,7 +181,7 @@ STAccount* STAccount::construct(SerializerIterator& u, const char *name)
|
|||||||
//
|
//
|
||||||
|
|
||||||
// Return a new object from a SerializerIterator.
|
// Return a new object from a SerializerIterator.
|
||||||
STVector256* STVector256::construct(SerializerIterator& u, const char *name)
|
STVector256* STVector256::construct(SerializerIterator& u, FieldName* name)
|
||||||
{
|
{
|
||||||
std::vector<unsigned char> data = u.getVL();
|
std::vector<unsigned char> data = u.getVL();
|
||||||
std::vector<uint256> value;
|
std::vector<uint256> value;
|
||||||
@@ -255,7 +250,7 @@ void STAccount::setValueNCA(const NewcoinAddress& nca)
|
|||||||
setValueH160(nca.getAccountID());
|
setValueH160(nca.getAccountID());
|
||||||
}
|
}
|
||||||
|
|
||||||
STPathSet* STPathSet::construct(SerializerIterator& s, const char *name)
|
STPathSet* STPathSet::construct(SerializerIterator& s, FieldName* name)
|
||||||
{
|
{
|
||||||
std::vector<STPath> paths;
|
std::vector<STPath> paths;
|
||||||
std::vector<STPathElement> path;
|
std::vector<STPathElement> path;
|
||||||
@@ -342,18 +337,6 @@ int STPath::getSerializeSize() const
|
|||||||
return iBytes;
|
return iBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int STPathSet::getLength() const
|
|
||||||
{
|
|
||||||
int iBytes = 0;
|
|
||||||
|
|
||||||
BOOST_FOREACH(const STPath& spPath, value)
|
|
||||||
{
|
|
||||||
iBytes += spPath.getSerializeSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
return iBytes ? iBytes : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Json::Value STPath::getJson(int) const
|
Json::Value STPath::getJson(int) const
|
||||||
{
|
{
|
||||||
Json::Value ret(Json::arrayValue);
|
Json::Value ret(Json::arrayValue);
|
||||||
|
|||||||
@@ -8,28 +8,13 @@
|
|||||||
|
|
||||||
#include "uint256.h"
|
#include "uint256.h"
|
||||||
#include "Serializer.h"
|
#include "Serializer.h"
|
||||||
|
#include "FieldNames.h"
|
||||||
|
|
||||||
enum SerializedTypeID
|
|
||||||
{
|
|
||||||
// special types
|
|
||||||
STI_DONE = -1,
|
|
||||||
STI_NOTPRESENT = 0,
|
|
||||||
|
|
||||||
#define TYPE(name, field, value) STI_##field = value,
|
|
||||||
#define FIELD(name, field, value)
|
|
||||||
#include "SerializeProto.h"
|
|
||||||
#undef TYPE
|
|
||||||
#undef FIELD
|
|
||||||
|
|
||||||
// high level types
|
|
||||||
STI_TRANSACTION = 100001,
|
|
||||||
STI_LEDGERENTRY = 100002
|
|
||||||
};
|
|
||||||
|
|
||||||
enum PathFlags
|
enum PathFlags
|
||||||
{
|
{
|
||||||
PF_END = 0x00, // End of current path & path list.
|
PF_END = 0x00, // End of current path & path list.
|
||||||
PF_BOUNDRY = 0xFF, // End of current path & new path follows.
|
PF_BOUNDARY = 0xFF, // End of current path & new path follows.
|
||||||
|
|
||||||
PF_ACCOUNT = 0x01,
|
PF_ACCOUNT = 0x01,
|
||||||
PF_OFFER = 0x02,
|
PF_OFFER = 0x02,
|
||||||
@@ -48,24 +33,24 @@ enum PathFlags
|
|||||||
class SerializedType
|
class SerializedType
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
const char* name;
|
FieldName* fName;
|
||||||
|
|
||||||
virtual SerializedType* duplicate() const { return new SerializedType(name); }
|
virtual SerializedType* duplicate() const { return new SerializedType(fName); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SerializedType() : name(NULL) { ; }
|
SerializedType() : fName(NULL) { ; }
|
||||||
SerializedType(const char* n) : name(n) { ; }
|
SerializedType(FieldName* n) : fName(n) { ; }
|
||||||
SerializedType(const SerializedType& n) : name(n.name) { ; }
|
SerializedType(const SerializedType& n) : fName(n.fName) { ; }
|
||||||
virtual ~SerializedType() { ; }
|
virtual ~SerializedType() { ; }
|
||||||
|
|
||||||
static std::auto_ptr<SerializedType> deserialize(const char* name)
|
static std::auto_ptr<SerializedType> deserialize(FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(new SerializedType(name)); }
|
{ return std::auto_ptr<SerializedType>(new SerializedType(name)); }
|
||||||
|
|
||||||
void setName(const char* n) { name=n; }
|
void setFName(FieldName* n) { fName=n; }
|
||||||
const char *getName() const { return name; }
|
FieldName* getFName() { return fName; }
|
||||||
|
const char *getName() const { return (fName != NULL) ? fName->fieldName : NULL; }
|
||||||
|
|
||||||
virtual int getLength() const { return 0; }
|
|
||||||
virtual SerializedTypeID getSType() const { return STI_NOTPRESENT; }
|
virtual SerializedTypeID getSType() const { return STI_NOTPRESENT; }
|
||||||
std::auto_ptr<SerializedType> clone() const { return std::auto_ptr<SerializedType>(duplicate()); }
|
std::auto_ptr<SerializedType> clone() const { return std::auto_ptr<SerializedType>(duplicate()); }
|
||||||
|
|
||||||
@@ -81,7 +66,7 @@ public:
|
|||||||
{ assert(getSType() == STI_NOTPRESENT); return t.getSType() == STI_NOTPRESENT; }
|
{ assert(getSType() == STI_NOTPRESENT); return t.getSType() == STI_NOTPRESENT; }
|
||||||
|
|
||||||
SerializedType& operator=(const SerializedType& t)
|
SerializedType& operator=(const SerializedType& t)
|
||||||
{ name = (name == NULL) ? t.name : name; return *this; }
|
{ if (fName == NULL) fName = t.fName; return *this; }
|
||||||
bool operator==(const SerializedType& t) const
|
bool operator==(const SerializedType& t) const
|
||||||
{ return (getSType() == t.getSType()) && isEquivalent(t); }
|
{ return (getSType() == t.getSType()) && isEquivalent(t); }
|
||||||
bool operator!=(const SerializedType& t) const
|
bool operator!=(const SerializedType& t) const
|
||||||
@@ -97,23 +82,22 @@ class STUInt8 : public SerializedType
|
|||||||
protected:
|
protected:
|
||||||
unsigned char value;
|
unsigned char value;
|
||||||
|
|
||||||
STUInt8* duplicate() const { return new STUInt8(name, value); }
|
STUInt8* duplicate() const { return new STUInt8(fName, value); }
|
||||||
static STUInt8* construct(SerializerIterator&, const char* name = NULL);
|
static STUInt8* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
STUInt8(unsigned char v=0) : value(v) { ; }
|
STUInt8(unsigned char v=0) : value(v) { ; }
|
||||||
STUInt8(const char* n, unsigned char v=0) : SerializedType(n), value(v) { ; }
|
STUInt8(FieldName* n, unsigned char v=0) : SerializedType(n), value(v) { ; }
|
||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
int getLength() const { return 1; }
|
|
||||||
SerializedTypeID getSType() const { return STI_UINT8; }
|
SerializedTypeID getSType() const { return STI_UINT8; }
|
||||||
std::string getText() const;
|
std::string getText() const;
|
||||||
void add(Serializer& s) const { s.add8(value); }
|
void add(Serializer& s) const { s.add8(value); }
|
||||||
|
|
||||||
unsigned char getValue() const { return value; }
|
unsigned char getValue() const { return value; }
|
||||||
void setValue(unsigned char v) { value=v; }
|
void setValue(unsigned char v) { value = v; }
|
||||||
|
|
||||||
operator unsigned char() const { return value; }
|
operator unsigned char() const { return value; }
|
||||||
virtual bool isEquivalent(const SerializedType& t) const;
|
virtual bool isEquivalent(const SerializedType& t) const;
|
||||||
@@ -124,17 +108,16 @@ class STUInt16 : public SerializedType
|
|||||||
protected:
|
protected:
|
||||||
uint16 value;
|
uint16 value;
|
||||||
|
|
||||||
STUInt16* duplicate() const { return new STUInt16(name, value); }
|
STUInt16* duplicate() const { return new STUInt16(fName, value); }
|
||||||
static STUInt16* construct(SerializerIterator&, const char* name = NULL);
|
static STUInt16* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
STUInt16(uint16 v=0) : value(v) { ; }
|
STUInt16(uint16 v=0) : value(v) { ; }
|
||||||
STUInt16(const char* n, uint16 v=0) : SerializedType(n), value(v) { ; }
|
STUInt16(FieldName* n, uint16 v=0) : SerializedType(n), value(v) { ; }
|
||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
int getLength() const { return 2; }
|
|
||||||
SerializedTypeID getSType() const { return STI_UINT16; }
|
SerializedTypeID getSType() const { return STI_UINT16; }
|
||||||
std::string getText() const;
|
std::string getText() const;
|
||||||
void add(Serializer& s) const { s.add16(value); }
|
void add(Serializer& s) const { s.add16(value); }
|
||||||
@@ -151,17 +134,16 @@ class STUInt32 : public SerializedType
|
|||||||
protected:
|
protected:
|
||||||
uint32 value;
|
uint32 value;
|
||||||
|
|
||||||
STUInt32* duplicate() const { return new STUInt32(name, value); }
|
STUInt32* duplicate() const { return new STUInt32(fName, value); }
|
||||||
static STUInt32* construct(SerializerIterator&, const char* name = NULL);
|
static STUInt32* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
STUInt32(uint32 v=0) : value(v) { ; }
|
STUInt32(uint32 v=0) : value(v) { ; }
|
||||||
STUInt32(const char* n, uint32 v=0) : SerializedType(n), value(v) { ; }
|
STUInt32(FieldName* n, uint32 v=0) : SerializedType(n), value(v) { ; }
|
||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
int getLength() const { return 4; }
|
|
||||||
SerializedTypeID getSType() const { return STI_UINT32; }
|
SerializedTypeID getSType() const { return STI_UINT32; }
|
||||||
std::string getText() const;
|
std::string getText() const;
|
||||||
void add(Serializer& s) const { s.add32(value); }
|
void add(Serializer& s) const { s.add32(value); }
|
||||||
@@ -178,17 +160,16 @@ class STUInt64 : public SerializedType
|
|||||||
protected:
|
protected:
|
||||||
uint64 value;
|
uint64 value;
|
||||||
|
|
||||||
STUInt64* duplicate() const { return new STUInt64(name, value); }
|
STUInt64* duplicate() const { return new STUInt64(fName, value); }
|
||||||
static STUInt64* construct(SerializerIterator&, const char* name = NULL);
|
static STUInt64* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
STUInt64(uint64 v=0) : value(v) { ; }
|
STUInt64(uint64 v=0) : value(v) { ; }
|
||||||
STUInt64(const char* n, uint64 v=0) : SerializedType(n), value(v) { ; }
|
STUInt64(FieldName* n, uint64 v=0) : SerializedType(n), value(v) { ; }
|
||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
int getLength() const { return 8; }
|
|
||||||
SerializedTypeID getSType() const { return STI_UINT64; }
|
SerializedTypeID getSType() const { return STI_UINT64; }
|
||||||
std::string getText() const;
|
std::string getText() const;
|
||||||
void add(Serializer& s) const { s.add64(value); }
|
void add(Serializer& s) const { s.add64(value); }
|
||||||
@@ -224,7 +205,7 @@ protected:
|
|||||||
|
|
||||||
void canonicalize();
|
void canonicalize();
|
||||||
STAmount* duplicate() const { return new STAmount(*this); }
|
STAmount* duplicate() const { return new STAmount(*this); }
|
||||||
static STAmount* construct(SerializerIterator&, const char* name = NULL);
|
static STAmount* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
static const int cMinOffset = -96, cMaxOffset = 80;
|
static const int cMinOffset = -96, cMaxOffset = 80;
|
||||||
static const uint64 cMinValue = 1000000000000000ull, cMaxValue = 9999999999999999ull;
|
static const uint64 cMinValue = 1000000000000000ull, cMaxValue = 9999999999999999ull;
|
||||||
@@ -234,10 +215,10 @@ protected:
|
|||||||
|
|
||||||
STAmount(bool isNeg, uint64 value) : mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNeg) { ; }
|
STAmount(bool isNeg, uint64 value) : mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNeg) { ; }
|
||||||
|
|
||||||
STAmount(const char *name, uint64 value, bool isNegative)
|
STAmount(FieldName *name, uint64 value, bool isNegative)
|
||||||
: SerializedType(name), mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNegative)
|
: SerializedType(fName), mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNegative)
|
||||||
{ ; }
|
{ ; }
|
||||||
STAmount(const char *n, const uint160& cur, const uint160& iss, uint64 val, int off, bool isNat, bool isNeg)
|
STAmount(FieldName *n, const uint160& cur, const uint160& iss, uint64 val, int off, bool isNat, bool isNeg)
|
||||||
: SerializedType(n), mCurrency(cur), mIssuer(iss), mValue(val), mOffset(off),
|
: SerializedType(n), mCurrency(cur), mIssuer(iss), mValue(val), mOffset(off),
|
||||||
mIsNative(isNat), mIsNegative(isNeg) { ; }
|
mIsNative(isNat), mIsNegative(isNeg) { ; }
|
||||||
|
|
||||||
@@ -250,7 +231,7 @@ public:
|
|||||||
STAmount(uint64 v = 0, bool isNeg = false) : mValue(v), mOffset(0), mIsNative(true), mIsNegative(isNeg)
|
STAmount(uint64 v = 0, bool isNeg = false) : mValue(v), mOffset(0), mIsNative(true), mIsNegative(isNeg)
|
||||||
{ if (v==0) mIsNegative = false; }
|
{ if (v==0) mIsNegative = false; }
|
||||||
|
|
||||||
STAmount(const char* n, uint64 v = 0)
|
STAmount(FieldName* n, uint64 v = 0)
|
||||||
: SerializedType(n), mValue(v), mOffset(0), mIsNative(true), mIsNegative(false)
|
: SerializedType(n), mValue(v), mOffset(0), mIsNative(true), mIsNegative(false)
|
||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
@@ -259,14 +240,14 @@ public:
|
|||||||
{ canonicalize(); }
|
{ canonicalize(); }
|
||||||
|
|
||||||
// YYY This should probably require issuer too.
|
// YYY This should probably require issuer too.
|
||||||
STAmount(const char* n, const uint160& currency, const uint160& issuer,
|
STAmount(FieldName* n, const uint160& currency, const uint160& issuer,
|
||||||
uint64 v = 0, int off = 0, bool isNeg = false) :
|
uint64 v = 0, int off = 0, bool isNeg = false) :
|
||||||
SerializedType(n), mCurrency(currency), mIssuer(issuer), mValue(v), mOffset(off), mIsNegative(isNeg)
|
SerializedType(n), mCurrency(currency), mIssuer(issuer), mValue(v), mOffset(off), mIsNegative(isNeg)
|
||||||
{ canonicalize(); }
|
{ canonicalize(); }
|
||||||
|
|
||||||
STAmount(const char* n, int64 v);
|
STAmount(FieldName* n, int64 v);
|
||||||
|
|
||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
static STAmount saFromRate(uint64 uRate = 0)
|
static STAmount saFromRate(uint64 uRate = 0)
|
||||||
@@ -279,7 +260,6 @@ public:
|
|||||||
return STAmount(uCurrencyID, uIssuerID, iV < 0 ? -iV : iV, iOff, iV < 0);
|
return STAmount(uCurrencyID, uIssuerID, iV < 0 ? -iV : iV, iOff, iV < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getLength() const { return mIsNative ? 8 : 28; }
|
|
||||||
SerializedTypeID getSType() const { return STI_AMOUNT; }
|
SerializedTypeID getSType() const { return STI_AMOUNT; }
|
||||||
std::string getText() const;
|
std::string getText() const;
|
||||||
std::string getRaw() const;
|
std::string getRaw() const;
|
||||||
@@ -377,7 +357,7 @@ public:
|
|||||||
// Native currency conversions, to/from display format
|
// Native currency conversions, to/from display format
|
||||||
static uint64 convertToDisplayAmount(const STAmount& internalAmount, uint64 totalNow, uint64 totalInit);
|
static uint64 convertToDisplayAmount(const STAmount& internalAmount, uint64 totalNow, uint64 totalInit);
|
||||||
static STAmount convertToInternalAmount(uint64 displayAmount, uint64 totalNow, uint64 totalInit,
|
static STAmount convertToInternalAmount(uint64 displayAmount, uint64 totalNow, uint64 totalInit,
|
||||||
const char* name = NULL);
|
FieldName* name = NULL);
|
||||||
|
|
||||||
static std::string createHumanCurrency(const uint160& uCurrency);
|
static std::string createHumanCurrency(const uint160& uCurrency);
|
||||||
static STAmount deserialize(SerializerIterator&);
|
static STAmount deserialize(SerializerIterator&);
|
||||||
@@ -394,19 +374,18 @@ class STHash128 : public SerializedType
|
|||||||
protected:
|
protected:
|
||||||
uint128 value;
|
uint128 value;
|
||||||
|
|
||||||
STHash128* duplicate() const { return new STHash128(name, value); }
|
STHash128* duplicate() const { return new STHash128(fName, value); }
|
||||||
static STHash128* construct(SerializerIterator&, const char* name = NULL);
|
static STHash128* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
STHash128(const uint128& v) : value(v) { ; }
|
STHash128(const uint128& v) : value(v) { ; }
|
||||||
STHash128(const char* n, const uint128& v) : SerializedType(n), value(v) { ; }
|
STHash128(FieldName* n, const uint128& v) : SerializedType(n), value(v) { ; }
|
||||||
STHash128(const char* n) : SerializedType(n) { ; }
|
STHash128(FieldName* n) : SerializedType(n) { ; }
|
||||||
STHash128() { ; }
|
STHash128() { ; }
|
||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
int getLength() const { return 20; }
|
|
||||||
SerializedTypeID getSType() const { return STI_HASH128; }
|
SerializedTypeID getSType() const { return STI_HASH128; }
|
||||||
virtual std::string getText() const;
|
virtual std::string getText() const;
|
||||||
void add(Serializer& s) const { s.add128(value); }
|
void add(Serializer& s) const { s.add128(value); }
|
||||||
@@ -423,19 +402,18 @@ class STHash160 : public SerializedType
|
|||||||
protected:
|
protected:
|
||||||
uint160 value;
|
uint160 value;
|
||||||
|
|
||||||
STHash160* duplicate() const { return new STHash160(name, value); }
|
STHash160* duplicate() const { return new STHash160(fName, value); }
|
||||||
static STHash160* construct(SerializerIterator&, const char* name = NULL);
|
static STHash160* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
STHash160(const uint160& v) : value(v) { ; }
|
STHash160(const uint160& v) : value(v) { ; }
|
||||||
STHash160(const char* n, const uint160& v) : SerializedType(n), value(v) { ; }
|
STHash160(FieldName* n, const uint160& v) : SerializedType(n), value(v) { ; }
|
||||||
STHash160(const char* n) : SerializedType(n) { ; }
|
STHash160(FieldName* n) : SerializedType(n) { ; }
|
||||||
STHash160() { ; }
|
STHash160() { ; }
|
||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
int getLength() const { return 20; }
|
|
||||||
SerializedTypeID getSType() const { return STI_HASH160; }
|
SerializedTypeID getSType() const { return STI_HASH160; }
|
||||||
virtual std::string getText() const;
|
virtual std::string getText() const;
|
||||||
void add(Serializer& s) const { s.add160(value); }
|
void add(Serializer& s) const { s.add160(value); }
|
||||||
@@ -452,19 +430,18 @@ class STHash256 : public SerializedType
|
|||||||
protected:
|
protected:
|
||||||
uint256 value;
|
uint256 value;
|
||||||
|
|
||||||
STHash256* duplicate() const { return new STHash256(name, value); }
|
STHash256* duplicate() const { return new STHash256(fName, value); }
|
||||||
static STHash256* construct(SerializerIterator&, const char* name = NULL);
|
static STHash256* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
STHash256(const uint256& v) : value(v) { ; }
|
STHash256(const uint256& v) : value(v) { ; }
|
||||||
STHash256(const char* n, const uint256& v) : SerializedType(n), value(v) { ; }
|
STHash256(FieldName* n, const uint256& v) : SerializedType(n), value(v) { ; }
|
||||||
STHash256(const char* n) : SerializedType(n) { ; }
|
STHash256(FieldName* n) : SerializedType(n) { ; }
|
||||||
STHash256() { ; }
|
STHash256() { ; }
|
||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
int getLength() const { return 32; }
|
|
||||||
SerializedTypeID getSType() const { return STI_HASH256; }
|
SerializedTypeID getSType() const { return STI_HASH256; }
|
||||||
std::string getText() const;
|
std::string getText() const;
|
||||||
void add(Serializer& s) const { s.add256(value); }
|
void add(Serializer& s) const { s.add256(value); }
|
||||||
@@ -481,20 +458,19 @@ class STVariableLength : public SerializedType
|
|||||||
protected:
|
protected:
|
||||||
std::vector<unsigned char> value;
|
std::vector<unsigned char> value;
|
||||||
|
|
||||||
virtual STVariableLength* duplicate() const { return new STVariableLength(name, value); }
|
virtual STVariableLength* duplicate() const { return new STVariableLength(fName, value); }
|
||||||
static STVariableLength* construct(SerializerIterator&, const char* name = NULL);
|
static STVariableLength* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
STVariableLength(const std::vector<unsigned char>& v) : value(v) { ; }
|
STVariableLength(const std::vector<unsigned char>& v) : value(v) { ; }
|
||||||
STVariableLength(const char* n, const std::vector<unsigned char>& v) : SerializedType(n), value(v) { ; }
|
STVariableLength(FieldName* n, const std::vector<unsigned char>& v) : SerializedType(n), value(v) { ; }
|
||||||
STVariableLength(const char* n) : SerializedType(n) { ; }
|
STVariableLength(FieldName* n) : SerializedType(n) { ; }
|
||||||
STVariableLength(SerializerIterator&, const char* name = NULL);
|
STVariableLength(SerializerIterator&, FieldName* name = NULL);
|
||||||
STVariableLength() { ; }
|
STVariableLength() { ; }
|
||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
int getLength() const;
|
|
||||||
virtual SerializedTypeID getSType() const { return STI_VL; }
|
virtual SerializedTypeID getSType() const { return STI_VL; }
|
||||||
virtual std::string getText() const;
|
virtual std::string getText() const;
|
||||||
void add(Serializer& s) const { s.addVL(value); }
|
void add(Serializer& s) const { s.addVL(value); }
|
||||||
@@ -511,16 +487,16 @@ public:
|
|||||||
class STAccount : public STVariableLength
|
class STAccount : public STVariableLength
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
virtual STAccount* duplicate() const { return new STAccount(name, value); }
|
virtual STAccount* duplicate() const { return new STAccount(fName, value); }
|
||||||
static STAccount* construct(SerializerIterator&, const char* name = NULL);
|
static STAccount* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
STAccount(const std::vector<unsigned char>& v) : STVariableLength(v) { ; }
|
STAccount(const std::vector<unsigned char>& v) : STVariableLength(v) { ; }
|
||||||
STAccount(const char* n, const std::vector<unsigned char>& v) : STVariableLength(n, v) { ; }
|
STAccount(FieldName* n, const std::vector<unsigned char>& v) : STVariableLength(n, v) { ; }
|
||||||
STAccount(const char* n) : STVariableLength(n) { ; }
|
STAccount(FieldName* n) : STVariableLength(n) { ; }
|
||||||
STAccount() { ; }
|
STAccount() { ; }
|
||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
SerializedTypeID getSType() const { return STI_ACCOUNT; }
|
SerializedTypeID getSType() const { return STI_ACCOUNT; }
|
||||||
@@ -649,19 +625,18 @@ class STPathSet : public SerializedType
|
|||||||
protected:
|
protected:
|
||||||
std::vector<STPath> value;
|
std::vector<STPath> value;
|
||||||
|
|
||||||
STPathSet* duplicate() const { return new STPathSet(name, value); }
|
STPathSet* duplicate() const { return new STPathSet(fName, value); }
|
||||||
static STPathSet* construct(SerializerIterator&, const char* name = NULL);
|
static STPathSet* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
STPathSet() { ; }
|
STPathSet() { ; }
|
||||||
STPathSet(const char* n) : SerializedType(n) { ; }
|
STPathSet(FieldName* n) : SerializedType(n) { ; }
|
||||||
STPathSet(const std::vector<STPath>& v) : value(v) { ; }
|
STPathSet(const std::vector<STPath>& v) : value(v) { ; }
|
||||||
STPathSet(const char* n, const std::vector<STPath>& v) : SerializedType(n), value(v) { ; }
|
STPathSet(FieldName* n, const std::vector<STPath>& v) : SerializedType(n), value(v) { ; }
|
||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
int getLength() const;
|
|
||||||
// std::string getText() const;
|
// std::string getText() const;
|
||||||
void add(Serializer& s) const;
|
void add(Serializer& s) const;
|
||||||
virtual Json::Value getJson(int) const;
|
virtual Json::Value getJson(int) const;
|
||||||
@@ -722,20 +697,19 @@ class STVector256 : public SerializedType
|
|||||||
protected:
|
protected:
|
||||||
std::vector<uint256> mValue;
|
std::vector<uint256> mValue;
|
||||||
|
|
||||||
STVector256* duplicate() const { return new STVector256(name, mValue); }
|
STVector256* duplicate() const { return new STVector256(fName, mValue); }
|
||||||
static STVector256* construct(SerializerIterator&, const char* name = NULL);
|
static STVector256* construct(SerializerIterator&, FieldName* name = NULL);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
STVector256() { ; }
|
STVector256() { ; }
|
||||||
STVector256(const char* n) : SerializedType(n) { ; }
|
STVector256(FieldName* n) : SerializedType(n) { ; }
|
||||||
STVector256(const char* n, const std::vector<uint256>& v) : SerializedType(n), mValue(v) { ; }
|
STVector256(FieldName* n, const std::vector<uint256>& v) : SerializedType(n), mValue(v) { ; }
|
||||||
STVector256(const std::vector<uint256>& vector) : mValue(vector) { ; }
|
STVector256(const std::vector<uint256>& vector) : mValue(vector) { ; }
|
||||||
|
|
||||||
SerializedTypeID getSType() const { return STI_VECTOR256; }
|
SerializedTypeID getSType() const { return STI_VECTOR256; }
|
||||||
int getLength() const { return Serializer::lengthVL(mValue.size() * (256 / 8)); }
|
|
||||||
void add(Serializer& s) const;
|
void add(Serializer& s) const;
|
||||||
|
|
||||||
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, const char* name)
|
static std::auto_ptr<SerializedType> deserialize(SerializerIterator& sit, FieldName* name)
|
||||||
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
{ return std::auto_ptr<SerializedType>(construct(sit, name)); }
|
||||||
|
|
||||||
const std::vector<uint256>& peekValue() const { return mValue; }
|
const std::vector<uint256>& peekValue() const { return mValue; }
|
||||||
|
|||||||
@@ -1,122 +1,120 @@
|
|||||||
|
|
||||||
#include "TransactionFormats.h"
|
#include "TransactionFormats.h"
|
||||||
|
|
||||||
#define S_FIELD(x) sf##x, #x
|
|
||||||
|
|
||||||
TransactionFormat InnerTxnFormats[]=
|
TransactionFormat InnerTxnFormats[]=
|
||||||
{
|
{
|
||||||
{ "AccountSet", ttACCOUNT_SET, {
|
{ "AccountSet", ttACCOUNT_SET, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
{ sfSourceTag, SOE_OPTIONAL },
|
||||||
{ S_FIELD(EmailHash), STI_HASH128, SOE_IFFLAG, 2 },
|
{ sfEmailHash, SOE_OPTIONAL },
|
||||||
{ S_FIELD(WalletLocator), STI_HASH256, SOE_IFFLAG, 4 },
|
{ sfWalletLocator, SOE_OPTIONAL },
|
||||||
{ S_FIELD(MessageKey), STI_VL, SOE_IFFLAG, 8 },
|
{ sfMessageKey, SOE_OPTIONAL },
|
||||||
{ S_FIELD(Domain), STI_VL, SOE_IFFLAG, 16 },
|
{ sfDomain, SOE_OPTIONAL },
|
||||||
{ S_FIELD(TransferRate), STI_UINT32, SOE_IFFLAG, 32 },
|
{ sfTransferRate, SOE_OPTIONAL },
|
||||||
{ S_FIELD(PublishHash), STI_HASH256, SOE_IFFLAG, 64 },
|
{ sfPublishHash, SOE_OPTIONAL },
|
||||||
{ S_FIELD(PublishSize), STI_UINT32, SOE_IFFLAG, 128 },
|
{ sfPublishSize, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "Claim", ttCLAIM, {
|
{ "Claim", ttCLAIM, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Generator), STI_VL, SOE_REQUIRED, 0 },
|
{ sfGenerator, SOE_REQUIRED },
|
||||||
{ S_FIELD(PublicKey), STI_VL, SOE_REQUIRED, 0 },
|
{ sfPublicKey, SOE_REQUIRED },
|
||||||
{ S_FIELD(Signature), STI_VL, SOE_REQUIRED, 0 },
|
{ sfSignature, SOE_REQUIRED },
|
||||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
{ sfSourceTag, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "CreditSet", ttCREDIT_SET, {
|
{ "CreditSet", ttCREDIT_SET, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Destination), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfDestination, SOE_REQUIRED },
|
||||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
{ sfSourceTag, SOE_OPTIONAL },
|
||||||
{ S_FIELD(LimitAmount), STI_AMOUNT, SOE_IFFLAG, 2 },
|
{ sfLimitAmount, SOE_OPTIONAL },
|
||||||
{ S_FIELD(QualityIn), STI_UINT32, SOE_IFFLAG, 4 },
|
{ sfQualityIn, SOE_OPTIONAL },
|
||||||
{ S_FIELD(QualityOut), STI_UINT32, SOE_IFFLAG, 8 },
|
{ sfQualityOut, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
/*
|
/*
|
||||||
{ "Invoice", ttINVOICE, {
|
{ "Invoice", ttINVOICE, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Target), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfTarget, SOE_REQUIRED },
|
||||||
{ S_FIELD(Amount), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfAmount, SOE_REQUIRED },
|
||||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
{ sfSourceTag, SOE_OPTIONAL },
|
||||||
{ S_FIELD(Destination), STI_ACCOUNT, SOE_IFFLAG, 2 },
|
{ sfDestination, SOE_OPTIONAL },
|
||||||
{ S_FIELD(Identifier), STI_VL, SOE_IFFLAG, 4 },
|
{ sfIdentifier, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
*/
|
*/
|
||||||
{ "NicknameSet", ttNICKNAME_SET, {
|
{ "NicknameSet", ttNICKNAME_SET, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Nickname), STI_HASH256, SOE_REQUIRED, 0 },
|
{ sfNickname, SOE_REQUIRED },
|
||||||
{ S_FIELD(MinimumOffer), STI_AMOUNT, SOE_IFFLAG, 1 },
|
{ sfMinimumOffer, SOE_OPTIONAL },
|
||||||
{ S_FIELD(Signature), STI_VL, SOE_IFFLAG, 2 },
|
{ sfSignature, SOE_OPTIONAL },
|
||||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 4 },
|
{ sfSourceTag, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "OfferCreate", ttOFFER_CREATE, {
|
{ "OfferCreate", ttOFFER_CREATE, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED},
|
||||||
{ S_FIELD(TakerPays), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfTakerPays, SOE_REQUIRED },
|
||||||
{ S_FIELD(TakerGets), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfTakerGets, SOE_REQUIRED },
|
||||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
{ sfSourceTag, SOE_OPTIONAL },
|
||||||
{ S_FIELD(Expiration), STI_UINT32, SOE_IFFLAG, 2 },
|
{ sfExpiration, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "OfferCancel", ttOFFER_CANCEL, {
|
{ "OfferCancel", ttOFFER_CANCEL, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(OfferSequence), STI_UINT32, SOE_REQUIRED, 0 },
|
{ sfOfferSequence, SOE_REQUIRED },
|
||||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
{ sfSourceTag, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "PasswordFund", ttPASSWORD_FUND, {
|
{ "PasswordFund", ttPASSWORD_FUND, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Destination), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfDestination, SOE_REQUIRED },
|
||||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
{ sfSourceTag, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "PasswordSet", ttPASSWORD_SET, {
|
{ "PasswordSet", ttPASSWORD_SET, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(AuthorizedKey), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfAuthorizedKey, SOE_REQUIRED },
|
||||||
{ S_FIELD(Generator), STI_VL, SOE_REQUIRED, 0 },
|
{ sfGenerator, SOE_REQUIRED },
|
||||||
{ S_FIELD(PublicKey), STI_VL, SOE_REQUIRED, 0 },
|
{ sfPublicKey, SOE_REQUIRED },
|
||||||
{ S_FIELD(Signature), STI_VL, SOE_REQUIRED, 0 },
|
{ sfSignature, SOE_REQUIRED },
|
||||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
{ sfSourceTag, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "Payment", ttPAYMENT, {
|
{ "Payment", ttPAYMENT, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Destination), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfDestination, SOE_REQUIRED },
|
||||||
{ S_FIELD(Amount), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfAmount, SOE_REQUIRED },
|
||||||
{ S_FIELD(SendMax), STI_AMOUNT, SOE_IFFLAG, 1 },
|
{ sfSendMax, SOE_OPTIONAL },
|
||||||
{ S_FIELD(Paths), STI_PATHSET, SOE_IFFLAG, 2 },
|
{ sfPaths, SOE_OPTIONAL },
|
||||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 4 },
|
{ sfSourceTag, SOE_OPTIONAL },
|
||||||
{ S_FIELD(InvoiceID), STI_HASH256, SOE_IFFLAG, 8 },
|
{ sfInvoiceID, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "WalletAdd", ttWALLET_ADD, {
|
{ "WalletAdd", ttWALLET_ADD, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Amount), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfAmount, SOE_REQUIRED },
|
||||||
{ S_FIELD(AuthorizedKey), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfAuthorizedKey, SOE_REQUIRED },
|
||||||
{ S_FIELD(PublicKey), STI_VL, SOE_REQUIRED, 0 },
|
{ sfPublicKey, SOE_REQUIRED },
|
||||||
{ S_FIELD(Signature), STI_VL, SOE_REQUIRED, 0 },
|
{ sfSignature, SOE_REQUIRED },
|
||||||
{ S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 },
|
{ sfSourceTag, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "Contract", ttCONTRACT, {
|
{ "Contract", ttCONTRACT, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Expiration), STI_UINT32, SOE_REQUIRED, 0 },
|
{ sfExpiration, SOE_REQUIRED },
|
||||||
{ S_FIELD(BondAmount), STI_UINT32, SOE_REQUIRED, 0 },
|
{ sfBondAmount, SOE_REQUIRED },
|
||||||
{ S_FIELD(StampEscrow), STI_UINT32, SOE_REQUIRED, 0 },
|
{ sfStampEscrow, SOE_REQUIRED },
|
||||||
{ S_FIELD(RippleEscrow), STI_AMOUNT, SOE_REQUIRED, 0 },
|
{ sfRippleEscrow, SOE_REQUIRED },
|
||||||
{ S_FIELD(CreateCode), STI_VL, SOE_REQUIRED, 0 },
|
{ sfCreateCode, SOE_OPTIONAL },
|
||||||
{ S_FIELD(FundCode), STI_VL, SOE_REQUIRED, 0 },
|
{ sfFundCode, SOE_OPTIONAL },
|
||||||
{ S_FIELD(RemoveCode), STI_VL, SOE_REQUIRED, 0 },
|
{ sfRemoveCode, SOE_OPTIONAL },
|
||||||
{ S_FIELD(ExpireCode), STI_VL, SOE_REQUIRED, 0 },
|
{ sfExpireCode, SOE_OPTIONAL },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ "Contract", ttCONTRACT_REMOVE, {
|
{ "RemoveContract", ttCONTRACT_REMOVE, {
|
||||||
{ S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 },
|
{ sfFlags, SOE_REQUIRED },
|
||||||
{ S_FIELD(Target), STI_ACCOUNT, SOE_REQUIRED, 0 },
|
{ sfTarget, SOE_REQUIRED },
|
||||||
{ sfInvalid, NULL, STI_DONE, SOE_NEVER, -1 } }
|
{ sfInvalid, SOE_END } }
|
||||||
},
|
},
|
||||||
{ NULL, ttINVALID }
|
{ NULL, ttINVALID }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ enum TransactionType
|
|||||||
|
|
||||||
struct TransactionFormat
|
struct TransactionFormat
|
||||||
{
|
{
|
||||||
const char *t_name;
|
const char * t_name;
|
||||||
TransactionType t_type;
|
TransactionType t_type;
|
||||||
SOElement elements[16];
|
SOElement elements[24];
|
||||||
};
|
};
|
||||||
|
|
||||||
const int TransactionISigningPubKey = 0;
|
const int TransactionISigningPubKey = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user