Refactor STObject, STLedgerEntry:

* Normalize names
* Remove unused and deprecated members
This commit is contained in:
Nik Bougalis
2016-09-04 01:16:17 -07:00
parent 5be33a650d
commit 9a988963e9
15 changed files with 62 additions and 154 deletions

View File

@@ -346,7 +346,7 @@ Ledger::setAccepted(NetClock::time_point closeTime,
bool Ledger::addSLE (SLE const& sle)
{
SHAMapItem item (sle.getIndex(), sle.getSerializer());
SHAMapItem item (sle.key(), sle.getSerializer());
return stateMap_->addItem(std::move(item), false, false);
}
@@ -421,8 +421,6 @@ Ledger::read (Keylet const& k) const
item->size()}, item->key());
if (! k.check(*sle))
return nullptr;
// VFALCO TODO Eliminate "immutable" runtime property
sle->setImmutable();
// need move otherwise makes a copy
// because return type is different
return std::move(sle);
@@ -632,8 +630,6 @@ Ledger::peek (Keylet const& k) const
SerialIter{value->data(), value->size()}, value->key());
if (! k.check(*sle))
return nullptr;
// VFALCO TODO Eliminate "immutable" runtime property
sle->setImmutable();
return sle;
}

View File

@@ -103,7 +103,7 @@ void OrderBookDB::update(
{
if (sle->getType () == ltDIR_NODE &&
sle->isFieldPresent (sfExchangeRate) &&
sle->getFieldH256 (sfRootIndex) == sle->getIndex())
sle->getFieldH256 (sfRootIndex) == sle->key())
{
Book book;
book.in.currency.copyFrom(sle->getFieldH160(

View File

@@ -2901,7 +2901,7 @@ void NetworkOPsImp::getBookPage (
}
else
{
uTipIndex = sleOfferDir->getIndex ();
uTipIndex = sleOfferDir->key();
saDirRate = amountFromQuality (getQuality (uTipIndex));
cdirFirst (view,

View File

@@ -59,7 +59,7 @@ public:
uint256
key() const
{
return sle_->getIndex();
return sle_->key();
}
// VFALCO Take off the "get" from each function name

View File

@@ -105,10 +105,10 @@ CreateTicket::doApply ()
auto viewJ = ctx_.app.journal ("View");
auto result = dirAdd(view(), hint, keylet::ownerDir (account_),
sleTicket->getIndex (), describeOwnerDir (account_), viewJ);
sleTicket->key(), describeOwnerDir (account_), viewJ);
JLOG(j_.trace()) <<
"Creating ticket " << to_string (sleTicket->getIndex ()) <<
"Creating ticket " << to_string (sleTicket->key()) <<
": " << transHuman (result.first);
if (result.first == tesSUCCESS)

View File

@@ -120,7 +120,7 @@ public:
std::string id () const
{
return to_string (m_entry->getIndex());
return to_string (m_entry->key());
}
Issue issueIn () const;

View File

@@ -152,7 +152,7 @@ TOfferStreamBase<TIn, TOut>::step ()
tp{d{(*entry)[sfExpiration]}} <= expire_)
{
JLOG(j_.trace()) <<
"Removing expired offer " << entry->getIndex();
"Removing expired offer " << entry->key();
permRmOffer (entry);
continue;
}
@@ -165,7 +165,7 @@ TOfferStreamBase<TIn, TOut>::step ()
if (amount.empty())
{
JLOG(j_.warn()) <<
"Removing bad offer " << entry->getIndex();
"Removing bad offer " << entry->key();
permRmOffer (entry);
offer_ = TOffer<TIn, TOut>{};
continue;
@@ -189,12 +189,12 @@ TOfferStreamBase<TIn, TOut>::step ()
{
permRmOffer (entry);
JLOG(j_.trace()) <<
"Removing unfunded offer " << entry->getIndex();
"Removing unfunded offer " << entry->key();
}
else
{
JLOG(j_.trace()) <<
"Removing became unfunded offer " << entry->getIndex();
"Removing became unfunded offer " << entry->key();
}
offer_ = TOffer<TIn, TOut>{};
continue;

View File

@@ -170,7 +170,7 @@ TxMeta::getAffectedAccounts() const
STObject& TxMeta::getAffectedNode (SLE::ref node, SField const& type)
{
uint256 index = node->getIndex ();
uint256 index = node->key();
for (auto& n : mNodes)
{
if (n.getFieldH256 (sfLedgerIndex) == index)

View File

@@ -1061,14 +1061,14 @@ trustCreate (ApplyView& view,
std::tie (terResult, std::ignore) = dirAdd (view,
uLowNode, keylet::ownerDir (uLowAccountID),
sleRippleState->getIndex (),
sleRippleState->key(),
describeOwnerDir (uLowAccountID), j);
if (tesSUCCESS == terResult)
{
std::tie (terResult, std::ignore) = dirAdd (view,
uHighNode, keylet::ownerDir (uHighAccountID),
sleRippleState->getIndex (),
sleRippleState->key(),
describeOwnerDir (uHighAccountID), j);
}
@@ -1156,7 +1156,7 @@ trustDelete (ApplyView& view,
false,
uLowNode,
getOwnerDirIndex (uLowAccountID),
sleRippleState->getIndex (),
sleRippleState->key(),
false,
!bLowNode,
j);
@@ -1169,7 +1169,7 @@ trustDelete (ApplyView& view,
false,
uHighNode,
getOwnerDirIndex (uHighAccountID),
sleRippleState->getIndex (),
sleRippleState->key(),
false,
!bHighNode,
j);
@@ -1188,7 +1188,7 @@ offerDelete (ApplyView& view,
{
if (! sle)
return tesSUCCESS;
auto offerIndex = sle->getIndex ();
auto offerIndex = sle->key();
auto owner = sle->getAccountID (sfAccount);
// Detect legacy directories.

View File

@@ -45,14 +45,11 @@ public:
{
}
STLedgerEntry (const Serializer & s, uint256 const& index);
STLedgerEntry (SerialIter & sit, uint256 const& index);
STLedgerEntry(SerialIter&& sit, uint256 const& index)
: STLedgerEntry(sit, index) {}
STLedgerEntry (const STObject & object, uint256 const& index);
STLedgerEntry (STObject const& object, uint256 const& index);
STBase*
copy (std::size_t n, void* buf) const override
@@ -87,42 +84,19 @@ public:
return key_;
}
// DEPRECATED
uint256 const& getIndex () const
{
return key_;
}
void setImmutable ()
{
mMutable = false;
}
bool isMutable ()
{
return mMutable;
}
LedgerEntryType getType () const
{
return type_;
}
std::uint16_t getVersion () const
{
return getFieldU16 (sfLedgerEntryType);
}
// is this a ledger entry that can be threaded
bool isThreadedType() const;
bool isThreadedType() const; // is this a ledger entry that can be threaded
bool isThreaded () const; // is this ledger entry actually threaded
uint256 getThreadedTransaction () const;
std::uint32_t getThreadedLedger () const;
bool thread (uint256 const& txID, std::uint32_t ledgerSeq, uint256 & prevTxID,
std::uint32_t & prevLedgerID);
bool thread (
uint256 const& txID,
std::uint32_t ledgerSeq,
uint256 & prevTxID,
std::uint32_t & prevLedgerID);
private:
/* Make STObject comply with the template for this SLE type
@@ -133,8 +107,6 @@ private:
private:
uint256 key_;
LedgerEntryType type_;
LedgerFormats::Item const* mFormat;
bool mMutable;
};
using SLE = STLedgerEntry;

View File

@@ -330,8 +330,6 @@ public:
ResultOfSetTypeFromSField setTypeFromSField (SField const&);
bool isValidForType ();
bool isFieldAllowed (SField const&);
bool isFree () const
{
return mType == nullptr;
@@ -424,7 +422,6 @@ public:
// these throw if the field type doesn't match, or return default values
// if the field is optional but not present
std::string getFieldString (SField const& field) const;
unsigned char getFieldU8 (SField const& field) const;
std::uint16_t getFieldU16 (SField const& field) const;
std::uint32_t getFieldU32 (SField const& field) const;
@@ -440,7 +437,6 @@ public:
STPathSet const& getFieldPathSet (SField const& field) const;
const STVector256& getFieldV256 (SField const& field) const;
const STArray& getFieldArray (SField const& field) const;
const STObject& getFieldObject (SField const& field) const;
/** Return the value of a field.
@@ -499,10 +495,8 @@ public:
void setAccountID (SField const& field, AccountID const&);
void setFieldAmount (SField const& field, STAmount const&);
void setFieldPathSet (SField const& field, STPathSet const&);
void setFieldV256 (SField const& field, STVector256 const& v);
void setFieldArray (SField const& field, STArray const& v);
void setFieldObject (SField const& field, STObject const& v);
template <class Tag>
void setFieldH160 (SField const& field, base_uint<160, Tag> const& v)

View File

@@ -32,55 +32,54 @@ STLedgerEntry::STLedgerEntry (Keylet const& k)
: STObject(sfLedgerEntry)
, key_ (k.key)
, type_ (k.type)
, mMutable (true)
{
mFormat =
auto const format =
LedgerFormats::getInstance().findByType (type_);
if (mFormat == nullptr)
if (format == nullptr)
Throw<std::runtime_error> ("invalid ledger entry type");
set (mFormat->elements);
set (format->elements);
setFieldU16 (sfLedgerEntryType,
static_cast <std::uint16_t> (mFormat->getType ()));
static_cast <std::uint16_t> (type_));
}
STLedgerEntry::STLedgerEntry (
SerialIter& sit, uint256 const& index)
: STObject (sfLedgerEntry), key_ (index), mMutable (true)
SerialIter& sit,
uint256 const& index)
: STObject (sfLedgerEntry)
, key_ (index)
{
set (sit);
setSLEType ();
}
STLedgerEntry::STLedgerEntry (
const Serializer& s, uint256 const& index)
: STObject (sfLedgerEntry), key_ (index), mMutable (true)
{
SerialIter sit (s.slice());
set (sit);
setSLEType ();
}
STLedgerEntry::STLedgerEntry (
const STObject & object, uint256 const& index)
: STObject (object), key_(index), mMutable (true)
STObject const& object,
uint256 const& index)
: STObject (object)
, key_ (index)
{
setSLEType ();
}
void STLedgerEntry::setSLEType ()
{
mFormat = LedgerFormats::getInstance().findByType (
static_cast <LedgerEntryType> (getFieldU16 (sfLedgerEntryType)));
auto format = LedgerFormats::getInstance().findByType (
static_cast <LedgerEntryType> (
getFieldU16 (sfLedgerEntryType)));
if (mFormat == nullptr)
if (format == nullptr)
Throw<std::runtime_error> ("invalid ledger entry type");
type_ = mFormat->getType ();
if (!setType (mFormat->elements))
type_ = format->getType ();
if (!setType (format->elements))
{
if (auto j = debugLog().error())
{
j << "Ledger entry not valid for type " << mFormat->getName ();
j << "Ledger entry not valid for type " << format->getName ();
j << "Object: " << getJson (0);
}
@@ -90,10 +89,16 @@ void STLedgerEntry::setSLEType ()
std::string STLedgerEntry::getFullText () const
{
auto const format =
LedgerFormats::getInstance().findByType (type_);
if (format == nullptr)
Throw<std::runtime_error> ("invalid ledger entry type");
std::string ret = "\"";
ret += to_string (key_);
ret += "\" = { ";
ret += mFormat->getName ();
ret += format->getName ();
ret += ", ";
ret += STObject::getFullText ();
ret += "}";
@@ -121,23 +126,11 @@ bool STLedgerEntry::isThreadedType () const
return getFieldIndex (sfPreviousTxnID) != -1;
}
bool STLedgerEntry::isThreaded () const
{
return isFieldPresent (sfPreviousTxnID);
}
uint256 STLedgerEntry::getThreadedTransaction () const
{
return getFieldH256 (sfPreviousTxnID);
}
std::uint32_t STLedgerEntry::getThreadedLedger () const
{
return getFieldU32 (sfPreviousTxnLgrSeq);
}
bool STLedgerEntry::thread (uint256 const& txID, std::uint32_t ledgerSeq,
uint256& prevTxID, std::uint32_t& prevLedgerID)
bool STLedgerEntry::thread (
uint256 const& txID,
std::uint32_t ledgerSeq,
uint256& prevTxID,
std::uint32_t& prevLedgerID)
{
uint256 oldPrevTxID = getFieldH256 (sfPreviousTxnID);

View File

@@ -164,28 +164,6 @@ STObject::setTypeFromSField (SField const& sField)
return ret;
}
bool STObject::isValidForType ()
{
auto it = v_.begin();
for (auto const& elem : mType->all())
{
if (it == v_.end())
return false;
if (elem->e_field != it->get().getFName())
return false;
++it;
}
return true;
}
bool STObject::isFieldAllowed (SField const& field)
{
if (mType == nullptr)
return true;
return mType->getIndex (field) != -1;
}
// return true = terminated with end-of-object
bool STObject::set (SerialIter& sit, int depth)
{
@@ -504,15 +482,6 @@ void STObject::delField (int index)
v_.erase (v_.begin () + index);
}
std::string STObject::getFieldString (SField const& field) const
{
const STBase* rf = peekAtPField (field);
if (! rf) Throw<std::runtime_error> ("Field not found");
return rf->getText ();
}
unsigned char STObject::getFieldU8 (SField const& field) const
{
return getFieldByValue <STUInt8> (field);
@@ -584,12 +553,6 @@ const STArray& STObject::getFieldArray (SField const& field) const
return getFieldByConstRef <STArray> (field, empty);
}
const STObject& STObject::getFieldObject (SField const& field) const
{
static STObject const empty{sfInvalid};
return getFieldByConstRef <STObject> (field, empty);
}
void
STObject::set (std::unique_ptr<STBase> v)
{
@@ -664,21 +627,11 @@ void STObject::setFieldAmount (SField const& field, STAmount const& v)
setFieldUsingAssignment (field, v);
}
void STObject::setFieldPathSet (SField const& field, STPathSet const& v)
{
setFieldUsingAssignment (field, v);
}
void STObject::setFieldArray (SField const& field, STArray const& v)
{
setFieldUsingAssignment (field, v);
}
void STObject::setFieldObject (SField const& field, STObject const& v)
{
setFieldUsingAssignment (field, v);
}
Json::Value STObject::getJson (int options) const
{
Json::Value ret (Json::objectValue);

View File

@@ -167,7 +167,7 @@ Json::Value doAccountChannels (RPC::Context& context)
{
result[jss::limit] = limit;
result[jss::marker] = to_string (visitData.items.back()->getIndex());
result[jss::marker] = to_string (visitData.items.back()->key());
visitData.items.pop_back ();
}

View File

@@ -141,7 +141,7 @@ Json::Value doAccountOffers (RPC::Context& context)
{
result[jss::limit] = limit;
result[jss::marker] = to_string (offers.back ()->getIndex ());
result[jss::marker] = to_string (offers.back ()->key ());
offers.pop_back ();
}