mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 06:25:51 +00:00
Refactor TxFormats and LedgerEntryFormat to use a common template.
This commit is contained in:
@@ -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