diff --git a/Builds/VisualStudio2012/RippleD.vcxproj b/Builds/VisualStudio2012/RippleD.vcxproj index 59eb30c3de..8f4d920169 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj +++ b/Builds/VisualStudio2012/RippleD.vcxproj @@ -234,7 +234,7 @@ true true - + true true true @@ -1352,8 +1352,9 @@ - + + diff --git a/Builds/VisualStudio2012/RippleD.vcxproj.filters b/Builds/VisualStudio2012/RippleD.vcxproj.filters index 7c2bd2c131..37bdbd0b3c 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2012/RippleD.vcxproj.filters @@ -264,9 +264,6 @@ [1] Ripple\ripple_data\protocol - - [1] Ripple\ripple_data\protocol - [1] Ripple\ripple_data\protocol @@ -825,6 +822,9 @@ [1] Ripple\ripple_basics\utility + + [1] Ripple\ripple_data\protocol + @@ -957,9 +957,6 @@ [1] Ripple\ripple_data\protocol - - [1] Ripple\ripple_data\protocol - [1] Ripple\ripple_data\protocol @@ -1539,6 +1536,12 @@ [1] Ripple\ripple_basics\utility + + [1] Ripple\ripple_data\protocol + + + [1] Ripple\ripple_data\protocol + diff --git a/TODO.txt b/TODO.txt index a306a20f7b..77a3d5c0e4 100644 --- a/TODO.txt +++ b/TODO.txt @@ -6,6 +6,8 @@ RIPPLE TODO * Determine why rippled has a slow startup on Windows * Improve the performance when running all unit tests on Windows +- Rename "fullBelow" to something like haveAllDescendants or haveAllChildren. + - Class to represent IP and Port number, with members to print, check syntax, etc... replace the boost calls. @@ -17,9 +19,6 @@ RIPPLE TODO subdirectories within the module as per the project filters. * Make sure there are no pending commits from David -- Refactor TxFormats into template WireFormats<> and use it for transactions - and ledger entries, replace the redundant code with template typedefs. - - Rewrite Sustain to use Beast and work on Windows as well * Do not enable watchdog process if a debugger is attached @@ -245,3 +244,10 @@ Regarding a defect where a failing transaction was being submitted over and over think it can claim a fee. With these two bits of logic, two unhealthy servers could infinitely propagate a transaction back and forth between each other. + +A node is "full below" if we believe we have (either in the database or + scheduled to be stored in the database) the contents of every node below that + node in a hash tree. When trying to acquire a hash tree/map, if a node is + full below, we know not to bother with anything below that node. + +The fullBelowCache is a cache of hashes of nodes that are full below. diff --git a/modules/ripple_data/protocol/ripple_KnownFormats.h b/modules/ripple_data/protocol/ripple_KnownFormats.h new file mode 100644 index 0000000000..25d8c8a26d --- /dev/null +++ b/modules/ripple_data/protocol/ripple_KnownFormats.h @@ -0,0 +1,171 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. +*/ +//============================================================================== + +#ifndef RIPPLE_KNOWNFORMATS_H_INCLUDED +#define RIPPLE_KNOWNFORMATS_H_INCLUDED + +/** Manages a list of known formats. + + Each format has a name, an associated KeyType (typically an enumeration), + and a predefined @ref SOElement. + + @tparam KeyType The type of key identifying the format. +*/ +template +class KnownFormats +{ +public: + /** A known format. + */ + class Item + { + public: + Item (char const* name, KeyType type) + : m_name (name) + , m_type (type) + { + } + + Item& operator<< (SOElement const& el) + { + elements.push_back (el); + + return *this; + } + + /** Retrieve the name of the format. + */ + std::string const& getName () const noexcept + { + return m_name; + } + + /** Retrieve the transaction type this format represents. + */ + KeyType getType () const noexcept + { + return m_type; + } + + public: + // VFALCO TODO make an accessor for this + SOTemplate elements; + + private: + std::string const m_name; + KeyType const m_type; + }; + +public: + /** Create the known formats object. + + Derived classes will load the object will all the known formats. + */ + KnownFormats () + { + } + + /** Destroy the known formats object. + + The defined formats are deleted. + */ + ~KnownFormats () + { + } + + /** Retrieve the type for a format specified by name. + + If the format name is unknown, an exception is thrown. + + @param name The name of the type. + @return The type. + */ + KeyType findTypeByName (std::string const name) const + { + Item const* const result = findByName (name); + + if (result != nullptr) + { + return result->getType (); + } + else + { + throw std::runtime_error ("Unknown format name"); + } + } + + /** Retrieve a format based on its type. + */ + // VFALCO TODO Can we just return the SOElement& ? + Item const* findByType (KeyType type) const noexcept + { + Item* result = nullptr; + + TypeMap::const_iterator const iter = m_types.find (type); + + if (iter != m_types.end ()) + { + result = iter->second; + } + + return result; + } + +protected: + /** Retrieve a format based on its name. + */ + Item const* findByName (std::string const& name) const noexcept + { + Item* result = nullptr; + + NameMap::const_iterator const iter = m_names.find (name); + + if (iter != m_names.end ()) + { + result = iter->second; + } + + return result; + } + + /** Add a new format. + + The new format has the set of common fields already added. + + @param name The name of this format. + @param type The type of this format. + + @return The created format. + */ + Item& add (char const* name, KeyType type) + { + Item& item = *m_formats.add (new Item (name, type)); + + addCommonFields (item); + + m_types [item.getType ()] = &item; + m_names [item.getName ()] = &item; + + return item; + } + + /** Adds common fields. + + This is called for every new item. + */ + virtual void addCommonFields (Item& item) = 0; + +private: + // VFALCO TODO use String instead of std::string + typedef std::map NameMap; + typedef std::map TypeMap; + + OwnedArray m_formats; + NameMap m_names; + TypeMap m_types; +}; + +#endif diff --git a/modules/ripple_data/protocol/ripple_LedgerFormat.cpp b/modules/ripple_data/protocol/ripple_LedgerFormats.cpp similarity index 74% rename from modules/ripple_data/protocol/ripple_LedgerFormat.cpp rename to modules/ripple_data/protocol/ripple_LedgerFormats.cpp index 5231ea182b..4c5182e6f1 100644 --- a/modules/ripple_data/protocol/ripple_LedgerFormat.cpp +++ b/modules/ripple_data/protocol/ripple_LedgerFormats.cpp @@ -4,22 +4,10 @@ */ //============================================================================== -std::map LedgerEntryFormat::byType; - -std::map LedgerEntryFormat::byName; - -#define LEF_BASE \ - << SOElement(sfLedgerIndex, SOE_OPTIONAL) \ - << SOElement(sfLedgerEntryType, SOE_REQUIRED) \ - << SOElement(sfFlags, SOE_REQUIRED) - -#define DECLARE_LEF(name, type) lef = new LedgerEntryFormat(#name, type); (*lef) LEF_BASE - -void LEFInit () +LedgerFormats::LedgerFormats () + : SharedSingleton (SingletonLifetime::persistAfterCreation) { - LedgerEntryFormat* lef; - - DECLARE_LEF (AccountRoot, ltACCOUNT_ROOT) + add ("AccountRoot", ltACCOUNT_ROOT) << SOElement (sfAccount, SOE_REQUIRED) << SOElement (sfSequence, SOE_REQUIRED) << SOElement (sfBalance, SOE_REQUIRED) @@ -35,7 +23,7 @@ void LEFInit () << SOElement (sfDomain, SOE_OPTIONAL) ; - DECLARE_LEF (Contract, ltCONTRACT) + add ("Contract", ltCONTRACT) << SOElement (sfAccount, SOE_REQUIRED) << SOElement (sfBalance, SOE_REQUIRED) << SOElement (sfPreviousTxnID, SOE_REQUIRED) @@ -50,7 +38,7 @@ void LEFInit () << SOElement (sfExpireCode, SOE_OPTIONAL) ; - DECLARE_LEF (DirectoryNode, ltDIR_NODE) + add ("DirectoryNode", ltDIR_NODE) << SOElement (sfOwner, SOE_OPTIONAL) // for owner directories << SOElement (sfTakerPaysCurrency, SOE_OPTIONAL) // for order book directories << SOElement (sfTakerPaysIssuer, SOE_OPTIONAL) // for order book directories @@ -63,16 +51,16 @@ void LEFInit () << SOElement (sfIndexPrevious, SOE_OPTIONAL) ; - DECLARE_LEF (GeneratorMap, ltGENERATOR_MAP) + add ("GeneratorMap", ltGENERATOR_MAP) << SOElement (sfGenerator, SOE_REQUIRED) ; - DECLARE_LEF (Nickname, ltNICKNAME) + add ("Nickname", ltNICKNAME) << SOElement (sfAccount, SOE_REQUIRED) << SOElement (sfMinimumOffer, SOE_OPTIONAL) ; - DECLARE_LEF (Offer, ltOFFER) + add ("Offer", ltOFFER) << SOElement (sfAccount, SOE_REQUIRED) << SOElement (sfSequence, SOE_REQUIRED) << SOElement (sfTakerPays, SOE_REQUIRED) @@ -85,7 +73,7 @@ void LEFInit () << SOElement (sfExpiration, SOE_OPTIONAL) ; - DECLARE_LEF (RippleState, ltRIPPLE_STATE) + add ("RippleState", ltRIPPLE_STATE) << SOElement (sfBalance, SOE_REQUIRED) << SOElement (sfLowLimit, SOE_REQUIRED) << SOElement (sfHighLimit, SOE_REQUIRED) @@ -99,17 +87,17 @@ void LEFInit () << SOElement (sfHighQualityOut, SOE_OPTIONAL) ; - DECLARE_LEF (LedgerHashes, ltLEDGER_HASHES) + add ("LedgerHashes", ltLEDGER_HASHES) << SOElement (sfFirstLedgerSequence, SOE_OPTIONAL) // Remove if we do a ledger restart << SOElement (sfLastLedgerSequence, SOE_OPTIONAL) << SOElement (sfHashes, SOE_REQUIRED) ; - DECLARE_LEF (EnabledFeatures, ltFEATURES) + add ("EnabledFeatures", ltFEATURES) << SOElement (sfFeatures, SOE_REQUIRED) ; - DECLARE_LEF (FeeSettings, ltFEE_SETTINGS) + add ("FeeSettings", ltFEE_SETTINGS) << SOElement (sfBaseFee, SOE_REQUIRED) << SOElement (sfReferenceFeeUnits, SOE_REQUIRED) << SOElement (sfReserveBase, SOE_REQUIRED) @@ -117,34 +105,16 @@ void LEFInit () ; } -LedgerEntryFormat* LedgerEntryFormat::getLgrFormat (LedgerEntryType t) +LedgerFormats* LedgerFormats::createInstance () { - std::map::iterator it = byType.find (static_cast (t)); - - if (it == byType.end ()) - return NULL; - - return it->second; + return new LedgerFormats; } -LedgerEntryFormat* LedgerEntryFormat::getLgrFormat (int t) +void LedgerFormats::addCommonFields (Item& item) { - std::map::iterator it = byType.find ((t)); - - if (it == byType.end ()) - return NULL; - - return it->second; + item + << SOElement(sfLedgerIndex, SOE_OPTIONAL) + << SOElement(sfLedgerEntryType, SOE_REQUIRED) + << SOElement(sfFlags, SOE_REQUIRED) + ; } - -LedgerEntryFormat* LedgerEntryFormat::getLgrFormat (const std::string& t) -{ - std::map::iterator it = byName.find ((t)); - - if (it == byName.end ()) - return NULL; - - return it->second; -} - -// vim:ts=4 diff --git a/modules/ripple_data/protocol/ripple_LedgerFormat.h b/modules/ripple_data/protocol/ripple_LedgerFormats.h similarity index 76% rename from modules/ripple_data/protocol/ripple_LedgerFormat.h rename to modules/ripple_data/protocol/ripple_LedgerFormats.h index 7547c11795..29a223de1d 100644 --- a/modules/ripple_data/protocol/ripple_LedgerFormat.h +++ b/modules/ripple_data/protocol/ripple_LedgerFormats.h @@ -97,33 +97,23 @@ enum LedgerSpecificFlags lsfHighAuth = 0x00080000, }; -// VFALCO TODO See if we can merge LedgerEntryFormat with TxFormats -// -class LedgerEntryFormat +//------------------------------------------------------------------------------ + +/** Holds the list of known ledger entry formats. +*/ +class LedgerFormats + : public KnownFormats + , public SharedSingleton { +private: + LedgerFormats (); + public: - std::string t_name; - LedgerEntryType t_type; - SOTemplate elements; + static LedgerFormats* createInstance (); - static std::map byType; - static std::map byName; - - LedgerEntryFormat (const char* name, LedgerEntryType type) : t_name (name), t_type (type) - { - byName[name] = this; - byType[type] = this; - } - LedgerEntryFormat& operator<< (const SOElement& el) - { - elements.push_back (el); - return *this; - } - - static LedgerEntryFormat* getLgrFormat (LedgerEntryType t); - static LedgerEntryFormat* getLgrFormat (const std::string& t); - static LedgerEntryFormat* getLgrFormat (int t); +private: + void addCommonFields (Item& item); }; #endif -// vim:ts=4 + diff --git a/modules/ripple_data/protocol/ripple_SerializedObject.cpp b/modules/ripple_data/protocol/ripple_SerializedObject.cpp index 7581afb120..dada73dce5 100644 --- a/modules/ripple_data/protocol/ripple_SerializedObject.cpp +++ b/modules/ripple_data/protocol/ripple_SerializedObject.cpp @@ -1288,7 +1288,7 @@ UPTR_T STObject::parseJson (const Json::Value& object, SField::ref inN if (field == sfTransactionType) { // Retrieve type from name. Throws if not found. - TxType const txType = TxFormats::getInstance().findTypeByName (strValue); + TxType const txType = TxFormats::getInstance()->findTypeByName (strValue); data.push_back (new STUInt16 (field, static_cast (txType))); @@ -1297,12 +1297,9 @@ UPTR_T STObject::parseJson (const Json::Value& object, SField::ref inN } else if (field == sfLedgerEntryType) { - LedgerEntryFormat* f = LedgerEntryFormat::getLgrFormat (strValue); + LedgerEntryType const type = LedgerFormats::getInstance()->findTypeByName (strValue); - if (!f) - throw std::runtime_error ("Unknown ledger entry type"); - - data.push_back (new STUInt16 (field, static_cast (f->t_type))); + data.push_back (new STUInt16 (field, static_cast (type))); if (*name == sfGeneric) name = &sfLedgerEntry; diff --git a/modules/ripple_data/protocol/ripple_SerializedTypes.cpp b/modules/ripple_data/protocol/ripple_SerializedTypes.cpp index b60ac1908d..7d60b2791d 100644 --- a/modules/ripple_data/protocol/ripple_SerializedTypes.cpp +++ b/modules/ripple_data/protocol/ripple_SerializedTypes.cpp @@ -131,18 +131,20 @@ std::string STUInt16::getText () const { if (getFName () == sfLedgerEntryType) { - LedgerEntryFormat* f = LedgerEntryFormat::getLgrFormat (value); + LedgerFormats::Item const* const item = + LedgerFormats::getInstance ()->findByType (static_cast (value)); - if (f != NULL) - return f->t_name; + if (item != nullptr) + return item->getName (); } if (getFName () == sfTransactionType) { - TxFormats::Item const* f = TxFormats::getInstance().findByType (static_cast (value)); + TxFormats::Item const* const item = + TxFormats::getInstance()->findByType (static_cast (value)); - if (f != NULL) - return f->getName (); + if (item != nullptr) + return item->getName (); } return boost::lexical_cast (value); @@ -152,18 +154,20 @@ Json::Value STUInt16::getJson (int) const { if (getFName () == sfLedgerEntryType) { - LedgerEntryFormat* f = LedgerEntryFormat::getLgrFormat (value); + LedgerFormats::Item const* const item = + LedgerFormats::getInstance ()->findByType (static_cast (value)); - if (f != NULL) - return f->t_name; + if (item != nullptr) + return item->getName (); } if (getFName () == sfTransactionType) { - TxFormats::Item const* f = TxFormats::getInstance().findByType (static_cast (value)); + TxFormats::Item const* const item = + TxFormats::getInstance()->findByType (static_cast (value)); - if (f != NULL) - return f->getName (); + if (item != nullptr) + return item->getName (); } return value; diff --git a/modules/ripple_data/protocol/ripple_TxFormats.cpp b/modules/ripple_data/protocol/ripple_TxFormats.cpp index 692ac6dae5..865ca4fbda 100644 --- a/modules/ripple_data/protocol/ripple_TxFormats.cpp +++ b/modules/ripple_data/protocol/ripple_TxFormats.cpp @@ -4,48 +4,8 @@ */ //============================================================================== -TxFormats::Item::Item (char const* name, TxType type) - : m_name (name) - , m_type (type) -{ -} - -TxFormats::Item& TxFormats::Item::operator<< (SOElement const& el) -{ - elements.push_back (el); - - return *this; -} - -std::string const& TxFormats::Item::getName () const noexcept -{ - return m_name; -} - -TxType TxFormats::Item::getType () const noexcept -{ - return m_type; -} - -//------------------------------------------------------------------------------ - -void TxFormats::addCommonFields (Item& item) -{ - item - << SOElement(sfTransactionType, SOE_REQUIRED) - << SOElement(sfFlags, SOE_OPTIONAL) - << SOElement(sfSourceTag, SOE_OPTIONAL) - << SOElement(sfAccount, SOE_REQUIRED) - << SOElement(sfSequence, SOE_REQUIRED) - << SOElement(sfPreviousTxnID, SOE_OPTIONAL) - << SOElement(sfFee, SOE_REQUIRED) - << SOElement(sfOperationLimit, SOE_OPTIONAL) - << SOElement(sfSigningPubKey, SOE_REQUIRED) - << SOElement(sfTxnSignature, SOE_OPTIONAL) - ; -} - TxFormats::TxFormats () + : SharedSingleton (SingletonLifetime::persistAfterCreation) { add ("AccountSet", ttACCOUNT_SET) << SOElement (sfEmailHash, SOE_OPTIONAL) @@ -115,63 +75,23 @@ TxFormats::TxFormats () ; } -TxFormats const& TxFormats::getInstance () +void TxFormats::addCommonFields (Item& item) { - static TxFormats instance; - - return instance; + item + << SOElement(sfTransactionType, SOE_REQUIRED) + << SOElement(sfFlags, SOE_OPTIONAL) + << SOElement(sfSourceTag, SOE_OPTIONAL) + << SOElement(sfAccount, SOE_REQUIRED) + << SOElement(sfSequence, SOE_REQUIRED) + << SOElement(sfPreviousTxnID, SOE_OPTIONAL) + << SOElement(sfFee, SOE_REQUIRED) + << SOElement(sfOperationLimit, SOE_OPTIONAL) + << SOElement(sfSigningPubKey, SOE_REQUIRED) + << SOElement(sfTxnSignature, SOE_OPTIONAL) + ; } -TxType TxFormats::findTypeByName (std::string const name) const +TxFormats* TxFormats::createInstance () { - Item const* const result = findByName (name); - - if (result != nullptr) - { - return result->getType (); - } - else - { - throw std::runtime_error ("Unknown format name"); - } -} - -TxFormats::Item const* TxFormats::findByType (TxType type) const noexcept -{ - Item* result = nullptr; - - TypeMap::const_iterator const iter = m_types.find (type); - - if (iter != m_types.end ()) - { - result = iter->second; - } - - return result; -} - -TxFormats::Item const* TxFormats::findByName (std::string const& name) const noexcept -{ - Item* result = nullptr; - - NameMap::const_iterator const iter = m_names.find (name); - - if (iter != m_names.end ()) - { - result = iter->second; - } - - return result; -} - -TxFormats::Item& TxFormats::add (char const* name, TxType type) -{ - Item& item = *m_formats.add (new Item (name, type)); - - addCommonFields (item); - - m_types [item.getType ()] = &item; - m_names [item.getName ()] = &item; - - return item; + return new TxFormats; } diff --git a/modules/ripple_data/protocol/ripple_TxFormats.h b/modules/ripple_data/protocol/ripple_TxFormats.h index 42e1e42859..d6414ffd3a 100644 --- a/modules/ripple_data/protocol/ripple_TxFormats.h +++ b/modules/ripple_data/protocol/ripple_TxFormats.h @@ -38,34 +38,9 @@ enum TxType /** Manages the list of known transaction formats. */ class TxFormats + : public KnownFormats + , public SharedSingleton { -public: - /** A transaction format. - */ - class Item - { - public: - Item (char const* name, TxType type); - - Item& operator<< (SOElement const& el); - - /** Retrieve the name of the format. - */ - std::string const& getName () const noexcept; - - /** Retrieve the transaction type this format represents. - */ - TxType getType () const noexcept; - - public: - // VFALCO TODO make an accessor for this - SOTemplate elements; - - private: - std::string const m_name; - TxType const m_type; - }; - private: /** Create the object. @@ -73,50 +48,10 @@ private: */ TxFormats (); - static void addCommonFields (Item& item); + void addCommonFields (Item& item); public: - /** Retrieve the global instance. - */ - static TxFormats const& getInstance (); - - /** Retrieve the type for a transaction format specified by name. - - If the format name is unknown, an exception is thrown. - - @param name The name of the transaction type. - @return The transaction type. - */ - TxType findTypeByName (std::string const name) const; - - /** Retrieve a format based on its transaction type. - */ - Item const* findByType (TxType type) const noexcept; - - /** Retrieve a format based on its name. - */ - Item const* findByName (std::string const& name) const noexcept; - -protected: - /** Add a new format. - - The new format has the set of common fields already added. - - @param name The name of this format. - @param type The transaction type of this format. - - @return The created format. - */ - Item& add (char const* name, TxType type); - -private: - // VFALCO TODO use String instead of std::string - typedef std::map NameMap; - typedef std::map TypeMap; - - OwnedArray m_formats; - NameMap m_names; - TypeMap m_types; + static TxFormats* createInstance (); }; #endif diff --git a/modules/ripple_data/ripple_data.cpp b/modules/ripple_data/ripple_data.cpp index 72dcb022a8..12b2d5d5fb 100644 --- a/modules/ripple_data/ripple_data.cpp +++ b/modules/ripple_data/ripple_data.cpp @@ -71,7 +71,7 @@ namespace ripple #include "crypto/ripple_RFC1751.cpp" #include "protocol/ripple_FieldNames.cpp" -#include "protocol/ripple_LedgerFormat.cpp" +#include "protocol/ripple_LedgerFormats.cpp" #include "protocol/ripple_PackedMessage.cpp" #include "protocol/ripple_RippleAddress.cpp" #include "protocol/ripple_SerializedTypes.cpp" diff --git a/modules/ripple_data/ripple_data.h b/modules/ripple_data/ripple_data.h index f7119de17e..122663b2ca 100644 --- a/modules/ripple_data/ripple_data.h +++ b/modules/ripple_data/ripple_data.h @@ -47,10 +47,11 @@ namespace ripple #include "protocol/ripple_TER.h" #include "protocol/ripple_SerializedTypes.h" // needs Serializer, TER #include "protocol/ripple_SerializedObjectTemplate.h" + #include "protocol/ripple_KnownFormats.h" + #include "protocol/ripple_LedgerFormats.h" // needs SOTemplate from SerializedObjectTemplate + #include "protocol/ripple_TxFormats.h" #include "protocol/ripple_SerializedObject.h" -#include "protocol/ripple_LedgerFormat.h" // needs SOTemplate from SerializedObject #include "protocol/ripple_TxFlags.h" -#include "protocol/ripple_TxFormats.h" #include "utility/ripple_UptimeTimerAdapter.h" diff --git a/src/cpp/ripple/ripple_Main.cpp b/src/cpp/ripple/ripple_Main.cpp index 21c5d8b59e..484746e9b1 100644 --- a/src/cpp/ripple/ripple_Main.cpp +++ b/src/cpp/ripple/ripple_Main.cpp @@ -6,9 +6,6 @@ namespace po = boost::program_options; -// VFALCO TODO make these singletons that initialize statically -extern void LEFInit (); - void setupServer () { getApp().setup (); @@ -250,8 +247,6 @@ int rippleMain (int argc, char** argv) // VFALCO TODO make this a singleton that initializes statically // Or could make it a SharedSingleton // - LEFInit (); - if (vm.count ("unittest")) { boost::unit_test::unit_test_main (init_unit_test, argc, argv); diff --git a/src/cpp/ripple/ripple_SerializedLedger.cpp b/src/cpp/ripple/ripple_SerializedLedger.cpp index 3a19036c6d..61b0f7498b 100644 --- a/src/cpp/ripple/ripple_SerializedLedger.cpp +++ b/src/cpp/ripple/ripple_SerializedLedger.cpp @@ -13,14 +13,16 @@ SerializedLedgerEntry::SerializedLedgerEntry (SerializerIterator& sit, uint256 c { set (sit); uint16 type = getFieldU16 (sfLedgerEntryType); - mFormat = LedgerEntryFormat::getLgrFormat (static_cast (type)); - - if (mFormat == NULL) + + LedgerFormats::Item const* const item = + LedgerFormats::getInstance()->findByType (static_cast (type)); + + if (item == nullptr) throw std::runtime_error ("invalid ledger entry type"); - mType = mFormat->t_type; + mType = item->getType (); - if (!setType (mFormat->elements)) + if (!setType (item->elements)) throw std::runtime_error ("ledger entry not valid for type"); } @@ -31,16 +33,18 @@ SerializedLedgerEntry::SerializedLedgerEntry (const Serializer& s, uint256 const set (sit); uint16 type = getFieldU16 (sfLedgerEntryType); - mFormat = LedgerEntryFormat::getLgrFormat (static_cast (type)); - if (mFormat == NULL) + LedgerFormats::Item const* const item = + LedgerFormats::getInstance()->findByType (static_cast (type)); + + if (item == nullptr) throw std::runtime_error ("invalid ledger entry type"); - mType = mFormat->t_type; + mType = item->getType (); - if (!setType (mFormat->elements)) + if (!setType (item->elements)) { - WriteLog (lsWARNING, SerializedLedgerLog) << "Ledger entry not valid for type " << mFormat->t_name; + WriteLog (lsWARNING, SerializedLedgerLog) << "Ledger entry not valid for type " << mFormat->getName (); WriteLog (lsWARNING, SerializedLedgerLog) << getJson (0); throw std::runtime_error ("ledger entry not valid for type"); } @@ -49,12 +53,19 @@ SerializedLedgerEntry::SerializedLedgerEntry (const Serializer& s, uint256 const SerializedLedgerEntry::SerializedLedgerEntry (LedgerEntryType type, uint256 const& index) : STObject (sfLedgerEntry), mIndex (index), mType (type), mMutable (true) { - mFormat = LedgerEntryFormat::getLgrFormat (type); + LedgerFormats::Item const* const item = + LedgerFormats::getInstance()->findByType (type); - if (mFormat == NULL) throw std::runtime_error ("invalid ledger entry type"); + if (item != nullptr) + { + set (item->elements); - set (mFormat->elements); - setFieldU16 (sfLedgerEntryType, static_cast (mFormat->t_type)); + setFieldU16 (sfLedgerEntryType, static_cast (item->getType ())); + } + else + { + throw std::runtime_error ("invalid ledger entry type"); + } } SerializedLedgerEntry::pointer SerializedLedgerEntry::getMutable () const @@ -69,7 +80,7 @@ std::string SerializedLedgerEntry::getFullText () const std::string ret = "\""; ret += mIndex.GetHex (); ret += "\" = { "; - ret += mFormat->t_name; + ret += mFormat->getName (); ret += ", "; ret += STObject::getFullText (); ret += "}"; diff --git a/src/cpp/ripple/ripple_SerializedLedger.h b/src/cpp/ripple/ripple_SerializedLedger.h index c92c3a403f..0a7e75d172 100644 --- a/src/cpp/ripple/ripple_SerializedLedger.h +++ b/src/cpp/ripple/ripple_SerializedLedger.h @@ -72,7 +72,7 @@ public: { return getFieldU16 (sfLedgerEntryType); } - const LedgerEntryFormat* getFormat () + LedgerFormats::Item const* getFormat () { return mFormat; } @@ -98,7 +98,7 @@ private: private: uint256 mIndex; LedgerEntryType mType; - const LedgerEntryFormat* mFormat; + LedgerFormats::Item const* mFormat; bool mMutable; }; diff --git a/src/cpp/ripple/ripple_SerializedTransaction.cpp b/src/cpp/ripple/ripple_SerializedTransaction.cpp index d93e8854cc..45ba2ffb46 100644 --- a/src/cpp/ripple/ripple_SerializedTransaction.cpp +++ b/src/cpp/ripple/ripple_SerializedTransaction.cpp @@ -12,7 +12,7 @@ SerializedTransaction::SerializedTransaction (TxType type) , mSigGood (false) , mSigBad (false) { - mFormat = TxFormats::getInstance().findByType (type); + mFormat = TxFormats::getInstance()->findByType (type); if (mFormat == nullptr) { @@ -31,7 +31,7 @@ SerializedTransaction::SerializedTransaction (STObject const& object) { mType = static_cast (getFieldU16 (sfTransactionType)); - mFormat = TxFormats::getInstance().findByType (mType); + mFormat = TxFormats::getInstance()->findByType (mType); if (!mFormat) { @@ -59,7 +59,7 @@ SerializedTransaction::SerializedTransaction (SerializerIterator& sit) : STObjec set (sit); mType = static_cast (getFieldU16 (sfTransactionType)); - mFormat = TxFormats::getInstance().findByType (mType); + mFormat = TxFormats::getInstance()->findByType (mType); if (!mFormat) {