From 644d97a332b02be604949d8d8f1e4c53b6e84050 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 16 Apr 2013 11:42:04 -0700 Subject: [PATCH] Add a getLedgerNext that takes into account changes in the LES. Conflicts: src/cpp/ripple/RippleCalc.cpp --- src/cpp/ripple/LedgerEntrySet.cpp | 33 +++++++++++++++++++++++++++++++ src/cpp/ripple/LedgerEntrySet.h | 3 +++ 2 files changed, 36 insertions(+) diff --git a/src/cpp/ripple/LedgerEntrySet.cpp b/src/cpp/ripple/LedgerEntrySet.cpp index 873ddd23ad..c29e9a7e78 100644 --- a/src/cpp/ripple/LedgerEntrySet.cpp +++ b/src/cpp/ripple/LedgerEntrySet.cpp @@ -892,6 +892,39 @@ bool LedgerEntrySet::dirNext( return true; } +uint256 LedgerEntrySet::getNextLedgerIndex(const uint256& uHash) +{ + // find next node in ledger that isn't deleted by LES + uint256 ledgerNext = uHash; + std::map::const_iterator it; + do + { + ledgerNext = mLedger->getNextLedgerIndex(ledgerNext); + it = mEntries.find(ledgerNext); + } while ((it != mEntries.end()) && (it->second.mAction == taaDELETE)); + + // find next node in LES that isn't deleted + for (it = mEntries.upper_bound(uHash); it != mEntries.end(); ++it) + { + + // node found in LES, node found in ledger, return earliest + if (it->second.mAction != taaDELETE) + return (ledgerNext < it->first) ? ledgerNext : it->first; + + } + + // nothing next in LES, return next ledger node + return ledgerNext; +} + +uint256 LedgerEntrySet::getNextLedgerIndex(const uint256& uHash, const uint256& uEnd) +{ + uint256 next = getNextLedgerIndex(uHash); + if (next > uEnd) + return uint256(); + return next; +} + // If there is a count, adjust the owner count by iAmount. Otherwise, compute the owner count and store it. void LedgerEntrySet::ownerCountAdjust(const uint160& uOwnerID, int iAmount, SLE::ref sleAccountRoot) { diff --git a/src/cpp/ripple/LedgerEntrySet.h b/src/cpp/ripple/LedgerEntrySet.h index 44e61b53f4..cbac5b1e96 100644 --- a/src/cpp/ripple/LedgerEntrySet.h +++ b/src/cpp/ripple/LedgerEntrySet.h @@ -120,6 +120,9 @@ public: bool dirNext(const uint256& uRootIndex, SLE::pointer& sleNode, unsigned int& uDirEntry, uint256& uEntryIndex); TER dirCount(const uint256& uDirIndex, uint32& uCount); + uint256 getNextLedgerIndex(const uint256& uHash); + uint256 getNextLedgerIndex(const uint256& uHash, const uint256& uEnd); + void ownerCountAdjust(const uint160& uOwnerID, int iAmount, SLE::ref sleAccountRoot=SLE::pointer()); // Offer functions.