mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
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:
@@ -29,25 +29,11 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
AccountState::AccountState (RippleAddress const& naAccountID)
|
||||
: mAccountID (naAccountID)
|
||||
, mValid (false)
|
||||
AccountState::AccountState (std::shared_ptr<SLE const> sle,
|
||||
RippleAddress const& naAccountID)
|
||||
: mLedgerEntry (sle)
|
||||
{
|
||||
if (naAccountID.isValid ())
|
||||
{
|
||||
mValid = true;
|
||||
|
||||
mLedgerEntry = std::make_shared <STLedgerEntry> (
|
||||
ltACCOUNT_ROOT, getAccountRootIndex (naAccountID));
|
||||
|
||||
mLedgerEntry->setFieldAccount (sfAccount, naAccountID.getAccountID ());
|
||||
}
|
||||
}
|
||||
|
||||
AccountState::AccountState (SLE::ref ledgerEntry, RippleAddress const& naAccountID) :
|
||||
mAccountID (naAccountID), mLedgerEntry (ledgerEntry), mValid (false)
|
||||
{
|
||||
if (!mLedgerEntry)
|
||||
if (! mLedgerEntry)
|
||||
return;
|
||||
|
||||
if (mLedgerEntry->getType () != ltACCOUNT_ROOT)
|
||||
@@ -84,11 +70,4 @@ void AccountState::addJson (Json::Value& val)
|
||||
}
|
||||
}
|
||||
|
||||
void AccountState::dump ()
|
||||
{
|
||||
Json::Value j (Json::objectValue);
|
||||
addJson (j);
|
||||
WriteLog (lsINFO, Ledger) << j;
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -28,70 +28,35 @@
|
||||
namespace ripple {
|
||||
|
||||
//
|
||||
// Provide abstract access to an account's state, such that access to the serialized format is hidden.
|
||||
// Provide abstract access to an account's state, such that
|
||||
// access to the serialized format is hidden.
|
||||
//
|
||||
|
||||
// VFALCO TODO Remove this class, its redundant and hardly used
|
||||
class AccountState
|
||||
{
|
||||
public:
|
||||
// VFALCO TODO Figure out if we need this to be shared
|
||||
using pointer = std::shared_ptr<AccountState>;
|
||||
|
||||
public:
|
||||
// For new accounts
|
||||
explicit AccountState (RippleAddress const& naAccountID);
|
||||
|
||||
// For accounts in a ledger
|
||||
AccountState (SLE::ref ledgerEntry, RippleAddress const& naAccountI);
|
||||
AccountState (std::shared_ptr<SLE const> sle,
|
||||
RippleAddress const& naAccountI);
|
||||
|
||||
bool haveAuthorizedKey ()
|
||||
{
|
||||
return mLedgerEntry->isFieldPresent (sfRegularKey);
|
||||
}
|
||||
|
||||
RippleAddress getAuthorizedKey ()
|
||||
{
|
||||
return mLedgerEntry->getFieldAccount (sfRegularKey);
|
||||
}
|
||||
|
||||
STAmount getBalance () const
|
||||
{
|
||||
return mLedgerEntry->getFieldAmount (sfBalance);
|
||||
}
|
||||
|
||||
std::uint32_t getSeq () const
|
||||
{
|
||||
return mLedgerEntry->getFieldU32 (sfSequence);
|
||||
}
|
||||
|
||||
STLedgerEntry::pointer getSLE ()
|
||||
{
|
||||
return mLedgerEntry;
|
||||
}
|
||||
|
||||
STLedgerEntry const& peekSLE () const
|
||||
SLE const&
|
||||
sle() const
|
||||
{
|
||||
return *mLedgerEntry;
|
||||
}
|
||||
|
||||
STLedgerEntry& peekSLE ()
|
||||
{
|
||||
return *mLedgerEntry;
|
||||
}
|
||||
|
||||
Blob getRaw () const;
|
||||
|
||||
void addJson (Json::Value& value);
|
||||
|
||||
void dump ();
|
||||
|
||||
private:
|
||||
// VFALCO TODO Remove this
|
||||
static std::string createGravatarUrl (uint128 uEmailHash);
|
||||
|
||||
private:
|
||||
RippleAddress const mAccountID;
|
||||
RippleAddress mAuthorizedKey;
|
||||
STLedgerEntry::pointer mLedgerEntry;
|
||||
|
||||
bool mValid;
|
||||
bool mValid = false;
|
||||
std::shared_ptr<SLE const> mLedgerEntry;
|
||||
};
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -245,13 +245,6 @@ public:
|
||||
std::uint32_t startLedgerSeq, std::uint32_t endLedgerSeq,
|
||||
int maxTransactions) override;
|
||||
|
||||
//
|
||||
// Account functions.
|
||||
//
|
||||
|
||||
AccountState::pointer getAccountState (
|
||||
Ledger::ref lrLedger, RippleAddress const& accountID) override;
|
||||
|
||||
//
|
||||
// Directory functions.
|
||||
//
|
||||
@@ -1082,16 +1075,6 @@ int NetworkOPsImp::findTransactionsByDestination (
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Account functions
|
||||
//
|
||||
|
||||
AccountState::pointer NetworkOPsImp::getAccountState (
|
||||
Ledger::ref lrLedger, RippleAddress const& accountID)
|
||||
{
|
||||
return lrLedger->getAccountState (accountID);
|
||||
}
|
||||
|
||||
//
|
||||
// Directory functions
|
||||
//
|
||||
@@ -1104,7 +1087,8 @@ STVector256 NetworkOPsImp::getDirNodeInfo (
|
||||
std::uint64_t& uNodeNext)
|
||||
{
|
||||
STVector256 svIndexes;
|
||||
SLE::pointer sleNode = lrLedger->getDirNode (uNodeIndex);
|
||||
auto const sleNode = fetch(*lrLedger, uNodeIndex,
|
||||
getApp().getSLECache(), ltDIR_NODE);
|
||||
|
||||
if (sleNode)
|
||||
{
|
||||
@@ -1149,8 +1133,8 @@ Json::Value NetworkOPsImp::getOwnerInfo (
|
||||
{
|
||||
Json::Value jvObjects (Json::objectValue);
|
||||
auto uRootIndex = getOwnerDirIndex (naAccount.getAccountID ());
|
||||
auto sleNode = lpLedger->getDirNode (uRootIndex);
|
||||
|
||||
auto sleNode = fetch(*lpLedger, uRootIndex,
|
||||
getApp().getSLECache(), ltDIR_NODE);
|
||||
if (sleNode)
|
||||
{
|
||||
std::uint64_t uNodeDir;
|
||||
@@ -1159,7 +1143,8 @@ Json::Value NetworkOPsImp::getOwnerInfo (
|
||||
{
|
||||
for (auto const& uDirEntry : sleNode->getFieldV256 (sfIndexes))
|
||||
{
|
||||
auto sleCur = lpLedger->getSLEi (uDirEntry);
|
||||
auto sleCur = fetch(*lpLedger, uDirEntry,
|
||||
getApp().getSLECache());
|
||||
|
||||
switch (sleCur->getType ())
|
||||
{
|
||||
@@ -1192,8 +1177,9 @@ Json::Value NetworkOPsImp::getOwnerInfo (
|
||||
|
||||
if (uNodeDir)
|
||||
{
|
||||
sleNode = lpLedger->getDirNode (
|
||||
getDirNodeIndex (uRootIndex, uNodeDir));
|
||||
sleNode = fetch(*lpLedger, getDirNodeIndex(
|
||||
uRootIndex, uNodeDir), getApp().getSLECache(),
|
||||
ltDIR_NODE);
|
||||
assert (sleNode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,14 +168,6 @@ public:
|
||||
RippleAddress const& destinationAccount, std::uint32_t startLedgerSeq,
|
||||
std::uint32_t endLedgerSeq, int maxTransactions) = 0;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Account functions
|
||||
//
|
||||
|
||||
virtual AccountState::pointer getAccountState (Ledger::ref lrLedger,
|
||||
RippleAddress const& accountID) = 0;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
// Directory functions
|
||||
|
||||
Reference in New Issue
Block a user