From 2446db0bbe362c2e1f1575fbb024b5e858d66635 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 25 Sep 2012 19:27:09 -0700 Subject: [PATCH] More serialization work. --- src/Amount.cpp | 7 +- src/FieldNames.cpp | 50 ++++--------- src/FieldNames.h | 57 +++++++++----- src/LedgerEntrySet.h | 3 +- src/SerializedLedger.h | 66 ++++++++--------- src/SerializedObject.cpp | 16 ++-- src/SerializedObject.h | 100 +++++++++++++------------ src/SerializedTransaction.h | 64 ++++++++-------- src/SerializedTypes.cpp | 24 +++--- src/SerializedTypes.h | 143 ++++++++++++++++++------------------ src/TransactionMeta.cpp | 2 +- 11 files changed, 266 insertions(+), 266 deletions(-) diff --git a/src/Amount.cpp b/src/Amount.cpp index 56b0104a3..c9e3e4475 100644 --- a/src/Amount.cpp +++ b/src/Amount.cpp @@ -298,7 +298,7 @@ void STAmount::add(Serializer& s) const } } -STAmount::STAmount(FieldName* name, int64 value) : SerializedType(name), mOffset(0), mIsNative(true) +STAmount::STAmount(SField::ref name, int64 value) : SerializedType(name), mOffset(0), mIsNative(true) { if (value >= 0) { @@ -330,7 +330,7 @@ uint64 STAmount::toUInt64() const return mValue | (static_cast(mOffset + 256 + 97) << (64 - 10)); } -STAmount* STAmount::construct(SerializerIterator& sit, FieldName* name) +STAmount* STAmount::construct(SerializerIterator& sit, SField::ref name) { uint64 value = sit.get64(); @@ -882,8 +882,7 @@ uint64 STAmount::convertToDisplayAmount(const STAmount& internalAmount, uint64 t return muldiv(internalAmount.getNValue(), totalInit, totalNow); } -STAmount STAmount::convertToInternalAmount(uint64 displayAmount, uint64 totalNow, uint64 totalInit, - FieldName* name) +STAmount STAmount::convertToInternalAmount(uint64 displayAmount, uint64 totalNow, uint64 totalInit, SField::ref name) { // Convert a display/request currency amount to an internal amount return STAmount(name, muldiv(displayAmount, totalNow, totalInit)); } diff --git a/src/FieldNames.cpp b/src/FieldNames.cpp index 72589d000..c8388ad02 100644 --- a/src/FieldNames.cpp +++ b/src/FieldNames.cpp @@ -5,49 +5,27 @@ #include -#define FIELD(name, type, index) { sf##name, #name, STI_##type, index }, + +SField sfInvalid(-1), sfGeneric(0); + +#define FIELD(name, type, index) SField sf##name(FIELD_CODE(STI_##type, index), STI_##type, index, naem); #define TYPE(name, type, index) - -FieldName FieldNames[]= -{ #include "SerializeProto.h" - - { sfInvalid, 0, STI_DONE, 0 } -}; - #undef FIELD #undef TYPE -static std::map unknownFieldMap; -static boost::mutex unknownFieldMutex; +static std::map SField::codeToField; +static boost::mutex SField::mapMutex; -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; +SField::ref SField::getField(int code); +{ if ((type <= 0) || (type >= 256) || (field <= 0) || (field >= 256 - return NULL; + return sfInvalid; + boost::mutex::scoped_lock sl(mapMutex); - boost::mutex::scoped_lock sl(unknownFieldMutex); - std::map it = unknownFieldMap.Find(f); - if (it != unknownFieldMap.end()) - return it->second; + std::map it = unknownFieldMap.Find(code); + if (it != codeToField.end()) + return *(it->second); - FieldName* n = new FieldName(); - n->field = f; - n->fieldName = "unknown"; - n->fieldType = static_cast(type); - n->fieldNum = field; - unknownFieldMap[f] = n; - return n; + return *(new SField(code, static_cast(code>>16), code&0xffff, NULL)); } diff --git a/src/FieldNames.h b/src/FieldNames.h index b056b237f..db29e0ebd 100644 --- a/src/FieldNames.h +++ b/src/FieldNames.h @@ -1,9 +1,14 @@ #ifndef __FIELDNAMES__ #define __FIELDNAMES__ +#include + +#define FIELD_CODE(type, index) ((static_cast(type) << 16) | index) + enum SerializedTypeID { // special types + STI_UNKNOWN = -2, STI_DONE = -1, STI_NOTPRESENT = 0, @@ -26,31 +31,43 @@ enum SOE_Flags SOE_OPTIONAL = 1, // optional }; -enum SOE_Field +class SField { - sfInvalid = -1, - sfGeneric = 0, +public: + typedef const SField& ref; + typedef SField const * ptr; -#define FIELD(name, type, index) sf##name = (STI_##type << 16) | index, +protected: + static std::map codeToField; + static boost::mutex mapMutex; + +public: + + const int fieldCode; // (type<<16)|index + const SerializedTypeID fieldType; // STI_* + const int fieldValue; // Code number for protocol + const char* fieldName; + + SField(int fc, SerializedTypeID tid, int fv, const char* fn) : + fieldCode(fc), fieldType(tid), fieldValue(fv), fieldName(fn) + { codeToField[fc] = this; } + + SField(int fc) : fieldCode(fc), fieldType(STI_UNKNOWN), fieldValue(0), fieldName(NULL) { ; } + + static SField::ref getField(int fieldCode); + static SField::ref getField(SerializedTypeID type, int value) { return getField(FIELD_CODE(type, value)); } + + bool isGeneric() const { return fieldCode == 0; } + bool isInvalid() const { return fieldCode == -1; } + bool isKnown() const { return fieldType != STI_UNKNOWN; } +}; + +extern SField sfInvalid, sfGeneric; + +#define FIELD(name, type, index) extern SField sf##name; #define TYPE(name, type, index) #include "SerializeProto.h" #undef FIELD #undef TYPE - // test fields - sfTest1=100000, sfTest2, sfTest3, sfTest4 -}; - -struct FieldName -{ - SOE_Field field; - const char *fieldName; - SerializedTypeID fieldType; - int fieldNum; -}; - -extern FieldName FieldNames[]; -extern FieldName* getFieldName(SOE_Field); -extern FieldName* getFieldName(int type, int field); - #endif diff --git a/src/LedgerEntrySet.h b/src/LedgerEntrySet.h index 150a5ae89..8a7c926c4 100644 --- a/src/LedgerEntrySet.h +++ b/src/LedgerEntrySet.h @@ -104,7 +104,8 @@ public: uint32 rippleTransferRate(const uint160& uIssuerID); STAmount rippleOwed(const uint160& uToAccountID, const uint160& uFromAccountID, const uint160& uCurrencyID); STAmount rippleLimit(const uint160& uToAccountID, const uint160& uFromAccountID, const uint160& uCurrencyID); - uint32 rippleQualityIn(const uint160& uToAccountID, const uint160& uFromAccountID, const uint160& uCurrencyID, const SOE_Field sfLow=sfLowQualityIn, const SOE_Field sfHigh=sfHighQualityIn); + uint32 rippleQualityIn(const uint160& uToAccountID, const uint160& uFromAccountID, const uint160& uCurrencyID, + SField::ref sfLow = sfLowQualityIn, SField::ref sfHigh = sfHighQualityIn); uint32 rippleQualityOut(const uint160& uToAccountID, const uint160& uFromAccountID, const uint160& uCurrencyID) { return rippleQualityIn(uToAccountID, uFromAccountID, uCurrencyID, sfLowQualityOut, sfHighQualityOut); } diff --git a/src/SerializedLedger.h b/src/SerializedLedger.h index e60662d2d..813e4dccb 100644 --- a/src/SerializedLedger.h +++ b/src/SerializedLedger.h @@ -43,25 +43,25 @@ public: uint16 getVersion() const { return mVersion.getValue(); } const LedgerEntryFormat* getFormat() { return mFormat; } - int getIFieldIndex(SOE_Field field) const { return mObject.getFieldIndex(field); } + int getIFieldIndex(SField::ref field) const { return mObject.getFieldIndex(field); } int getIFieldCount() const { return mObject.getCount(); } - const SerializedType& peekIField(SOE_Field field) const { return mObject.peekAtField(field); } - SerializedType& getIField(SOE_Field field) { return mObject.getField(field); } - SOE_Field getIFieldSType(int index) { return mObject.getFieldSType(index); } + const SerializedType& peekIField(SField::ref field) const { return mObject.peekAtField(field); } + SerializedType& getIField(SField::ref field) { return mObject.getField(field); } + SField::ref getIFieldSType(int index) { return mObject.getFieldSType(index); } - std::string getIFieldString(SOE_Field field) const { return mObject.getFieldString(field); } - unsigned char getIFieldU8(SOE_Field field) const { return mObject.getValueFieldU8(field); } - uint16 getIFieldU16(SOE_Field field) const { return mObject.getValueFieldU16(field); } - uint32 getIFieldU32(SOE_Field field) const { return mObject.getValueFieldU32(field); } - uint64 getIFieldU64(SOE_Field field) const { return mObject.getValueFieldU64(field); } - uint128 getIFieldH128(SOE_Field field) const { return mObject.getValueFieldH128(field); } - uint160 getIFieldH160(SOE_Field field) const { return mObject.getValueFieldH160(field); } - uint256 getIFieldH256(SOE_Field field) const { return mObject.getValueFieldH256(field); } - std::vector getIFieldVL(SOE_Field field) const { return mObject.getValueFieldVL(field); } - std::vector getIFieldTL(SOE_Field field) const { return mObject.getValueFieldTL(field); } - NewcoinAddress getIValueFieldAccount(SOE_Field field) const { return mObject.getValueFieldAccount(field); } - STAmount getIValueFieldAmount(SOE_Field field) const { return mObject.getValueFieldAmount(field); } - STVector256 getIFieldV256(SOE_Field field) { return mObject.getValueFieldV256(field); } + std::string getIFieldString(SField::ref field) const { return mObject.getFieldString(field); } + unsigned char getIFieldU8(SField::ref field) const { return mObject.getValueFieldU8(field); } + uint16 getIFieldU16(SField::ref field) const { return mObject.getValueFieldU16(field); } + uint32 getIFieldU32(SField::ref field) const { return mObject.getValueFieldU32(field); } + uint64 getIFieldU64(SField::ref field) const { return mObject.getValueFieldU64(field); } + uint128 getIFieldH128(SField::ref field) const { return mObject.getValueFieldH128(field); } + uint160 getIFieldH160(SField::ref field) const { return mObject.getValueFieldH160(field); } + uint256 getIFieldH256(SField::ref field) const { return mObject.getValueFieldH256(field); } + std::vector getIFieldVL(SField::ref field) const { return mObject.getValueFieldVL(field); } + std::vector getIFieldTL(SField::ref field) const { return mObject.getValueFieldTL(field); } + NewcoinAddress getIValueFieldAccount(SField::ref field) const { return mObject.getValueFieldAccount(field); } + STAmount getIValueFieldAmount(SField::ref field) const { return mObject.getValueFieldAmount(field); } + STVector256 getIFieldV256(SField::ref field) { return mObject.getValueFieldV256(field); } bool isThreadedType(); // is this a ledger entry that can be threaded bool isThreaded(); // is this ledger entry actually threaded @@ -75,28 +75,28 @@ public: bool thread(const uint256& txID, uint32 ledgerSeq, uint256& prevTxID, uint32& prevLedgerID); std::vector getOwners(); // nodes notified if this node is deleted - void setIFieldU8(SOE_Field field, unsigned char v) { return mObject.setValueFieldU8(field, v); } - void setIFieldU16(SOE_Field field, uint16 v) { return mObject.setValueFieldU16(field, v); } - void setIFieldU32(SOE_Field field, uint32 v) { return mObject.setValueFieldU32(field, v); } - void setIFieldU64(SOE_Field field, uint64 v) { return mObject.setValueFieldU64(field, v); } - void setIFieldH128(SOE_Field field, const uint128& v) { return mObject.setValueFieldH128(field, v); } - void setIFieldH160(SOE_Field field, const uint160& v) { return mObject.setValueFieldH160(field, v); } - void setIFieldH256(SOE_Field field, const uint256& v) { return mObject.setValueFieldH256(field, v); } - void setIFieldVL(SOE_Field field, const std::vector& v) + void setIFieldU8(SField::ref field, unsigned char v) { return mObject.setValueFieldU8(field, v); } + void setIFieldU16(SField::ref field, uint16 v) { return mObject.setValueFieldU16(field, v); } + void setIFieldU32(SField::ref field, uint32 v) { return mObject.setValueFieldU32(field, v); } + void setIFieldU64(SField::ref field, uint64 v) { return mObject.setValueFieldU64(field, v); } + void setIFieldH128(SField::ref field, const uint128& v) { return mObject.setValueFieldH128(field, v); } + void setIFieldH160(SField::ref field, const uint160& v) { return mObject.setValueFieldH160(field, v); } + void setIFieldH256(SField::ref field, const uint256& v) { return mObject.setValueFieldH256(field, v); } + void setIFieldVL(SField::ref field, const std::vector& v) { return mObject.setValueFieldVL(field, v); } - void setIFieldTL(SOE_Field field, const std::vector& v) + void setIFieldTL(SField::ref field, const std::vector& v) { return mObject.setValueFieldTL(field, v); } - void setIFieldAccount(SOE_Field field, const uint160& account) + void setIFieldAccount(SField::ref field, const uint160& account) { return mObject.setValueFieldAccount(field, account); } - void setIFieldAccount(SOE_Field field, const NewcoinAddress& account) + void setIFieldAccount(SField::ref field, const NewcoinAddress& account) { return mObject.setValueFieldAccount(field, account); } - void setIFieldAmount(SOE_Field field, const STAmount& amount) + void setIFieldAmount(SField::ref field, const STAmount& amount) { return mObject.setValueFieldAmount(field, amount); } - void setIFieldV256(SOE_Field field, const STVector256& v) { return mObject.setValueFieldV256(field, v); } + void setIFieldV256(SField::ref field, const STVector256& v) { return mObject.setValueFieldV256(field, v); } - bool getIFieldPresent(SOE_Field field) const { return mObject.isFieldPresent(field); } - void makeIFieldPresent(SOE_Field field) { mObject.makeFieldPresent(field); } - void makeIFieldAbsent(SOE_Field field) { return mObject.makeFieldAbsent(field); } + bool getIFieldPresent(SField::ref field) const { return mObject.isFieldPresent(field); } + void makeIFieldPresent(SField::ref field) { mObject.makeFieldPresent(field); } + void makeIFieldAbsent(SField::ref field) { return mObject.makeFieldAbsent(field); } }; typedef SerializedLedgerEntry SLE; diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index c1167a6d6..d935022cb 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -8,7 +8,7 @@ #include "Log.h" -std::auto_ptr STObject::makeDefaultObject(SerializedTypeID id, FieldName* name) +std::auto_ptr STObject::makeDefaultObject(SerializedTypeID id, SField::ref name) { switch(id) { @@ -53,7 +53,7 @@ std::auto_ptr STObject::makeDefaultObject(SerializedTypeID id, F } } -std::auto_ptr STObject::makeDeserializedObject(SerializedTypeID id, FieldName* name, +std::auto_ptr STObject::makeDeserializedObject(SerializedTypeID id, SField::ref name, SerializerIterator& sit, int depth) { switch(id) @@ -114,19 +114,19 @@ void STObject::set(const SOElement* elem) { mType.push_back(elem); if (elem->flags == SOE_OPTIONAL) - giveObject(makeDefaultObject(STI_NOTPRESENT, elem->e_name)); + giveObject(makeDefaultObject(STI_NOTPRESENT, elem)); else - giveObject(makeDefaultObject(elem->e_id, elem->e_name)); + giveObject(makeDefaultObject(elem->e_field, elem)); ++elem; } } -STObject::STObject(const SOElement* elem, FieldName* name) : SerializedType(name) +STObject::STObject(const SOElement* elem, SField::ref name) : SerializedType(name) { set(elem); } -void STObject::set(FieldName* name, SerializerIterator& sit, int depth = 0) +void STObject::set(SField::ref name, SerializerIterator& sit, int depth = 0) { mData.empty(); mType.empty(); @@ -139,12 +139,12 @@ void STObject::set(FieldName* name, SerializerIterator& sit, int depth = 0) sit.getFieldID(type, field); if ((type == STI_ARRAY) && (field == 1)) return; - FieldName* fn = getFieldName(type, field); + SField::ref fn = SField::getField(type, field); giveObject(makeDeserializedObject(static_cast type, fn, sit, depth + 1); } } -STObject::STObject(const SOElement* elem, SerializerIterator& sit, FieldName*name) : SerializedType(name) +STObject::STObject(const SOElement* elem, SerializerIterator& sit, SField::refname) : SerializedType(name) { set(elem, sit); } diff --git a/src/SerializedObject.h b/src/SerializedObject.h index f4f372ac5..491e85a59 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -13,7 +13,7 @@ struct SOElement { // An element in the description of a serialized object - SOE_Field e_field; + SField::ref e_field; SOE_Flags flags; }; @@ -24,13 +24,17 @@ protected: std::vector mType; STObject* duplicate() const { return new STObject(*this); } + static STObject* construct(SerializerIterator&, SField::ref); public: - STObject(FieldName *n = NULL) : SerializedType(n) { ; } - STObject(const SOElement *t, FieldName *n = NULL); - STObject(const SOElement *t, SerializerIterator& u, FieldName *n = NULL); + STObject(SField *n = NULL) : SerializedType(n) { ; } + STObject(const SOElement *t, SField *n = NULL); + STObject(const SOElement *t, SerializerIterator& u, SField *n = NULL); virtual ~STObject() { ; } + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) + { return std::auto_ptr(construct(sit, name)); } + void set(const SOElement* t); void set(const SOElement* t, SerializerIterator& u, int depth = 0); @@ -61,54 +65,54 @@ public: const SerializedType* peekAtPIndex(int offset) const { return &(mData[offset]); } SerializedType* getPIndex(int offset) { return &(mData[offset]); } - int getFieldIndex(SOE_Field field) const; - SOE_Field getFieldSType(int index) const; + int getFieldIndex(SField::ref field) const; + SField::ref getFieldSType(int index) const; - const SerializedType& peekAtField(SOE_Field field) const; - SerializedType& getField(SOE_Field field); - const SerializedType* peekAtPField(SOE_Field field) const; - SerializedType* getPField(SOE_Field field); - const SOElement* getFieldType(SOE_Field field) const; + const SerializedType& peekAtField(SField::ref field) const; + SerializedType& getField(SField::ref field); + const SerializedType* peekAtPField(SField::ref field) const; + SerializedType* getPField(SField::ref field); + const SOElement* getFieldType(SField::ref field) const; // these throw if the field type doesn't match, or return default values if the // field is optional but not present - std::string getFieldString(SOE_Field field) const; - unsigned char getValueFieldU8(SOE_Field field) const; - uint16 getValueFieldU16(SOE_Field field) const; - uint32 getValueFieldU32(SOE_Field field) const; - uint64 getValueFieldU64(SOE_Field field) const; - uint128 getValueFieldH128(SOE_Field field) const; - uint160 getValueFieldH160(SOE_Field field) const; - uint256 getValueFieldH256(SOE_Field field) const; - NewcoinAddress getValueFieldAccount(SOE_Field field) const; - std::vector getValueFieldVL(SOE_Field field) const; - std::vector getValueFieldTL(SOE_Field field) const; - STAmount getValueFieldAmount(SOE_Field field) const; - STPathSet getValueFieldPathSet(SOE_Field field) const; - STVector256 getValueFieldV256(SOE_Field field) const; + std::string getFieldString(SField::ref field) const; + unsigned char getValueFieldU8(SField::ref field) const; + uint16 getValueFieldU16(SField::ref field) const; + uint32 getValueFieldU32(SField::ref field) const; + uint64 getValueFieldU64(SField::ref field) const; + uint128 getValueFieldH128(SField::ref field) const; + uint160 getValueFieldH160(SField::ref field) const; + uint256 getValueFieldH256(SField::ref field) const; + NewcoinAddress getValueFieldAccount(SField::ref field) const; + std::vector getValueFieldVL(SField::ref field) const; + std::vector getValueFieldTL(SField::ref field) const; + STAmount getValueFieldAmount(SField::ref field) const; + STPathSet getValueFieldPathSet(SField::ref field) const; + STVector256 getValueFieldV256(SField::ref field) const; - void setValueFieldU8(SOE_Field field, unsigned char); - void setValueFieldU16(SOE_Field field, uint16); - void setValueFieldU32(SOE_Field field, uint32); - void setValueFieldU64(SOE_Field field, uint64); - void setValueFieldH128(SOE_Field field, const uint128&); - void setValueFieldH160(SOE_Field field, const uint160&); - void setValueFieldH256(SOE_Field field, const uint256&); - void setValueFieldVL(SOE_Field field, const std::vector&); - void setValueFieldTL(SOE_Field field, const std::vector&); - void setValueFieldAccount(SOE_Field field, const uint160&); - void setValueFieldAccount(SOE_Field field, const NewcoinAddress& addr) + void setValueFieldU8(SField::ref field, unsigned char); + void setValueFieldU16(SField::ref field, uint16); + void setValueFieldU32(SField::ref field, uint32); + void setValueFieldU64(SField::ref field, uint64); + void setValueFieldH128(SField::ref field, const uint128&); + void setValueFieldH160(SField::ref field, const uint160&); + void setValueFieldH256(SField::ref field, const uint256&); + void setValueFieldVL(SField::ref field, const std::vector&); + void setValueFieldTL(SField::ref field, const std::vector&); + void setValueFieldAccount(SField::ref field, const uint160&); + void setValueFieldAccount(SField::ref field, const NewcoinAddress& addr) { setValueFieldAccount(field, addr.getAccountID()); } - void setValueFieldAmount(SOE_Field field, const STAmount&); - void setValueFieldPathSet(SOE_Field field, const STPathSet&); - void setValueFieldV256(SOE_Field field, const STVector256& v); + void setValueFieldAmount(SField::ref field, const STAmount&); + void setValueFieldPathSet(SField::ref field, const STPathSet&); + void setValueFieldV256(SField::ref field, const STVector256& v); - bool isFieldPresent(SOE_Field field) const; - SerializedType* makeFieldPresent(SOE_Field field); - void makeFieldAbsent(SOE_Field field); + bool isFieldPresent(SField::ref field) const; + SerializedType* makeFieldPresent(SField::ref field); + void makeFieldAbsent(SField::ref field); - static std::auto_ptr makeDefaultObject(SerializedTypeID id, FieldName *name); - static std::auto_ptr makeDeserializedObject(SerializedTypeID id, FieldName *name, + static std::auto_ptr makeDefaultObject(SerializedTypeID id, SField *name); + static std::auto_ptr makeDeserializedObject(SerializedTypeID id, SField *name, SerializerIterator&, int depth); static void unitTest(); @@ -128,16 +132,16 @@ protected: vector value; - STArray* duplicate() const { return new STArray(fName, value); } - static STArray* construct(SerializerIterator&, FieldName* name = NULL); + STArray* duplicate() const { return new STArray(*this); } + static STArray* construct(SerializerIterator&, SField::ref); public: STArray() { ; } - STArray(FieldName* f, const vector& v) : SerializedType(f), value(v) { ; } + STArray(SField::ref f, const vector& v) : SerializedType(f), value(v) { ; } STArray(vector& v) : value(v) { ; } - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } const vector& getValue() const { return value; } diff --git a/src/SerializedTransaction.h b/src/SerializedTransaction.h index ee4ffb3ea..d1278b864 100644 --- a/src/SerializedTransaction.h +++ b/src/SerializedTransaction.h @@ -71,50 +71,50 @@ public: void setSequence(uint32); // inner transaction field functions - int getITFieldIndex(SOE_Field field) const; + int getITFieldIndex(SField::ref field) const; int getITFieldCount() const; - const SerializedType& peekITField(SOE_Field field) const; - SerializedType& getITField(SOE_Field field); + const SerializedType& peekITField(SField::ref field) const; + SerializedType& getITField(SField::ref field); // inner transaction field value functions - std::string getITFieldString(SOE_Field field) const { return mInnerTxn.getFieldString(field); } - unsigned char getITFieldU8(SOE_Field field) const { return mInnerTxn.getValueFieldU8(field); } - uint16 getITFieldU16(SOE_Field field) const { return mInnerTxn.getValueFieldU16(field); } - uint32 getITFieldU32(SOE_Field field) const { return mInnerTxn.getValueFieldU32(field); } - uint64 getITFieldU64(SOE_Field field) const { return mInnerTxn.getValueFieldU64(field); } - uint128 getITFieldH128(SOE_Field field) const { return mInnerTxn.getValueFieldH128(field); } - uint160 getITFieldH160(SOE_Field field) const { return mInnerTxn.getValueFieldH160(field); } - uint160 getITFieldAccount(SOE_Field field) const; - uint256 getITFieldH256(SOE_Field field) const { return mInnerTxn.getValueFieldH256(field); } - std::vector getITFieldVL(SOE_Field field) const { return mInnerTxn.getValueFieldVL(field); } - std::vector getITFieldTL(SOE_Field field) const { return mInnerTxn.getValueFieldTL(field); } - STAmount getITFieldAmount(SOE_Field field) const { return mInnerTxn.getValueFieldAmount(field); } - STPathSet getITFieldPathSet(SOE_Field field) const { return mInnerTxn.getValueFieldPathSet(field); } + std::string getITFieldString(SField::ref field) const { return mInnerTxn.getFieldString(field); } + unsigned char getITFieldU8(SField::ref field) const { return mInnerTxn.getValueFieldU8(field); } + uint16 getITFieldU16(SField::ref field) const { return mInnerTxn.getValueFieldU16(field); } + uint32 getITFieldU32(SField::ref field) const { return mInnerTxn.getValueFieldU32(field); } + uint64 getITFieldU64(SField::ref field) const { return mInnerTxn.getValueFieldU64(field); } + uint128 getITFieldH128(SField::ref field) const { return mInnerTxn.getValueFieldH128(field); } + uint160 getITFieldH160(SField::ref field) const { return mInnerTxn.getValueFieldH160(field); } + uint160 getITFieldAccount(SField::ref field) const; + uint256 getITFieldH256(SField::ref field) const { return mInnerTxn.getValueFieldH256(field); } + std::vector getITFieldVL(SField::ref field) const { return mInnerTxn.getValueFieldVL(field); } + std::vector getITFieldTL(SField::ref field) const { return mInnerTxn.getValueFieldTL(field); } + STAmount getITFieldAmount(SField::ref field) const { return mInnerTxn.getValueFieldAmount(field); } + STPathSet getITFieldPathSet(SField::ref field) const { return mInnerTxn.getValueFieldPathSet(field); } - void setITFieldU8(SOE_Field field, unsigned char v) { return mInnerTxn.setValueFieldU8(field, v); } - void setITFieldU16(SOE_Field field, uint16 v) { return mInnerTxn.setValueFieldU16(field, v); } - void setITFieldU32(SOE_Field field, uint32 v) { return mInnerTxn.setValueFieldU32(field, v); } - void setITFieldU64(SOE_Field field, uint32 v) { return mInnerTxn.setValueFieldU64(field, v); } - void setITFieldH128(SOE_Field field, const uint128& v) { return mInnerTxn.setValueFieldH128(field, v); } - void setITFieldH160(SOE_Field field, const uint160& v) { return mInnerTxn.setValueFieldH160(field, v); } - void setITFieldH256(SOE_Field field, const uint256& v) { return mInnerTxn.setValueFieldH256(field, v); } - void setITFieldVL(SOE_Field field, const std::vector& v) + void setITFieldU8(SField::ref field, unsigned char v) { return mInnerTxn.setValueFieldU8(field, v); } + void setITFieldU16(SField::ref field, uint16 v) { return mInnerTxn.setValueFieldU16(field, v); } + void setITFieldU32(SField::ref field, uint32 v) { return mInnerTxn.setValueFieldU32(field, v); } + void setITFieldU64(SField::ref field, uint32 v) { return mInnerTxn.setValueFieldU64(field, v); } + void setITFieldH128(SField::ref field, const uint128& v) { return mInnerTxn.setValueFieldH128(field, v); } + void setITFieldH160(SField::ref field, const uint160& v) { return mInnerTxn.setValueFieldH160(field, v); } + void setITFieldH256(SField::ref field, const uint256& v) { return mInnerTxn.setValueFieldH256(field, v); } + void setITFieldVL(SField::ref field, const std::vector& v) { return mInnerTxn.setValueFieldVL(field, v); } - void setITFieldTL(SOE_Field field, const std::vector& v) + void setITFieldTL(SField::ref field, const std::vector& v) { return mInnerTxn.setValueFieldTL(field, v); } - void setITFieldAccount(SOE_Field field, const uint160& v) + void setITFieldAccount(SField::ref field, const uint160& v) { return mInnerTxn.setValueFieldAccount(field, v); } - void setITFieldAccount(SOE_Field field, const NewcoinAddress& v) + void setITFieldAccount(SField::ref field, const NewcoinAddress& v) { return mInnerTxn.setValueFieldAccount(field, v); } - void setITFieldAmount(SOE_Field field, const STAmount& v) + void setITFieldAmount(SField::ref field, const STAmount& v) { return mInnerTxn.setValueFieldAmount(field, v); } - void setITFieldPathSet(SOE_Field field, const STPathSet& v) + void setITFieldPathSet(SField::ref field, const STPathSet& v) { return mInnerTxn.setValueFieldPathSet(field, v); } // optional field functions - bool getITFieldPresent(SOE_Field field) const; - void makeITFieldPresent(SOE_Field field); - void makeITFieldAbsent(SOE_Field field); + bool getITFieldPresent(SField::ref field) const; + void makeITFieldPresent(SField::ref field); + void makeITFieldAbsent(SField::ref field); std::vector getAffectedAccounts() const; diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index 25339b92e..6eeb0c912 100644 --- a/src/SerializedTypes.cpp +++ b/src/SerializedTypes.cpp @@ -27,7 +27,7 @@ std::string SerializedType::getFullText() const return ret; } -STUInt8* STUInt8::construct(SerializerIterator& u, FieldName* name) +STUInt8* STUInt8::construct(SerializerIterator& u, SField::ref name) { return new STUInt8(name, u.get8()); } @@ -43,7 +43,7 @@ bool STUInt8::isEquivalent(const SerializedType& t) const return v && (value == v->value); } -STUInt16* STUInt16::construct(SerializerIterator& u, FieldName* name) +STUInt16* STUInt16::construct(SerializerIterator& u, SField::ref name) { return new STUInt16(name, u.get16()); } @@ -59,7 +59,7 @@ bool STUInt16::isEquivalent(const SerializedType& t) const return v && (value == v->value); } -STUInt32* STUInt32::construct(SerializerIterator& u, FieldName* name) +STUInt32* STUInt32::construct(SerializerIterator& u, SField::ref name) { return new STUInt32(name, u.get32()); } @@ -75,7 +75,7 @@ bool STUInt32::isEquivalent(const SerializedType& t) const return v && (value == v->value); } -STUInt64* STUInt64::construct(SerializerIterator& u, FieldName* name) +STUInt64* STUInt64::construct(SerializerIterator& u, SField::ref name) { return new STUInt64(name, u.get64()); } @@ -91,7 +91,7 @@ bool STUInt64::isEquivalent(const SerializedType& t) const return v && (value == v->value); } -STHash128* STHash128::construct(SerializerIterator& u, FieldName* name) +STHash128* STHash128::construct(SerializerIterator& u, SField::ref name) { return new STHash128(name, u.get128()); } @@ -107,7 +107,7 @@ bool STHash128::isEquivalent(const SerializedType& t) const return v && (value == v->value); } -STHash160* STHash160::construct(SerializerIterator& u, FieldName* name) +STHash160* STHash160::construct(SerializerIterator& u, SField::ref name) { return new STHash160(name, u.get160()); } @@ -123,7 +123,7 @@ bool STHash160::isEquivalent(const SerializedType& t) const return v && (value == v->value); } -STHash256* STHash256::construct(SerializerIterator& u, FieldName* name) +STHash256* STHash256::construct(SerializerIterator& u, SField::ref name) { return new STHash256(name, u.get256()); } @@ -139,7 +139,7 @@ bool STHash256::isEquivalent(const SerializedType& t) const return v && (value == v->value); } -STVariableLength::STVariableLength(SerializerIterator& st, FieldName* name) : SerializedType(name) +STVariableLength::STVariableLength(SerializerIterator& st, SField::ref name) : SerializedType(name) { value = st.getVL(); } @@ -149,7 +149,7 @@ std::string STVariableLength::getText() const return strHex(value); } -STVariableLength* STVariableLength::construct(SerializerIterator& u, FieldName* name) +STVariableLength* STVariableLength::construct(SerializerIterator& u, SField::ref name) { return new STVariableLength(name, u.getVL()); } @@ -171,7 +171,7 @@ std::string STAccount::getText() const return a.humanAccountID(); } -STAccount* STAccount::construct(SerializerIterator& u, FieldName* name) +STAccount* STAccount::construct(SerializerIterator& u, SField::ref name) { return new STAccount(name, u.getVL()); } @@ -181,7 +181,7 @@ STAccount* STAccount::construct(SerializerIterator& u, FieldName* name) // // Return a new object from a SerializerIterator. -STVector256* STVector256::construct(SerializerIterator& u, FieldName* name) +STVector256* STVector256::construct(SerializerIterator& u, SField::ref name) { std::vector data = u.getVL(); std::vector value; @@ -250,7 +250,7 @@ void STAccount::setValueNCA(const NewcoinAddress& nca) setValueH160(nca.getAccountID()); } -STPathSet* STPathSet::construct(SerializerIterator& s, FieldName* name) +STPathSet* STPathSet::construct(SerializerIterator& s, SField::ref name) { std::vector paths; std::vector path; diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index f31a468d8..2085ab38a 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -33,23 +33,24 @@ enum PathFlags class SerializedType { protected: - FieldName* fName; + SField::ptr fName; - virtual SerializedType* duplicate() const { return new SerializedType(fName); } + virtual SerializedType* duplicate() const { return new SerializedType(*fName); } + SerializedType(SField::ptr n) : fName(n) { assert(fName); } public: - SerializedType() : fName(NULL) { ; } - SerializedType(FieldName* n) : fName(n) { ; } + SerializedType() : fName(&sfGeneric) { ; } + SerializedType(SField::ref n) : fName(&n) { assert(fName); } SerializedType(const SerializedType& n) : fName(n.fName) { ; } virtual ~SerializedType() { ; } - static std::auto_ptr deserialize(FieldName* name) + static std::auto_ptr deserialize(SField::ref name) { return std::auto_ptr(new SerializedType(name)); } - void setFName(FieldName* n) { fName=n; } - FieldName* getFName() { return fName; } - const char *getName() const { return (fName != NULL) ? fName->fieldName : NULL; } + void setFName(SField::ref n) { fName = &n; assert(fName); } + SField::ref getFName() { return *fName; } + const char *getName() const { return fName->fieldName; } virtual SerializedTypeID getSType() const { return STI_NOTPRESENT; } std::auto_ptr clone() const { return std::auto_ptr(duplicate()); } @@ -66,7 +67,7 @@ public: { assert(getSType() == STI_NOTPRESENT); return t.getSType() == STI_NOTPRESENT; } SerializedType& operator=(const SerializedType& t) - { if (fName == NULL) fName = t.fName; return *this; } + { if (!fName->fieldCode) fName = t.fName; return *this; } bool operator==(const SerializedType& t) const { return (getSType() == t.getSType()) && isEquivalent(t); } bool operator!=(const SerializedType& t) const @@ -82,14 +83,14 @@ class STUInt8 : public SerializedType protected: unsigned char value; - STUInt8* duplicate() const { return new STUInt8(fName, value); } - static STUInt8* construct(SerializerIterator&, FieldName* name = NULL); + STUInt8* duplicate() const { return new STUInt8(*this); } + static STUInt8* construct(SerializerIterator&, SField::ref f); public: - STUInt8(unsigned char v=0) : value(v) { ; } - STUInt8(FieldName* n, unsigned char v=0) : SerializedType(n), value(v) { ; } - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + STUInt8(unsigned char v = 0) : value(v) { ; } + STUInt8(SField::ref n, unsigned char v=0) : SerializedType(n), value(v) { ; } + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } SerializedTypeID getSType() const { return STI_UINT8; } @@ -108,14 +109,14 @@ class STUInt16 : public SerializedType protected: uint16 value; - STUInt16* duplicate() const { return new STUInt16(fName, value); } - static STUInt16* construct(SerializerIterator&, FieldName* name = NULL); + STUInt16* duplicate() const { return new STUInt16(*this); } + static STUInt16* construct(SerializerIterator&, SField::ref name); public: STUInt16(uint16 v=0) : value(v) { ; } - STUInt16(FieldName* n, uint16 v=0) : SerializedType(n), value(v) { ; } - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + STUInt16(SField::ref n, uint16 v=0) : SerializedType(n), value(v) { ; } + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } SerializedTypeID getSType() const { return STI_UINT16; } @@ -134,14 +135,14 @@ class STUInt32 : public SerializedType protected: uint32 value; - STUInt32* duplicate() const { return new STUInt32(fName, value); } - static STUInt32* construct(SerializerIterator&, FieldName* name = NULL); + STUInt32* duplicate() const { return new STUInt32(*this); } + static STUInt32* construct(SerializerIterator&, SField::ref name); public: - STUInt32(uint32 v=0) : value(v) { ; } - STUInt32(FieldName* n, uint32 v=0) : SerializedType(n), value(v) { ; } - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + STUInt32(uint32 v = 0) : value(v) { ; } + STUInt32(SField::ref n, uint32 v=0) : SerializedType(n), value(v) { ; } + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } SerializedTypeID getSType() const { return STI_UINT32; } @@ -160,14 +161,14 @@ class STUInt64 : public SerializedType protected: uint64 value; - STUInt64* duplicate() const { return new STUInt64(fName, value); } - static STUInt64* construct(SerializerIterator&, FieldName* name = NULL); + STUInt64* duplicate() const { return new STUInt64(*this); } + static STUInt64* construct(SerializerIterator&, SField::ref name); public: STUInt64(uint64 v=0) : value(v) { ; } - STUInt64(FieldName* n, uint64 v=0) : SerializedType(n), value(v) { ; } - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + STUInt64(SField::ref n, uint64 v=0) : SerializedType(n), value(v) { ; } + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } SerializedTypeID getSType() const { return STI_UINT64; } @@ -205,7 +206,7 @@ protected: void canonicalize(); STAmount* duplicate() const { return new STAmount(*this); } - static STAmount* construct(SerializerIterator&, FieldName* name = NULL); + static STAmount* construct(SerializerIterator&, SField::ref name); static const int cMinOffset = -96, cMaxOffset = 80; static const uint64 cMinValue = 1000000000000000ull, cMaxValue = 9999999999999999ull; @@ -215,10 +216,10 @@ protected: STAmount(bool isNeg, uint64 value) : mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNeg) { ; } - STAmount(FieldName *name, uint64 value, bool isNegative) + STAmount(SField *name, uint64 value, bool isNegative) : SerializedType(fName), mValue(value), mOffset(0), mIsNative(true), mIsNegative(isNegative) { ; } - STAmount(FieldName *n, const uint160& cur, const uint160& iss, uint64 val, int off, bool isNat, bool isNeg) + STAmount(SField *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), mIsNative(isNat), mIsNegative(isNeg) { ; } @@ -231,7 +232,7 @@ public: STAmount(uint64 v = 0, bool isNeg = false) : mValue(v), mOffset(0), mIsNative(true), mIsNegative(isNeg) { if (v==0) mIsNegative = false; } - STAmount(FieldName* n, uint64 v = 0) + STAmount(SField::ref n, uint64 v = 0) : SerializedType(n), mValue(v), mOffset(0), mIsNative(true), mIsNegative(false) { ; } @@ -240,14 +241,14 @@ public: { canonicalize(); } // YYY This should probably require issuer too. - STAmount(FieldName* n, const uint160& currency, const uint160& issuer, + STAmount(SField::ref n, const uint160& currency, const uint160& issuer, uint64 v = 0, int off = 0, bool isNeg = false) : SerializedType(n), mCurrency(currency), mIssuer(issuer), mValue(v), mOffset(off), mIsNegative(isNeg) { canonicalize(); } - STAmount(FieldName* n, int64 v); + STAmount(SField::ref n, int64 v); - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } static STAmount saFromRate(uint64 uRate = 0) @@ -357,7 +358,7 @@ public: // Native currency conversions, to/from display format static uint64 convertToDisplayAmount(const STAmount& internalAmount, uint64 totalNow, uint64 totalInit); static STAmount convertToInternalAmount(uint64 displayAmount, uint64 totalNow, uint64 totalInit, - FieldName* name = NULL); + SField::ref name = sfGeneric); static std::string createHumanCurrency(const uint160& uCurrency); static STAmount deserialize(SerializerIterator&); @@ -374,16 +375,16 @@ class STHash128 : public SerializedType protected: uint128 value; - STHash128* duplicate() const { return new STHash128(fName, value); } - static STHash128* construct(SerializerIterator&, FieldName* name = NULL); + STHash128* duplicate() const { return new STHash128(*this); } + static STHash128* construct(SerializerIterator&, SField::ref name); public: STHash128(const uint128& v) : value(v) { ; } - STHash128(FieldName* n, const uint128& v) : SerializedType(n), value(v) { ; } - STHash128(FieldName* n) : SerializedType(n) { ; } + STHash128(SField::ref n, const uint128& v) : SerializedType(n), value(v) { ; } + STHash128(SField::ref n) : SerializedType(n) { ; } STHash128() { ; } - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } SerializedTypeID getSType() const { return STI_HASH128; } @@ -402,16 +403,16 @@ class STHash160 : public SerializedType protected: uint160 value; - STHash160* duplicate() const { return new STHash160(fName, value); } - static STHash160* construct(SerializerIterator&, FieldName* name = NULL); + STHash160* duplicate() const { return new STHash160(*this); } + static STHash160* construct(SerializerIterator&, SField::ref name); public: STHash160(const uint160& v) : value(v) { ; } - STHash160(FieldName* n, const uint160& v) : SerializedType(n), value(v) { ; } - STHash160(FieldName* n) : SerializedType(n) { ; } + STHash160(SField::ref n, const uint160& v) : SerializedType(n), value(v) { ; } + STHash160(SField::ref n) : SerializedType(n) { ; } STHash160() { ; } - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } SerializedTypeID getSType() const { return STI_HASH160; } @@ -430,16 +431,16 @@ class STHash256 : public SerializedType protected: uint256 value; - STHash256* duplicate() const { return new STHash256(fName, value); } - static STHash256* construct(SerializerIterator&, FieldName* name = NULL); + STHash256* duplicate() const { return new STHash256(*this); } + static STHash256* construct(SerializerIterator&, SField::ref); public: STHash256(const uint256& v) : value(v) { ; } - STHash256(FieldName* n, const uint256& v) : SerializedType(n), value(v) { ; } - STHash256(FieldName* n) : SerializedType(n) { ; } + STHash256(SField::ref n, const uint256& v) : SerializedType(n), value(v) { ; } + STHash256(SField::ref n) : SerializedType(n) { ; } STHash256() { ; } - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } SerializedTypeID getSType() const { return STI_HASH256; } @@ -458,17 +459,17 @@ class STVariableLength : public SerializedType protected: std::vector value; - virtual STVariableLength* duplicate() const { return new STVariableLength(fName, value); } - static STVariableLength* construct(SerializerIterator&, FieldName* name = NULL); + virtual STVariableLength* duplicate() const { return new STVariableLength(*this); } + static STVariableLength* construct(SerializerIterator&, SField::ref); public: STVariableLength(const std::vector& v) : value(v) { ; } - STVariableLength(FieldName* n, const std::vector& v) : SerializedType(n), value(v) { ; } - STVariableLength(FieldName* n) : SerializedType(n) { ; } - STVariableLength(SerializerIterator&, FieldName* name = NULL); + STVariableLength(SField::ref n, const std::vector& v) : SerializedType(n), value(v) { ; } + STVariableLength(SField::ref n) : SerializedType(n) { ; } + STVariableLength(SerializerIterator&, SField::ref name = sfGeneric); STVariableLength() { ; } - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } virtual SerializedTypeID getSType() const { return STI_VL; } @@ -487,16 +488,16 @@ public: class STAccount : public STVariableLength { protected: - virtual STAccount* duplicate() const { return new STAccount(fName, value); } - static STAccount* construct(SerializerIterator&, FieldName* name = NULL); + virtual STAccount* duplicate() const { return new STAccount(*this); } + static STAccount* construct(SerializerIterator&, SField::ref); public: STAccount(const std::vector& v) : STVariableLength(v) { ; } - STAccount(FieldName* n, const std::vector& v) : STVariableLength(n, v) { ; } - STAccount(FieldName* n) : STVariableLength(n) { ; } + STAccount(SField::ref n, const std::vector& v) : STVariableLength(n, v) { ; } + STAccount(SField::ref n) : STVariableLength(n) { ; } STAccount() { ; } - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } SerializedTypeID getSType() const { return STI_ACCOUNT; } @@ -625,16 +626,16 @@ class STPathSet : public SerializedType protected: std::vector value; - STPathSet* duplicate() const { return new STPathSet(fName, value); } - static STPathSet* construct(SerializerIterator&, FieldName* name = NULL); + STPathSet* duplicate() const { return new STPathSet(*this); } + static STPathSet* construct(SerializerIterator&, SField::ref); public: STPathSet() { ; } - STPathSet(FieldName* n) : SerializedType(n) { ; } + STPathSet(SField::ref n) : SerializedType(n) { ; } STPathSet(const std::vector& v) : value(v) { ; } - STPathSet(FieldName* n, const std::vector& v) : SerializedType(n), value(v) { ; } - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + STPathSet(SField::ref n, const std::vector& v) : SerializedType(n), value(v) { ; } + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } // std::string getText() const; @@ -697,19 +698,19 @@ class STVector256 : public SerializedType protected: std::vector mValue; - STVector256* duplicate() const { return new STVector256(fName, mValue); } - static STVector256* construct(SerializerIterator&, FieldName* name = NULL); + STVector256* duplicate() const { return new STVector256(*this); } + static STVector256* construct(SerializerIterator&, SField::ref); public: STVector256() { ; } - STVector256(FieldName* n) : SerializedType(n) { ; } - STVector256(FieldName* n, const std::vector& v) : SerializedType(n), mValue(v) { ; } + STVector256(SField::ref n) : SerializedType(n) { ; } + STVector256(SField::ref n, const std::vector& v) : SerializedType(n), mValue(v) { ; } STVector256(const std::vector& vector) : mValue(vector) { ; } SerializedTypeID getSType() const { return STI_VECTOR256; } void add(Serializer& s) const; - static std::auto_ptr deserialize(SerializerIterator& sit, FieldName* name) + static std::auto_ptr deserialize(SerializerIterator& sit, SField::ref name) { return std::auto_ptr(construct(sit, name)); } const std::vector& peekValue() const { return mValue; } diff --git a/src/TransactionMeta.cpp b/src/TransactionMeta.cpp index 4c179f0b7..3f687897c 100644 --- a/src/TransactionMeta.cpp +++ b/src/TransactionMeta.cpp @@ -66,7 +66,7 @@ Json::Value TMNEThread::getJson(int) const TMNEAmount::TMNEAmount(int type, SerializerIterator& sit) : TransactionMetaNodeEntry(type) { - mAmount = *dynamic_cast(STAmount::deserialize(sit, NULL).get()); // Ouch + mAmount = *dynamic_cast(STAmount::deserialize(sit, sfAmount).get()); // Ouch } void TMNEAmount::addRaw(Serializer& s) const