From fdea361dd743e60f224c5ccb7dca927c68c89c09 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 30 May 2013 13:07:53 -0700 Subject: [PATCH] Add 'visitAccountItems' function. --- src/cpp/ripple/Ledger.cpp | 25 +++++++++++++++++++++++++ src/cpp/ripple/Ledger.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index c2ea6aa91..227f350eb 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -1020,6 +1020,31 @@ SLE::pointer Ledger::getSLEi(const uint256& uId) return ret; } +void Ledger::visitAccountItems(const uint160& accountID, FUNCTION_TYPE func) +{ // Visit each item in this account's owner directory + uint256 rootIndex = Ledger::getOwnerDirIndex(accountID); + uint256 currentIndex = rootIndex; + + while (1) + { + SLE::pointer ownerDir = getSLEi(currentIndex); + if (!ownerDir || (ownerDir->getType() != ltDIR_NODE)) + return; + + BOOST_FOREACH(const uint256& uNode, ownerDir->getFieldV256(sfIndexes).peekValue()) + { + func(getSLEi(uNode)); + } + + uint64 uNodeNext = ownerDir->getFieldU64(sfIndexNext); + if (!uNodeNext) + return; + + currentIndex = Ledger::getDirNodeIndex(rootIndex, uNodeNext); + } + +} + uint256 Ledger::getFirstLedgerIndex() { SHAMapItem::pointer node = mAccountStateMap->peekFirstItem(); diff --git a/src/cpp/ripple/Ledger.h b/src/cpp/ripple/Ledger.h index 1c7e09c08..b7e3cf524 100644 --- a/src/cpp/ripple/Ledger.h +++ b/src/cpp/ripple/Ledger.h @@ -189,6 +189,7 @@ public: SLE::pointer getAccountRoot(const uint160& accountID); SLE::pointer getAccountRoot(const RippleAddress& naAccountID); void updateSkipList(); + void visitAccountItems(const uint160& acctID, FUNCTION_TYPE); // database functions (low-level) static Ledger::pointer loadByIndex(uint32 ledgerIndex);