Refactor Ledger and support classes:

This performs a deep refactor on the Ledger class and its supporting
classes, in preparation for the move to shared_ptr<SLE const> in
places where the SLE is immutable and we are currently using
shared_ptr<SLE>.

Member functions are converted to free functions, the SLECache is an
explicit parameter, one line convenience functions are removed to
streamline the interface. Some callers are changed to use <SLE const>
instead of <SLE>

SLECache:
* Moved to its own header file

RippleState:
* Remove unused functions
* Store the SLE as const
* Simplify callers

AccountState:
* Remove unused members
* Simplify existing members

Ledger:
* Replace writeBack with insert and update
* Remove unused functions
* Remove LedgerStateParams
* Move getLastFullLedger to Application
* add entryCacheI, exists, fetch, erase
* Use boost::optional where it makes sense
* Make member functions free functions

Free functions:
* fetch: cache-aware SLE retrieval
* forEachItem, forEachItemAfter
* (various)
This commit is contained in:
Vinnie Falco
2015-06-05 07:25:45 -07:00
parent 454d2f8c45
commit babaac9305
45 changed files with 1224 additions and 1129 deletions

View File

@@ -61,6 +61,10 @@ public:
std::string getText () const override;
Json::Value getJson (int options) const override;
/** Returns the 'key' (or 'index') of this item.
The key identifies this entry's position in
the SHAMap associative container.
*/
uint256 const& getIndex () const
{
return mIndex;
@@ -93,15 +97,15 @@ public:
return mFormat;
}
bool isThreadedType (); // is this a ledger entry that can be threaded
bool isThreaded (); // is this ledger entry actually threaded
bool hasOneOwner (); // This node has one other node that owns it
bool hasTwoOwners (); // This node has two nodes that own it (like ripple balance)
RippleAddress getOwner ();
RippleAddress getFirstOwner ();
RippleAddress getSecondOwner ();
uint256 getThreadedTransaction ();
std::uint32_t getThreadedLedger ();
bool isThreadedType() const; // is this a ledger entry that can be threaded
bool isThreaded () const; // is this ledger entry actually threaded
bool hasOneOwner () const; // This node has one other node that owns it
bool hasTwoOwners () const; // This node has two nodes that own it (like ripple balance)
RippleAddress getOwner () const;
RippleAddress getFirstOwner () const;
RippleAddress getSecondOwner () const;
uint256 getThreadedTransaction () const;
std::uint32_t getThreadedLedger () const;
bool thread (uint256 const& txID, std::uint32_t ledgerSeq, uint256 & prevTxID,
std::uint32_t & prevLedgerID);

View File

@@ -118,22 +118,47 @@ Json::Value STLedgerEntry::getJson (int options) const
return ret;
}
bool STLedgerEntry::isThreadedType ()
bool STLedgerEntry::isThreadedType () const
{
return getFieldIndex (sfPreviousTxnID) != -1;
}
bool STLedgerEntry::isThreaded ()
bool STLedgerEntry::isThreaded () const
{
return isFieldPresent (sfPreviousTxnID);
}
uint256 STLedgerEntry::getThreadedTransaction ()
bool STLedgerEntry::hasOneOwner () const
{
return (mType != ltACCOUNT_ROOT) && (getFieldIndex (sfAccount) != -1);
}
bool STLedgerEntry::hasTwoOwners () const
{
return mType == ltRIPPLE_STATE;
}
RippleAddress STLedgerEntry::getOwner () const
{
return getFieldAccount (sfAccount);
}
RippleAddress STLedgerEntry::getFirstOwner () const
{
return RippleAddress::createAccountID (getFieldAmount (sfLowLimit).getIssuer ());
}
RippleAddress STLedgerEntry::getSecondOwner () const
{
return RippleAddress::createAccountID (getFieldAmount (sfHighLimit).getIssuer ());
}
uint256 STLedgerEntry::getThreadedTransaction () const
{
return getFieldH256 (sfPreviousTxnID);
}
std::uint32_t STLedgerEntry::getThreadedLedger ()
std::uint32_t STLedgerEntry::getThreadedLedger () const
{
return getFieldU32 (sfPreviousTxnLgrSeq);
}
@@ -158,29 +183,4 @@ bool STLedgerEntry::thread (uint256 const& txID, std::uint32_t ledgerSeq,
return true;
}
bool STLedgerEntry::hasOneOwner ()
{
return (mType != ltACCOUNT_ROOT) && (getFieldIndex (sfAccount) != -1);
}
bool STLedgerEntry::hasTwoOwners ()
{
return mType == ltRIPPLE_STATE;
}
RippleAddress STLedgerEntry::getOwner ()
{
return getFieldAccount (sfAccount);
}
RippleAddress STLedgerEntry::getFirstOwner ()
{
return RippleAddress::createAccountID (getFieldAmount (sfLowLimit).getIssuer ());
}
RippleAddress STLedgerEntry::getSecondOwner ()
{
return RippleAddress::createAccountID (getFieldAmount (sfHighLimit).getIssuer ());
}
} // ripple