mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 07:25:51 +00:00
Refactor TxFormats and LedgerEntryFormat to use a common template.
This commit is contained in:
@@ -234,7 +234,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_LedgerFormat.cpp">
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_LedgerFormats.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
@@ -1352,8 +1352,9 @@
|
||||
<ClInclude Include="..\..\modules\ripple_data\crypto\ripple_RFC1751.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_FieldNames.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_HashPrefix.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_LedgerFormat.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_LedgerFormats.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_PackedMessage.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_KnownFormats.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_Protocol.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_RippleAddress.h" />
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_RippleSystem.h" />
|
||||
|
||||
@@ -264,9 +264,6 @@
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_FieldNames.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_LedgerFormat.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_PackedMessage.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
@@ -825,6 +822,9 @@
|
||||
<ClCompile Include="..\..\modules\ripple_basics\utility\ripple_LogFile.cpp">
|
||||
<Filter>[1] Ripple\ripple_basics\utility</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\ripple_data\protocol\ripple_LedgerFormats.cpp">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\Subtrees\sqlite\sqlite3.h">
|
||||
@@ -957,9 +957,6 @@
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_HashPrefix.h">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_LedgerFormat.h">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_PackedMessage.h">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClInclude>
|
||||
@@ -1539,6 +1536,12 @@
|
||||
<ClInclude Include="..\..\modules\ripple_basics\utility\ripple_LogFile.h">
|
||||
<Filter>[1] Ripple\ripple_basics\utility</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_KnownFormats.h">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\ripple_data\protocol\ripple_LedgerFormats.h">
|
||||
<Filter>[1] Ripple\ripple_data\protocol</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="..\..\src\cpp\ripple\ripple.proto" />
|
||||
|
||||
12
TODO.txt
12
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.
|
||||
|
||||
171
modules/ripple_data/protocol/ripple_KnownFormats.h
Normal file
171
modules/ripple_data/protocol/ripple_KnownFormats.h
Normal file
@@ -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 KeyType>
|
||||
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 <std::string, Item*> NameMap;
|
||||
typedef std::map <KeyType, Item*> TypeMap;
|
||||
|
||||
OwnedArray <Item> m_formats;
|
||||
NameMap m_names;
|
||||
TypeMap m_types;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -4,22 +4,10 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
std::map <int, LedgerEntryFormat*> LedgerEntryFormat::byType;
|
||||
|
||||
std::map <std::string, LedgerEntryFormat*> 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 <LedgerFormats> (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<int, LedgerEntryFormat*>::iterator it = byType.find (static_cast<int> (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<int, LedgerEntryFormat*>::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<std::string, LedgerEntryFormat*>::iterator it = byName.find ((t));
|
||||
|
||||
if (it == byName.end ())
|
||||
return NULL;
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
@@ -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 <LedgerEntryType>
|
||||
, public SharedSingleton <LedgerFormats>
|
||||
{
|
||||
private:
|
||||
LedgerFormats ();
|
||||
|
||||
public:
|
||||
std::string t_name;
|
||||
LedgerEntryType t_type;
|
||||
SOTemplate elements;
|
||||
static LedgerFormats* createInstance ();
|
||||
|
||||
static std::map<int, LedgerEntryFormat*> byType;
|
||||
static std::map<std::string, LedgerEntryFormat*> 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
|
||||
|
||||
@@ -1288,7 +1288,7 @@ UPTR_T<STObject> 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<uint16> (txType)));
|
||||
|
||||
@@ -1297,12 +1297,9 @@ UPTR_T<STObject> 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<uint16> (f->t_type)));
|
||||
data.push_back (new STUInt16 (field, static_cast<uint16> (type)));
|
||||
|
||||
if (*name == sfGeneric)
|
||||
name = &sfLedgerEntry;
|
||||
|
||||
@@ -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 <LedgerEntryType> (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 <TxType> (value));
|
||||
TxFormats::Item const* const item =
|
||||
TxFormats::getInstance()->findByType (static_cast <TxType> (value));
|
||||
|
||||
if (f != NULL)
|
||||
return f->getName ();
|
||||
if (item != nullptr)
|
||||
return item->getName ();
|
||||
}
|
||||
|
||||
return boost::lexical_cast<std::string> (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 <LedgerEntryType> (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 <TxType> (value));
|
||||
TxFormats::Item const* const item =
|
||||
TxFormats::getInstance()->findByType (static_cast <TxType> (value));
|
||||
|
||||
if (f != NULL)
|
||||
return f->getName ();
|
||||
if (item != nullptr)
|
||||
return item->getName ();
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@@ -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 <TxFormats> (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;
|
||||
}
|
||||
|
||||
@@ -38,34 +38,9 @@ enum TxType
|
||||
/** Manages the list of known transaction formats.
|
||||
*/
|
||||
class TxFormats
|
||||
: public KnownFormats <TxType>
|
||||
, public SharedSingleton <TxFormats>
|
||||
{
|
||||
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 <std::string, Item*> NameMap;
|
||||
typedef std::map <TxType, Item*> TypeMap;
|
||||
|
||||
OwnedArray <Item> m_formats;
|
||||
NameMap m_names;
|
||||
TypeMap m_types;
|
||||
static TxFormats* createInstance ();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -13,14 +13,16 @@ SerializedLedgerEntry::SerializedLedgerEntry (SerializerIterator& sit, uint256 c
|
||||
{
|
||||
set (sit);
|
||||
uint16 type = getFieldU16 (sfLedgerEntryType);
|
||||
mFormat = LedgerEntryFormat::getLgrFormat (static_cast<LedgerEntryType> (type));
|
||||
|
||||
if (mFormat == NULL)
|
||||
LedgerFormats::Item const* const item =
|
||||
LedgerFormats::getInstance()->findByType (static_cast <LedgerEntryType> (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<LedgerEntryType> (type));
|
||||
|
||||
if (mFormat == NULL)
|
||||
LedgerFormats::Item const* const item =
|
||||
LedgerFormats::getInstance()->findByType (static_cast <LedgerEntryType> (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<uint16> (mFormat->t_type));
|
||||
setFieldU16 (sfLedgerEntryType, static_cast <uint16> (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 += "}";
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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 <TxType> (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<TxType> (getFieldU16 (sfTransactionType));
|
||||
|
||||
mFormat = TxFormats::getInstance().findByType (mType);
|
||||
mFormat = TxFormats::getInstance()->findByType (mType);
|
||||
|
||||
if (!mFormat)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user