diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index 09a8813ed8..8a74a82bf1 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -2637,6 +2637,9 @@ True + + True + True @@ -2679,6 +2682,8 @@ True + + diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index ab627a2f3d..2b93aa3a29 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -3705,6 +3705,9 @@ ripple\protocol\impl + + ripple\protocol\impl + ripple\protocol\impl @@ -3747,6 +3750,9 @@ ripple\protocol\impl + + ripple\protocol + ripple\protocol diff --git a/src/ripple/app/book/BookTip.h b/src/ripple/app/book/BookTip.h index dadd12e2fc..0059908fbc 100644 --- a/src/ripple/app/book/BookTip.h +++ b/src/ripple/app/book/BookTip.h @@ -70,7 +70,7 @@ public: Quality const quality() const noexcept { - return Quality (Ledger::getQuality (m_dir)); + return Quality (getQuality (m_dir)); } SLE::pointer const& diff --git a/src/ripple/app/book/impl/BookTip.cpp b/src/ripple/app/book/impl/BookTip.cpp index e8eaebdfaa..8afbefaf78 100644 --- a/src/ripple/app/book/impl/BookTip.cpp +++ b/src/ripple/app/book/impl/BookTip.cpp @@ -25,8 +25,8 @@ namespace core { BookTip::BookTip (LedgerView& view, BookRef book) : m_view (view) , m_valid (false) - , m_book (Ledger::getBookBase (book)) - , m_end (Ledger::getQualityNext (m_book)) + , m_book (getBookBase (book)) + , m_end (getQualityNext (m_book)) { } diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index ef8c39cc36..6d3ac4c3f6 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -381,7 +381,7 @@ void Ledger::setAccepted () bool Ledger::hasAccount (RippleAddress const& accountID) const { - return mAccountStateMap->hasItem (Ledger::getAccountRootIndex (accountID)); + return mAccountStateMap->hasItem (getAccountRootIndex (accountID)); } bool Ledger::addSLE (SLE const& sle) @@ -392,13 +392,13 @@ bool Ledger::addSLE (SLE const& sle) AccountState::pointer Ledger::getAccountState (RippleAddress const& accountID) const { - SLE::pointer sle = getSLEi (Ledger::getAccountRootIndex (accountID)); + SLE::pointer sle = getSLEi (getAccountRootIndex (accountID)); if (!sle) { WriteLog (lsDEBUG, Ledger) << "Ledger:getAccountState:" << " not found: " << accountID.humanAccountID () << - ": " << to_string (Ledger::getAccountRootIndex (accountID)); + ": " << to_string (getAccountRootIndex (accountID)); return AccountState::pointer (); } @@ -1351,7 +1351,7 @@ void Ledger::visitAccountItems ( Account const& accountID, std::function func) const { // Visit each item in this account's owner directory - uint256 rootIndex = Ledger::getOwnerDirIndex (accountID); + uint256 rootIndex = getOwnerDirIndex (accountID); uint256 currentIndex = rootIndex; while (1) @@ -1371,7 +1371,7 @@ void Ledger::visitAccountItems ( if (!uNodeNext) return; - currentIndex = Ledger::getDirNodeIndex (rootIndex, uNodeNext); + currentIndex = getDirNodeIndex (rootIndex, uNodeNext); } } @@ -1384,7 +1384,7 @@ bool Ledger::visitAccountItems ( std::function func) const { // Visit each item in this account's owner directory - uint256 const rootIndex (Ledger::getOwnerDirIndex (accountID)); + uint256 const rootIndex (getOwnerDirIndex (accountID)); uint256 currentIndex (rootIndex); // If startAfter is not zero try jumping to that page using the hint @@ -1431,7 +1431,7 @@ bool Ledger::visitAccountItems ( if (uNodeNext == 0) return found; - currentIndex = Ledger::getDirNodeIndex (rootIndex, uNodeNext); + currentIndex = getDirNodeIndex (rootIndex, uNodeNext); } } else @@ -1454,7 +1454,7 @@ bool Ledger::visitAccountItems ( if (uNodeNext == 0) return true; - currentIndex = Ledger::getDirNodeIndex (rootIndex, uNodeNext); + currentIndex = getDirNodeIndex (rootIndex, uNodeNext); } } } @@ -1597,88 +1597,29 @@ SLE::pointer Ledger::getGenerator (Account const& uGeneratorID) const return getASNodeI (getGeneratorIndex (uGeneratorID), ltGENERATOR_MAP); } -SLE::pointer Ledger::getOffer (uint256 const& uIndex) const +SLE::pointer +Ledger::getOffer (uint256 const& uIndex) const { return getASNodeI (uIndex, ltOFFER); } -SLE::pointer Ledger::getRippleState (uint256 const& uNode) const +SLE::pointer +Ledger::getOffer (Account const& account, std::uint32_t uSequence) const +{ + return getOffer (getOfferIndex (account, uSequence)); +} + +SLE::pointer +Ledger::getRippleState (uint256 const& uNode) const { return getASNodeI (uNode, ltRIPPLE_STATE); } -// For an entry put in the 64 bit index or quality. -uint256 Ledger::getQualityIndex ( - uint256 const& uBase, const std::uint64_t uNodeDir) +SLE::pointer +Ledger::getRippleState ( + Account const& a, Account const& b, Currency const& currency) const { - // Indexes are stored in big endian format: they print as hex as stored. - // Most significant bytes are first. Least significant bytes represent - // adjacent entries. We place uNodeDir in the 8 right most bytes to be - // adjacent. Want uNodeDir in big endian format so ++ goes to the next - // entry for indexes. - uint256 uNode (uBase); - - // TODO(tom): there must be a better way. - ((std::uint64_t*) uNode.end ())[-1] = htobe64 (uNodeDir); - - return uNode; -} - -// Return the last 64 bits. -std::uint64_t Ledger::getQuality (uint256 const& uBase) -{ - return be64toh (((std::uint64_t*) uBase.end ())[-1]); -} - -uint256 Ledger::getQualityNext (uint256 const& uBase) -{ - static uint256 uNext ("10000000000000000"); - return uBase + uNext; -} - -uint256 Ledger::getAccountRootIndex (Account const& account) -{ - Serializer s (22); - - s.add16 (spaceAccount); // 2 - s.add160 (account); // 20 - - return s.getSHA512Half (); -} - -uint256 Ledger::getLedgerFeeIndex () -{ - // get the index of the node that holds the fee schedul - Serializer s (2); - s.add16 (spaceFee); - return s.getSHA512Half (); -} - -uint256 Ledger::getLedgerAmendmentIndex () -{ - // get the index of the node that holds the enabled amendments - Serializer s (2); - s.add16 (spaceAmendment); - return s.getSHA512Half (); -} - -uint256 Ledger::getLedgerHashIndex () -{ - // get the index of the node that holds the last 256 ledgers - Serializer s (2); - s.add16 (spaceSkipList); - return s.getSHA512Half (); -} - -uint256 Ledger::getLedgerHashIndex (std::uint32_t desiredLedgerIndex) -{ - // Get the index of the node that holds the set of 256 ledgers that includes - // this ledger's hash (or the first ledger after it if it's not a multiple - // of 256). - Serializer s (6); - s.add16 (spaceSkipList); - s.add32 (desiredLedgerIndex >> 16); - return s.getSHA512Half (); + return getRippleState (getRippleStateIndex (a, b, currency)); } uint256 Ledger::getLedgerHash (std::uint32_t ledgerIndex) @@ -1786,112 +1727,6 @@ std::vector Ledger::getLedgerAmendments () const return usAmendments; } -uint256 Ledger::getBookBase (Book const& book) -{ - Serializer s (82); - - s.add16 (spaceBookDir); // 2 - s.add160 (book.in.currency); // 20 - s.add160 (book.out.currency); // 20 - s.add160 (book.in.account); // 20 - s.add160 (book.out.account); // 20 - - // Return with quality 0. - uint256 uBaseIndex = getQualityIndex (s.getSHA512Half ()); - - WriteLog (lsTRACE, Ledger) - << "getBookBase (" << book << ") = " << to_string (uBaseIndex); - - assert (isConsistent (book)); - - return uBaseIndex; -} - -uint256 Ledger::getDirNodeIndex ( - uint256 const& uDirRoot, const std::uint64_t uNodeIndex) -{ - if (uNodeIndex) - { - Serializer s (42); - - s.add16 (spaceDirNode); // 2 - s.add256 (uDirRoot); // 32 - s.add64 (uNodeIndex); // 8 - - return s.getSHA512Half (); - } - else - { - return uDirRoot; - } -} - -uint256 Ledger::getGeneratorIndex (Account const& uGeneratorID) -{ - Serializer s (22); - - s.add16 (spaceGenerator); // 2 - s.add160 (uGeneratorID); // 20 - - return s.getSHA512Half (); -} - -uint256 Ledger::getOfferIndex (Account const& account, std::uint32_t uSequence) -{ - Serializer s (26); - - s.add16 (spaceOffer); // 2 - s.add160 (account); // 20 - s.add32 (uSequence); // 4 - - return s.getSHA512Half (); -} - -uint256 Ledger::getOwnerDirIndex (Account const& account) -{ - Serializer s (22); - - s.add16 (spaceOwnerDir); // 2 - s.add160 (account); // 20 - - return s.getSHA512Half (); -} - -uint256 Ledger::getRippleStateIndex ( - Account const& a, Account const& b, Currency const& currency) -{ - Serializer s (62); - - s.add16 (spaceRipple); // 2 - - if (a < b) - { - s.add160 (a); // 20 - s.add160 (b); // 20 - } - else - { - s.add160 (b); // 20 - s.add160 (a); // 20 - } - - s.add160 (currency); // 20 - - return s.getSHA512Half (); -} - -uint256 Ledger::getTicketIndex ( - Account const& account, std::uint32_t uSequence) -{ - Serializer s (26); - - s.add16 (spaceTicket); // 2 - s.add160 (account); // 20 - s.add32 (uSequence); // 4 - - return s.getSHA512Half (); -} - bool Ledger::walkLedger () const { std::vector missingNodes1; @@ -2108,7 +1943,7 @@ void Ledger::updateFees () std::int64_t reserveIncrement = getConfig ().FEE_OWNER_RESERVE; LedgerStateParms p = lepNONE; - auto sle = getASNode (p, Ledger::getLedgerFeeIndex (), ltFEE_SETTINGS); + auto sle = getASNode (p, getLedgerFeeIndex (), ltFEE_SETTINGS); if (sle) { @@ -2209,7 +2044,7 @@ class Ledger_test : public beast::unit_test::suite "D2DC44E5DC189318DB36EF87D2104CDF0A0FE3A4B698BEEE55038D7EA4C68000"); // VFALCO NOTE This fails in the original version as well. - expect (6125895493223874560 == Ledger::getQuality (uBig)); + expect (6125895493223874560 == getQuality (uBig)); } public: void run () diff --git a/src/ripple/app/ledger/Ledger.h b/src/ripple/app/ledger/Ledger.h index a1b2e6dad1..a2485a1a4b 100644 --- a/src/ripple/app/ledger/Ledger.h +++ b/src/ripple/app/ledger/Ledger.h @@ -330,18 +330,10 @@ public: uint256 getPrevLedgerIndex (uint256 const& uHash, uint256 const& uBegin) const; // Ledger hash table function - static uint256 getLedgerHashIndex (); - static uint256 getLedgerHashIndex (std::uint32_t desiredLedgerIndex); - static int getLedgerHashOffset (std::uint32_t desiredLedgerIndex); - static int getLedgerHashOffset ( - std::uint32_t desiredLedgerIndex, std::uint32_t currentLedgerIndex); - uint256 getLedgerHash (std::uint32_t ledgerIndex); typedef std::vector> LedgerHashes; LedgerHashes getLedgerHashes () const; - static uint256 getLedgerAmendmentIndex (); - static uint256 getLedgerFeeIndex (); std::vector getLedgerAmendments () const; std::vector getNeededTransactionHashes ( @@ -349,60 +341,24 @@ public: std::vector getNeededAccountStateHashes ( int max, SHAMapSyncFilter* filter) const; - // index calculation functions - static uint256 getAccountRootIndex (Account const&); - - static uint256 getAccountRootIndex (const RippleAddress & account) - { - return getAccountRootIndex (account.getAccountID ()); - } - // // Generator Map functions // SLE::pointer getGenerator (Account const& uGeneratorID) const; - static uint256 getGeneratorIndex (Account const& uGeneratorID); - - // - // Order book functions - // - - // Order book dirs have a base so we can use next to step through them in - // quality order. - static uint256 getBookBase (Book const&); // // Offer functions // SLE::pointer getOffer (uint256 const& uIndex) const; - SLE::pointer getOffer (Account const& account, std::uint32_t uSequence) const - { - return getOffer (getOfferIndex (account, uSequence)); - } - - // The index of an offer. - static uint256 getOfferIndex ( - Account const& account, std::uint32_t uSequence); - - // - // Owner functions - // - - // VFALCO NOTE This is a simple math operation that converts the account ID - // into a 256 bit object (I think....need to research this) - // - // All items controlled by an account are here: offers - static uint256 getOwnerDirIndex (Account const&account); + SLE::pointer getOffer (Account const& account, std::uint32_t uSequence) const; // // Directory functions // Directories are doubly linked lists of nodes. // Given a directory root and and index compute the index of a node. - static uint256 getDirNodeIndex ( - uint256 const& uDirRoot, const std::uint64_t uNodeIndex = 0); static void ownerDirDescriber (SLE::ref, bool, Account const& owner); // Return a node: root or normal @@ -412,48 +368,22 @@ public: // Quality // - static uint256 getQualityIndex ( - uint256 const& uBase, const std::uint64_t uNodeDir = 0); - static uint256 getQualityNext (uint256 const& uBase); - static std::uint64_t getQuality (uint256 const& uBase); static void qualityDirDescriber ( SLE::ref, bool, Currency const& uTakerPaysCurrency, Account const& uTakerPaysIssuer, Currency const& uTakerGetsCurrency, Account const& uTakerGetsIssuer, const std::uint64_t & uRate); - // - // Tickets - // - - static uint256 getTicketIndex ( - Account const& account, std::uint32_t uSequence); - // // Ripple functions : credit lines // - // - // Index of node which is the ripple state between two accounts for a - // currency. - // - // VFALCO NOTE Rename these to make it clear they are simple functions that - // don't access global variables. e.g. - // "calculateKeyFromRippleStateAndAddress" - static uint256 getRippleStateIndex ( - Account const& a, Account const& b, Currency const& currency); - static uint256 getRippleStateIndex ( - Account const& a, Issue const& issue) - { - return getRippleStateIndex (a, issue.account, issue.currency); - } - SLE::pointer getRippleState (uint256 const& uNode) const; - - SLE::pointer getRippleState ( - Account const& a, Account const& b, Currency const& currency) const - { - return getRippleState (getRippleStateIndex (a, b, currency)); - } + SLE::pointer + getRippleState (uint256 const& uNode) const; + + SLE::pointer + getRippleState ( + Account const& a, Account const& b, Currency const& currency) const; std::uint32_t getReferenceFeeUnits () { diff --git a/src/ripple/app/ledger/LedgerEntrySet.cpp b/src/ripple/app/ledger/LedgerEntrySet.cpp index 6843fd42b9..9312c00d46 100644 --- a/src/ripple/app/ledger/LedgerEntrySet.cpp +++ b/src/ripple/app/ledger/LedgerEntrySet.cpp @@ -384,7 +384,7 @@ bool LedgerEntrySet::threadTx (RippleAddress const& threadTo, Ledger::ref ledger NodeToLedgerEntry& newMods) { SLE::pointer sle = getForMod ( - Ledger::getAccountRootIndex (threadTo.getAccountID ()), ledger, newMods); + getAccountRootIndex (threadTo.getAccountID ()), ledger, newMods); #ifdef META_DEBUG WriteLog (lsTRACE, LedgerEntrySet) << "Thread to " << threadTo.getAccountID (); @@ -591,7 +591,7 @@ TER LedgerEntrySet::dirCount (uint256 const& uRootIndex, std::uint32_t& uCount) do { - SLE::pointer sleNode = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeDir)); + SLE::pointer sleNode = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeDir)); if (sleNode) { @@ -617,7 +617,7 @@ bool LedgerEntrySet::dirIsEmpty (uint256 const& uRootIndex) { std::uint64_t uNodeDir = 0; - SLE::pointer sleNode = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeDir)); + SLE::pointer sleNode = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeDir)); if (!sleNode) return true; @@ -665,7 +665,7 @@ TER LedgerEntrySet::dirAdd ( if (uNodeDir) { // Try adding to last node. - sleNode = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeDir)); + sleNode = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeDir)); assert (sleNode); } @@ -698,7 +698,7 @@ TER LedgerEntrySet::dirAdd ( entryModify (sleRoot); // Create the new node. - sleNode = entryCreate (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeDir)); + sleNode = entryCreate (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeDir)); sleNode->setFieldH256 (sfRootIndex, uRootIndex); if (uNodeDir != 1) @@ -734,7 +734,7 @@ TER LedgerEntrySet::dirDelete ( const bool bSoft) // --> True, uNodeDir is not hard and fast (pass uNodeDir=0). { std::uint64_t uNodeCur = uNodeDir; - SLE::pointer sleNode = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeCur)); + SLE::pointer sleNode = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeCur)); if (!sleNode) { @@ -836,7 +836,7 @@ TER LedgerEntrySet::dirDelete ( else { // Have only a root node and a last node. - SLE::pointer sleLast = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeNext)); + SLE::pointer sleLast = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeNext)); assert (sleLast); @@ -858,11 +858,11 @@ TER LedgerEntrySet::dirDelete ( { // Not root and not last node. Can delete node. - SLE::pointer slePrevious = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodePrevious)); + SLE::pointer slePrevious = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodePrevious)); assert (slePrevious); - SLE::pointer sleNext = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeNext)); + SLE::pointer sleNext = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeNext)); assert (slePrevious); assert (sleNext); @@ -962,7 +962,7 @@ bool LedgerEntrySet::dirNext ( } else { - SLE::pointer sleNext = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeNext)); + SLE::pointer sleNext = entryCache (ltDIR_NODE, getDirNodeIndex (uRootIndex, uNodeNext)); uDirEntry = 0; if (!sleNext) @@ -1046,7 +1046,7 @@ void LedgerEntrySet::incrementOwnerCount (SLE::ref sleAccount) void LedgerEntrySet::incrementOwnerCount (Account const& owner) { incrementOwnerCount(entryCache (ltACCOUNT_ROOT, - Ledger::getAccountRootIndex (owner))); + getAccountRootIndex (owner))); } void LedgerEntrySet::decrementOwnerCount (SLE::ref sleAccount) @@ -1070,7 +1070,7 @@ void LedgerEntrySet::decrementOwnerCount (SLE::ref sleAccount) void LedgerEntrySet::decrementOwnerCount (Account const& owner) { decrementOwnerCount(entryCache (ltACCOUNT_ROOT, - Ledger::getAccountRootIndex (owner))); + getAccountRootIndex (owner))); } TER LedgerEntrySet::offerDelete (SLE::pointer sleOffer) @@ -1089,7 +1089,7 @@ TER LedgerEntrySet::offerDelete (SLE::pointer sleOffer) TER terResult = dirDelete ( false, uOwnerNode, - Ledger::getOwnerDirIndex (owner), offerIndex, false, !bOwnerNode); + getOwnerDirIndex (owner), offerIndex, false, !bOwnerNode); TER terResult2 = dirDelete ( false, uBookNode, uDirectory, offerIndex, true, false); @@ -1112,7 +1112,7 @@ STAmount LedgerEntrySet::rippleHolds ( { STAmount saBalance; SLE::pointer sleRippleState = entryCache (ltRIPPLE_STATE, - Ledger::getRippleStateIndex (account, issuer, currency)); + getRippleStateIndex (account, issuer, currency)); if (!sleRippleState) { @@ -1153,7 +1153,7 @@ STAmount LedgerEntrySet::accountHolds ( if (!currency) { SLE::pointer sleAccount = entryCache (ltACCOUNT_ROOT, - Ledger::getAccountRootIndex (account)); + getAccountRootIndex (account)); std::uint64_t uReserve = mLedger->getReserve ( sleAccount->getFieldU32 (sfOwnerCount)); @@ -1191,7 +1191,7 @@ bool LedgerEntrySet::isGlobalFrozen (Account const& issuer) if (!enforceFreeze () || isXRP (issuer)) return false; - SLE::pointer sle = entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (issuer)); + SLE::pointer sle = entryCache (ltACCOUNT_ROOT, getAccountRootIndex (issuer)); if (sle && sle->isFlag (lsfGlobalFreeze)) return true; @@ -1208,7 +1208,7 @@ bool LedgerEntrySet::isFrozen( if (!enforceFreeze () || isXRP (currency)) return false; - SLE::pointer sle = entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (issuer)); + SLE::pointer sle = entryCache (ltACCOUNT_ROOT, getAccountRootIndex (issuer)); if (sle && sle->isFlag (lsfGlobalFreeze)) return true; @@ -1216,7 +1216,7 @@ bool LedgerEntrySet::isFrozen( { // Check if the issuer froze the line sle = entryCache (ltRIPPLE_STATE, - Ledger::getRippleStateIndex (account, issuer, currency)); + getRippleStateIndex (account, issuer, currency)); if (sle && sle->isFlag ((issuer > account) ? lsfHighFreeze : lsfLowFreeze)) { return true; @@ -1320,7 +1320,7 @@ TER LedgerEntrySet::trustCreate ( TER terResult = dirAdd ( uLowNode, - Ledger::getOwnerDirIndex (uLowAccountID), + getOwnerDirIndex (uLowAccountID), sleRippleState->getIndex (), std::bind (&Ledger::ownerDirDescriber, std::placeholders::_1, std::placeholders::_2, @@ -1330,7 +1330,7 @@ TER LedgerEntrySet::trustCreate ( { terResult = dirAdd ( uHighNode, - Ledger::getOwnerDirIndex (uHighAccountID), + getOwnerDirIndex (uHighAccountID), sleRippleState->getIndex (), std::bind (&Ledger::ownerDirDescriber, std::placeholders::_1, std::placeholders::_2, @@ -1402,7 +1402,7 @@ TER LedgerEntrySet::trustDelete ( terResult = dirDelete ( false, uLowNode, - Ledger::getOwnerDirIndex (uLowAccountID), + getOwnerDirIndex (uLowAccountID), sleRippleState->getIndex (), false, !bLowNode); @@ -1414,7 +1414,7 @@ TER LedgerEntrySet::trustDelete ( terResult = dirDelete ( false, uHighNode, - Ledger::getOwnerDirIndex (uHighAccountID), + getOwnerDirIndex (uHighAccountID), sleRippleState->getIndex (), false, !bHighNode); @@ -1446,7 +1446,7 @@ TER LedgerEntrySet::rippleCredit ( assert (uSenderID != uReceiverID); bool bSenderHigh = uSenderID > uReceiverID; - uint256 uIndex = Ledger::getRippleStateIndex ( + uint256 uIndex = getRippleStateIndex ( uSenderID, uReceiverID, saAmount.getCurrency ()); auto sleRippleState = entryCache (ltRIPPLE_STATE, uIndex); @@ -1472,7 +1472,7 @@ TER LedgerEntrySet::rippleCredit ( uSenderID, uReceiverID, uIndex, - entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID)), + entryCache (ltACCOUNT_ROOT, getAccountRootIndex (uReceiverID)), false, false, false, @@ -1636,10 +1636,10 @@ TER LedgerEntrySet::accountSend ( TER terResult (tesSUCCESS); SLE::pointer sender = uSenderID != beast::zero - ? entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uSenderID)) + ? entryCache (ltACCOUNT_ROOT, getAccountRootIndex (uSenderID)) : SLE::pointer (); SLE::pointer receiver = uReceiverID != beast::zero - ? entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uReceiverID)) + ? entryCache (ltACCOUNT_ROOT, getAccountRootIndex (uReceiverID)) : SLE::pointer (); if (ShouldLog (lsTRACE, LedgerEntrySet)) @@ -1708,7 +1708,7 @@ std::uint32_t rippleTransferRate (LedgerEntrySet& ledger, Account const& issuer) { SLE::pointer sleAccount (ledger.entryCache ( - ltACCOUNT_ROOT, Ledger::getAccountRootIndex (issuer))); + ltACCOUNT_ROOT, getAccountRootIndex (issuer))); std::uint32_t quality = QUALITY_ONE; diff --git a/src/ripple/app/ledger/OrderBookDB.cpp b/src/ripple/app/ledger/OrderBookDB.cpp index 8936dfd19b..e2478e8de1 100644 --- a/src/ripple/app/ledger/OrderBookDB.cpp +++ b/src/ripple/app/ledger/OrderBookDB.cpp @@ -78,7 +78,7 @@ static void updateHelper (SLE::ref entry, book.out.account.copyFrom (entry->getFieldH160 (sfTakerGetsIssuer)); book.out.currency.copyFrom (entry->getFieldH160 (sfTakerGetsCurrency)); - uint256 index = Ledger::getBookBase (book); + uint256 index = getBookBase (book); if (seen.insert (index).second) { auto orderBook = std::make_shared (index, book); @@ -156,7 +156,7 @@ void OrderBookDB::addOrderBook(Book const& book) } } } - uint256 index = Ledger::getBookBase(book); + uint256 index = getBookBase(book); auto orderBook = std::make_shared (index, book); mSourceMap[book.in].push_back (orderBook); diff --git a/src/ripple/app/ledger/OrderBookIterator.cpp b/src/ripple/app/ledger/OrderBookIterator.cpp index 217107dbec..e29bf30df7 100644 --- a/src/ripple/app/ledger/OrderBookIterator.cpp +++ b/src/ripple/app/ledger/OrderBookIterator.cpp @@ -24,9 +24,9 @@ BookDirIterator::BookDirIterator( Currency const& currencyIn, Account const& issuerIn, Currency const& currencyOut, Account const& issuerOut) { - mBase = Ledger::getBookBase({{currencyIn, issuerIn}, + mBase = ripple::getBookBase({{currencyIn, issuerIn}, {currencyOut, issuerOut}}); - mEnd = Ledger::getQualityNext(mBase); + mEnd = getQualityNext(mBase); mIndex = mBase; } @@ -94,7 +94,7 @@ DirectoryEntryIterator BookDirIterator::getOfferIterator () const std::uint64_t BookDirIterator::getRate () const { - return Ledger::getQuality(mIndex); + return getQuality(mIndex); } bool BookDirIterator::addJson (Json::Value& jv) const diff --git a/src/ripple/app/ledger/OrderBookIterator.h b/src/ripple/app/ledger/OrderBookIterator.h index 11e400252c..0f6bdebb23 100644 --- a/src/ripple/app/ledger/OrderBookIterator.h +++ b/src/ripple/app/ledger/OrderBookIterator.h @@ -67,7 +67,7 @@ public: */ std::uint64_t getCurrentQuality () const { - return Ledger::getQuality(mIndex); + return getQuality(mIndex); } /** Make this iterator refer to the next book diff --git a/src/ripple/app/misc/AccountState.cpp b/src/ripple/app/misc/AccountState.cpp index d53ea40581..82db79e6ef 100644 --- a/src/ripple/app/misc/AccountState.cpp +++ b/src/ripple/app/misc/AccountState.cpp @@ -31,7 +31,7 @@ AccountState::AccountState (RippleAddress const& naAccountID) mValid = true; mLedgerEntry = std::make_shared ( - ltACCOUNT_ROOT, Ledger::getAccountRootIndex (naAccountID)); + ltACCOUNT_ROOT, getAccountRootIndex (naAccountID)); mLedgerEntry->setFieldAccount (sfAccount, naAccountID.getAccountID ()); } diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index 47506e125d..ae90fe45c3 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -1143,7 +1143,7 @@ Json::Value NetworkOPsImp::getOwnerInfo ( Ledger::pointer lpLedger, RippleAddress const& naAccount) { Json::Value jvObjects (Json::objectValue); - auto uRootIndex = lpLedger->getOwnerDirIndex (naAccount.getAccountID ()); + auto uRootIndex = getOwnerDirIndex (naAccount.getAccountID ()); auto sleNode = lpLedger->getDirNode (uRootIndex); if (sleNode) @@ -1189,7 +1189,7 @@ Json::Value NetworkOPsImp::getOwnerInfo ( if (uNodeDir) { sleNode = lpLedger->getDirNode ( - Ledger::getDirNodeIndex (uRootIndex, uNodeDir)); + getDirNodeIndex (uRootIndex, uNodeDir)); assert (sleNode); } } @@ -2986,8 +2986,8 @@ void NetworkOPsImp::getBookPage ( (jvResult[jss::offers] = Json::Value (Json::arrayValue)); std::map umBalance; - const uint256 uBookBase = Ledger::getBookBase (book); - const uint256 uBookEnd = Ledger::getQualityNext (uBookBase); + const uint256 uBookBase = getBookBase (book); + const uint256 uBookEnd = getQualityNext (uBookBase); uint256 uTipIndex = uBookBase; if (m_journal.trace) @@ -3036,7 +3036,7 @@ void NetworkOPsImp::getBookPage ( else { uTipIndex = sleOfferDir->getIndex (); - saDirRate = amountFromQuality (Ledger::getQuality (uTipIndex)); + saDirRate = amountFromQuality (getQuality (uTipIndex)); lesActive.dirFirst ( uTipIndex, sleOfferDir, uBookEntry, offerIndex); diff --git a/src/ripple/app/misc/SerializedLedger.cpp b/src/ripple/app/misc/SerializedLedger.cpp index 8dd661179e..d86c0988c3 100644 --- a/src/ripple/app/misc/SerializedLedger.cpp +++ b/src/ripple/app/misc/SerializedLedger.cpp @@ -189,7 +189,7 @@ std::vector SerializedLedgerEntry::getOwners () auto entry = dynamic_cast (peekAtPIndex (i)); if ((entry != nullptr) && entry->getValueH160 (account)) - owners.push_back (Ledger::getAccountRootIndex (account)); + owners.push_back (getAccountRootIndex (account)); } if ((fc == sfLowLimit) || (fc == sfHighLimit)) @@ -201,7 +201,7 @@ std::vector SerializedLedgerEntry::getOwners () auto issuer = entry->getIssuer (); if (issuer.isNonZero ()) - owners.push_back (Ledger::getAccountRootIndex (issuer)); + owners.push_back (getAccountRootIndex (issuer)); } } } diff --git a/src/ripple/app/paths/Credit.cpp b/src/ripple/app/paths/Credit.cpp index 270244aa7d..55e475b176 100644 --- a/src/ripple/app/paths/Credit.cpp +++ b/src/ripple/app/paths/Credit.cpp @@ -30,13 +30,12 @@ STAmount creditLimit ( STAmount result ({currency, account}); auto sleRippleState = ledger.entryCache (ltRIPPLE_STATE, - Ledger::getRippleStateIndex (account, issuer, currency)); + getRippleStateIndex (account, issuer, currency)); if (sleRippleState) { result = sleRippleState->getFieldAmount ( account < issuer ? sfLowLimit : sfHighLimit); - result.setIssuer (account); } @@ -54,14 +53,13 @@ STAmount creditBalance ( STAmount result ({currency, account}); auto sleRippleState = ledger.entryCache (ltRIPPLE_STATE, - Ledger::getRippleStateIndex (account, issuer, currency)); + getRippleStateIndex (account, issuer, currency)); if (sleRippleState) { result = sleRippleState->getFieldAmount (sfBalance); if (account < issuer) result.negate (); - result.setIssuer (account); } diff --git a/src/ripple/app/paths/NodeDirectory.h b/src/ripple/app/paths/NodeDirectory.h index 7b449d1733..50357dcf1a 100644 --- a/src/ripple/app/paths/NodeDirectory.h +++ b/src/ripple/app/paths/NodeDirectory.h @@ -52,8 +52,8 @@ class NodeDirectory { if (current != zero) return false; - current.copyFrom (Ledger::getBookBase (book)); - next.copyFrom (Ledger::getQualityNext (current)); + current.copyFrom (getBookBase (book)); + next.copyFrom (getQualityNext (current)); // TODO(tom): it seems impossible that any actual offers with // quality == 0 could occur - we should disallow them, and clear diff --git a/src/ripple/app/paths/PathState.cpp b/src/ripple/app/paths/PathState.cpp index 8a94d9e97f..89980b3dd0 100644 --- a/src/ripple/app/paths/PathState.cpp +++ b/src/ripple/app/paths/PathState.cpp @@ -263,7 +263,7 @@ TER PathState::pushNode ( { auto sleRippleState = lesEntries.entryCache ( ltRIPPLE_STATE, - Ledger::getRippleStateIndex ( + getRippleStateIndex ( backNode.account_, node.account_, backNode.issue_.currency)); @@ -290,7 +290,7 @@ TER PathState::pushNode ( auto sleBck = lesEntries.entryCache ( ltACCOUNT_ROOT, - Ledger::getAccountRootIndex (backNode.account_)); + getAccountRootIndex (backNode.account_)); // Is the source account the highest numbered account ID? bool bHigh = backNode.account_ > node.account_; @@ -623,7 +623,7 @@ void PathState::checkFreeze() if (nodes_[i].uFlags & STPathElement::typeIssuer) { sle = lesEntries.entryCache (ltACCOUNT_ROOT, - Ledger::getAccountRootIndex (nodes_[i].issue_.account)); + getAccountRootIndex (nodes_[i].issue_.account)); if (sle && sle->isFlag (lsfGlobalFreeze)) { @@ -642,7 +642,7 @@ void PathState::checkFreeze() if (inAccount != outAccount) { sle = lesEntries.entryCache (ltACCOUNT_ROOT, - Ledger::getAccountRootIndex (outAccount)); + getAccountRootIndex (outAccount)); if (sle && sle->isFlag (lsfGlobalFreeze)) { @@ -651,7 +651,7 @@ void PathState::checkFreeze() } sle = lesEntries.entryCache (ltRIPPLE_STATE, - Ledger::getRippleStateIndex (inAccount, + getRippleStateIndex (inAccount, outAccount, currencyID)); if (sle && sle->isFlag ( @@ -679,9 +679,9 @@ TER PathState::checkNoRipple ( { // fetch the ripple lines into and out of this node SLE::pointer sleIn = lesEntries.entryCache (ltRIPPLE_STATE, - Ledger::getRippleStateIndex (firstAccount, secondAccount, currency)); + getRippleStateIndex (firstAccount, secondAccount, currency)); SLE::pointer sleOut = lesEntries.entryCache (ltRIPPLE_STATE, - Ledger::getRippleStateIndex (secondAccount, thirdAccount, currency)); + getRippleStateIndex (secondAccount, thirdAccount, currency)); if (!sleIn || !sleOut) { diff --git a/src/ripple/app/paths/Pathfinder.cpp b/src/ripple/app/paths/Pathfinder.cpp index 6a47b815c3..6872f3c3bd 100644 --- a/src/ripple/app/paths/Pathfinder.cpp +++ b/src/ripple/app/paths/Pathfinder.cpp @@ -248,14 +248,14 @@ bool Pathfinder::findPaths (int searchLevel) bool bSrcXrp = isXRP (mSrcCurrency); bool bDstXrp = isXRP (mDstAmount.getCurrency()); - if (!mLedger->getSLEi (Ledger::getAccountRootIndex (mSrcAccount))) + if (!mLedger->getSLEi (getAccountRootIndex (mSrcAccount))) { // We can't even start without a source account. WriteLog (lsDEBUG, Pathfinder) << "invalid source account"; return false; } - if (!mLedger->getSLEi (Ledger::getAccountRootIndex (mDstAccount))) + if (!mLedger->getSLEi (getAccountRootIndex (mDstAccount))) { // Can't find the destination account - we must be funding a new // account. @@ -637,8 +637,7 @@ int Pathfinder::getPathsOut ( if (!it.second) return it.first->second; - auto sleAccount - = mLedger->getSLEi (Ledger::getAccountRootIndex (account)); + auto sleAccount = mLedger->getSLEi (getAccountRootIndex (account)); if (!sleAccount) return 0; @@ -775,8 +774,8 @@ bool Pathfinder::isNoRipple ( Account const& toAccount, Currency const& currency) { - SLE::pointer sleRipple = mLedger->getSLEi ( - Ledger::getRippleStateIndex (toAccount, fromAccount, currency)); + auto sleRipple = mLedger->getSLEi ( + getRippleStateIndex (toAccount, fromAccount, currency)); auto const flag ((toAccount > fromAccount) ? lsfHighNoRipple : lsfLowNoRipple); @@ -849,8 +848,8 @@ void Pathfinder::addLink ( else { // search for accounts to add - auto sleEnd = mLedger->getSLEi( - Ledger::getAccountRootIndex (uEndAccount)); + auto sleEnd = mLedger->getSLEi(getAccountRootIndex (uEndAccount)); + if (sleEnd) { bool const bRequireAuth ( diff --git a/src/ripple/app/paths/cursor/AdvanceNode.cpp b/src/ripple/app/paths/cursor/AdvanceNode.cpp index ee1dc04137..f7d4063f6e 100644 --- a/src/ripple/app/paths/cursor/AdvanceNode.cpp +++ b/src/ripple/app/paths/cursor/AdvanceNode.cpp @@ -104,7 +104,7 @@ TER PathCursor::advanceNode (bool const bReverse) const // Our quality changed since last iteration. // Use the rate from the directory. node().saOfrRate = amountFromQuality ( - Ledger::getQuality (node().directory.current)); + getQuality (node().directory.current)); // For correct ratio node().uEntry = 0; node().bEntryAdvance = true; diff --git a/src/ripple/app/paths/cursor/RippleLiquidity.cpp b/src/ripple/app/paths/cursor/RippleLiquidity.cpp index 6089d55296..1969c72f59 100644 --- a/src/ripple/app/paths/cursor/RippleLiquidity.cpp +++ b/src/ripple/app/paths/cursor/RippleLiquidity.cpp @@ -212,7 +212,7 @@ rippleQuality ( if (destination != source) { SLE::pointer sleRippleState (ledger.entryCache (ltRIPPLE_STATE, - Ledger::getRippleStateIndex (destination, source, currency))); + getRippleStateIndex (destination, source, currency))); // we should be able to assert(sleRippleState) here diff --git a/src/ripple/app/transactors/AddWallet.cpp b/src/ripple/app/transactors/AddWallet.cpp index 931c963b43..46422bf48c 100644 --- a/src/ripple/app/transactors/AddWallet.cpp +++ b/src/ripple/app/transactors/AddWallet.cpp @@ -67,7 +67,7 @@ public: } SLE::pointer sleDst (mEngine->entryCache ( - ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uDstAccountID))); + ltACCOUNT_ROOT, getAccountRootIndex (uDstAccountID))); if (sleDst) { @@ -105,7 +105,7 @@ public: // Create the account. sleDst = mEngine->entryCreate (ltACCOUNT_ROOT, - Ledger::getAccountRootIndex (uDstAccountID)); + getAccountRootIndex (uDstAccountID)); sleDst->setFieldAccount (sfAccount, uDstAccountID); sleDst->setFieldU32 (sfSequence, 1); diff --git a/src/ripple/app/transactors/CancelOffer.cpp b/src/ripple/app/transactors/CancelOffer.cpp index eebada962a..da6dfd3ec7 100644 --- a/src/ripple/app/transactors/CancelOffer.cpp +++ b/src/ripple/app/transactors/CancelOffer.cpp @@ -62,11 +62,9 @@ public: return temBAD_SEQUENCE; } - uint256 const offerIndex ( - Ledger::getOfferIndex (mTxnAccountID, uOfferSequence)); + uint256 const offerIndex (getOfferIndex (mTxnAccountID, uOfferSequence)); - SLE::pointer sleOffer ( - mEngine->entryCache (ltOFFER, offerIndex)); + SLE::pointer sleOffer (mEngine->entryCache (ltOFFER, offerIndex)); if (sleOffer) { diff --git a/src/ripple/app/transactors/CancelTicket.cpp b/src/ripple/app/transactors/CancelTicket.cpp index 856ba2119d..889890ae26 100644 --- a/src/ripple/app/transactors/CancelTicket.cpp +++ b/src/ripple/app/transactors/CancelTicket.cpp @@ -70,7 +70,7 @@ public: std::uint64_t const hint (sleTicket->getFieldU64 (sfOwnerNode)); TER const result = mEngine->view ().dirDelete (false, hint, - Ledger::getOwnerDirIndex (ticket_owner), ticketId, false, (hint == 0)); + getOwnerDirIndex (ticket_owner), ticketId, false, (hint == 0)); mEngine->view ().decrementOwnerCount (mTxnAccount); mEngine->view ().entryDelete (sleTicket); diff --git a/src/ripple/app/transactors/Change.cpp b/src/ripple/app/transactors/Change.cpp index 7f5ff79c29..2fc210a8ad 100644 --- a/src/ripple/app/transactors/Change.cpp +++ b/src/ripple/app/transactors/Change.cpp @@ -112,14 +112,12 @@ private: { uint256 amendment (mTxn.getFieldH256 (sfAmendment)); - SLE::pointer amendmentObject (mEngine->entryCache ( - ltAMENDMENTS, Ledger::getLedgerAmendmentIndex ())); + auto const index = getLedgerAmendmentIndex (); + + SLE::pointer amendmentObject (mEngine->entryCache (ltAMENDMENTS, index)); if (!amendmentObject) - { - amendmentObject = mEngine->entryCreate( - ltAMENDMENTS, Ledger::getLedgerAmendmentIndex()); - } + amendmentObject = mEngine->entryCreate(ltAMENDMENTS, index); STVector256 amendments (amendmentObject->getFieldV256 (sfAmendments)); @@ -143,12 +141,12 @@ private: TER applyFee () { - SLE::pointer feeObject = mEngine->entryCache ( - ltFEE_SETTINGS, Ledger::getLedgerFeeIndex ()); + auto const index = getLedgerFeeIndex (); + + SLE::pointer feeObject = mEngine->entryCache (ltFEE_SETTINGS, index); if (!feeObject) - feeObject = mEngine->entryCreate ( - ltFEE_SETTINGS, Ledger::getLedgerFeeIndex ()); + feeObject = mEngine->entryCreate (ltFEE_SETTINGS, index); m_journal.trace << "Previous fee object: " << feeObject->getJson (0); diff --git a/src/ripple/app/transactors/CreateOffer.cpp b/src/ripple/app/transactors/CreateOffer.cpp index 3ae2017228..a770b880dc 100644 --- a/src/ripple/app/transactors/CreateOffer.cpp +++ b/src/ripple/app/transactors/CreateOffer.cpp @@ -43,7 +43,7 @@ private: assert (!isXRP (issue.currency)); SLE::pointer const issuerAccount = mEngine->entryCache ( - ltACCOUNT_ROOT, Ledger::getAccountRootIndex (issue.account)); + ltACCOUNT_ROOT, getAccountRootIndex (issue.account)); if (!issuerAccount) { @@ -59,7 +59,7 @@ private: if (issuerAccount->getFieldU32 (sfFlags) & lsfRequireAuth) { SLE::pointer const trustLine (mEngine->entryCache ( - ltRIPPLE_STATE, Ledger::getRippleStateIndex ( + ltRIPPLE_STATE, getRippleStateIndex ( mTxnAccountID, issue.account, issue.currency))); if (!trustLine) @@ -179,7 +179,7 @@ public: std::uint32_t const uAccountSequenceNext = mTxnAccount->getFieldU32 (sfSequence); std::uint32_t const uSequence = mTxn.getSequence (); - const uint256 uLedgerIndex = Ledger::getOfferIndex (mTxnAccountID, uSequence); + const uint256 uLedgerIndex = getOfferIndex (mTxnAccountID, uSequence); if (m_journal.debug) { @@ -211,7 +211,7 @@ public: view.bumpSeq (); // Begin ledger variance. SLE::pointer sleCreator = mEngine->entryCache ( - ltACCOUNT_ROOT, Ledger::getAccountRootIndex (mTxnAccountID)); + ltACCOUNT_ROOT, getAccountRootIndex (mTxnAccountID)); if (uTxFlags & tfOfferCreateMask) { @@ -309,7 +309,7 @@ public: if ((terResult == tesSUCCESS) && bHaveCancel) { uint256 const uCancelIndex ( - Ledger::getOfferIndex (mTxnAccountID, uCancelSequence)); + getOfferIndex (mTxnAccountID, uCancelSequence)); SLE::pointer sleCancel = mEngine->entryCache (ltOFFER, uCancelIndex); // It's not an error to not find the offer to cancel: it might have @@ -485,7 +485,7 @@ public: // Add offer to owner's directory. terResult = view.dirAdd (uOwnerNode, - Ledger::getOwnerDirIndex (mTxnAccountID), uLedgerIndex, + getOwnerDirIndex (mTxnAccountID), uLedgerIndex, std::bind ( &Ledger::ownerDirDescriber, std::placeholders::_1, std::placeholders::_2, mTxnAccountID)); @@ -495,7 +495,7 @@ public: // Update owner count. view.incrementOwnerCount (sleCreator); - uint256 const uBookBase (Ledger::getBookBase ( + uint256 const uBookBase (getBookBase ( {{uPaysCurrency, uPaysIssuerID}, {uGetsCurrency, uGetsIssuerID}})); @@ -507,7 +507,7 @@ public: "/" << to_string (saTakerGets.getIssuer ()); // We use the original rate to place the offer. - uDirectory = Ledger::getQualityIndex (uBookBase, uRate); + uDirectory = getQualityIndex (uBookBase, uRate); // Add offer to order book. terResult = view.dirAdd (uBookNode, uDirectory, uLedgerIndex, diff --git a/src/ripple/app/transactors/CreateTicket.cpp b/src/ripple/app/transactors/CreateTicket.cpp index d14486687d..bd2935f696 100644 --- a/src/ripple/app/transactors/CreateTicket.cpp +++ b/src/ripple/app/transactors/CreateTicket.cpp @@ -68,7 +68,7 @@ public: } SLE::pointer sleTicket = mEngine->entryCreate (ltTICKET, - Ledger::getTicketIndex (mTxnAccountID, mTxn.getSequence ())); + getTicketIndex (mTxnAccountID, mTxn.getSequence ())); sleTicket->setFieldAccount (sfAccount, mTxnAccountID); sleTicket->setFieldU32 (sfSequence, mTxn.getSequence ()); @@ -81,7 +81,7 @@ public: Account const target_account (mTxn.getFieldAccount160 (sfTarget)); SLE::pointer sleTarget = mEngine->entryCache (ltACCOUNT_ROOT, - Ledger::getAccountRootIndex (target_account)); + getAccountRootIndex (target_account)); // Destination account does not exist. if (!sleTarget) @@ -101,7 +101,7 @@ public: }; TER result = mEngine->view ().dirAdd ( hint, - Ledger::getOwnerDirIndex (mTxnAccountID), + getOwnerDirIndex (mTxnAccountID), sleTicket->getIndex (), describer); diff --git a/src/ripple/app/transactors/Payment.cpp b/src/ripple/app/transactors/Payment.cpp index 5f719d0a18..f6f22f80e1 100644 --- a/src/ripple/app/transactors/Payment.cpp +++ b/src/ripple/app/transactors/Payment.cpp @@ -178,7 +178,7 @@ public: // // Open a ledger for editing. - auto const index = Ledger::getAccountRootIndex (uDstAccountID); + auto const index = getAccountRootIndex (uDstAccountID); SLE::pointer sleDst (mEngine->entryCache (ltACCOUNT_ROOT, index)); if (!sleDst) @@ -220,7 +220,7 @@ public: } // Create the account. - auto const newIndex = Ledger::getAccountRootIndex (uDstAccountID); + auto const newIndex = getAccountRootIndex (uDstAccountID); sleDst = mEngine->entryCreate (ltACCOUNT_ROOT, newIndex); sleDst->setFieldAccount (sfAccount, uDstAccountID); sleDst->setFieldU32 (sfSequence, 1); diff --git a/src/ripple/app/transactors/SetAccount.cpp b/src/ripple/app/transactors/SetAccount.cpp index 40a88f8b13..f2f0e237f8 100644 --- a/src/ripple/app/transactors/SetAccount.cpp +++ b/src/ripple/app/transactors/SetAccount.cpp @@ -83,7 +83,7 @@ public: if (bSetRequireAuth && !(uFlagsIn & lsfRequireAuth)) { - if (!mEngine->view().dirIsEmpty (Ledger::getOwnerDirIndex (mTxnAccountID))) + if (!mEngine->view().dirIsEmpty (getOwnerDirIndex (mTxnAccountID))) { m_journal.trace << "Retry: Owner directory not empty."; diff --git a/src/ripple/app/transactors/SetTrust.cpp b/src/ripple/app/transactors/SetTrust.cpp index b9c0c32c7e..ba5d3adaef 100644 --- a/src/ripple/app/transactors/SetTrust.cpp +++ b/src/ripple/app/transactors/SetTrust.cpp @@ -126,7 +126,7 @@ public: { SLE::pointer selDelete ( mEngine->entryCache (ltRIPPLE_STATE, - Ledger::getRippleStateIndex ( + getRippleStateIndex ( mTxnAccountID, uDstAccountID, currency))); if (selDelete) @@ -146,7 +146,7 @@ public: } SLE::pointer sleDst (mEngine->entryCache ( - ltACCOUNT_ROOT, Ledger::getAccountRootIndex (uDstAccountID))); + ltACCOUNT_ROOT, getAccountRootIndex (uDstAccountID))); if (!sleDst) { @@ -159,7 +159,7 @@ public: saLimitAllow.setIssuer (mTxnAccountID); SLE::pointer sleRippleState (mEngine->entryCache (ltRIPPLE_STATE, - Ledger::getRippleStateIndex (mTxnAccountID, uDstAccountID, currency))); + getRippleStateIndex (mTxnAccountID, uDstAccountID, currency))); if (sleRippleState) { @@ -392,7 +392,7 @@ public: // Zero balance in currency. STAmount saBalance ({currency, noAccount()}); - uint256 index (Ledger::getRippleStateIndex ( + uint256 index (getRippleStateIndex ( mTxnAccountID, uDstAccountID, currency)); m_journal.trace << diff --git a/src/ripple/app/transactors/Transactor.cpp b/src/ripple/app/transactors/Transactor.cpp index 8b116f574a..a568d91cad 100644 --- a/src/ripple/app/transactors/Transactor.cpp +++ b/src/ripple/app/transactors/Transactor.cpp @@ -272,7 +272,7 @@ TER Transactor::apply () return (terResult); mTxnAccount = mEngine->entryCache (ltACCOUNT_ROOT, - Ledger::getAccountRootIndex (mTxnAccountID)); + getAccountRootIndex (mTxnAccountID)); calculateFee (); // Find source account diff --git a/src/ripple/app/tx/TransactionEngine.cpp b/src/ripple/app/tx/TransactionEngine.cpp index 1a043fc3e8..ba1b6f129b 100644 --- a/src/ripple/app/tx/TransactionEngine.cpp +++ b/src/ripple/app/tx/TransactionEngine.cpp @@ -139,7 +139,7 @@ TER TransactionEngine::applyTransaction ( mNodes.clear (); SLE::pointer txnAcct = entryCache (ltACCOUNT_ROOT, - Ledger::getAccountRootIndex (txn.getSourceAccount ())); + getAccountRootIndex (txn.getSourceAccount ())); if (!txnAcct) terResult = terNO_ACCOUNT; diff --git a/src/ripple/protocol/Indexes.h b/src/ripple/protocol/Indexes.h new file mode 100644 index 0000000000..e598560b4c --- /dev/null +++ b/src/ripple/protocol/Indexes.h @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012, 2013 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef RIPPLE_PROTOCOL_INDEXES_H_INCLUDED +#define RIPPLE_PROTOCOL_INDEXES_H_INCLUDED + +#include +#include +#include + +#include +#include +#include + +namespace ripple { + +// get the index of the node that holds the last 256 ledgers +uint256 +getLedgerHashIndex (); + +// Get the index of the node that holds the set of 256 ledgers that includes +// this ledger's hash (or the first ledger after it if it's not a multiple +// of 256). +uint256 +getLedgerHashIndex (std::uint32_t desiredLedgerIndex); + +// get the index of the node that holds the enabled amendments +uint256 +getLedgerAmendmentIndex (); + +// get the index of the node that holds the fee schedule +uint256 +getLedgerFeeIndex (); + +uint256 +getAccountRootIndex (Account const& account); + +uint256 +getAccountRootIndex (const RippleAddress & account); + +uint256 +getGeneratorIndex (Account const& uGeneratorID); + +uint256 +getBookBase (Book const& book); + +uint256 +getOfferIndex (Account const& account, std::uint32_t uSequence); + +uint256 +getOwnerDirIndex (Account const& account); + +uint256 +getDirNodeIndex (uint256 const& uDirRoot, const std::uint64_t uNodeIndex); + +uint256 +getQualityIndex (uint256 const& uBase, const std::uint64_t uNodeDir = 0); + +uint256 +getQualityNext (uint256 const& uBase); + +std::uint64_t +getQuality (uint256 const& uBase); + +uint256 +getTicketIndex (Account const& account, std::uint32_t uSequence); + +uint256 +getRippleStateIndex (Account const& a, Account const& b, Currency const& currency); + +uint256 +getRippleStateIndex (Account const& a, Issue const& issue); + +} + +#endif diff --git a/src/ripple/protocol/impl/Indexes.cpp b/src/ripple/protocol/impl/Indexes.cpp new file mode 100644 index 0000000000..49227a9fc3 --- /dev/null +++ b/src/ripple/protocol/impl/Indexes.cpp @@ -0,0 +1,228 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012, 2013 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include +#include +#include +#include + +#include +#include +#include + +namespace ripple { + +// get the index of the node that holds the last 256 ledgers +uint256 +getLedgerHashIndex () +{ + Serializer s (2); + s.add16 (spaceSkipList); + return s.getSHA512Half (); +} + +// Get the index of the node that holds the set of 256 ledgers that includes +// this ledger's hash (or the first ledger after it if it's not a multiple +// of 256). +uint256 +getLedgerHashIndex (std::uint32_t desiredLedgerIndex) +{ + Serializer s (6); + s.add16 (spaceSkipList); + s.add32 (desiredLedgerIndex >> 16); + return s.getSHA512Half (); +} + +// get the index of the node that holds the enabled amendments +uint256 +getLedgerAmendmentIndex () +{ + Serializer s (2); + s.add16 (spaceAmendment); + return s.getSHA512Half (); +} + +// get the index of the node that holds the fee schedule +uint256 +getLedgerFeeIndex () +{ + Serializer s (2); + s.add16 (spaceFee); + return s.getSHA512Half (); +} + +uint256 +getAccountRootIndex (Account const& account) +{ + Serializer s (22); + + s.add16 (spaceAccount); + s.add160 (account); + + return s.getSHA512Half (); +} + +uint256 +getAccountRootIndex (const RippleAddress & account) +{ + return getAccountRootIndex (account.getAccountID ()); +} + +uint256 +getGeneratorIndex (Account const& uGeneratorID) +{ + Serializer s (22); + + s.add16 (spaceGenerator); + s.add160 (uGeneratorID); + + return s.getSHA512Half (); +} + +uint256 +getBookBase (Book const& book) +{ + Serializer s (82); + + assert (isConsistent (book)); + + s.add16 (spaceBookDir); + s.add160 (book.in.currency); + s.add160 (book.out.currency); + s.add160 (book.in.account); + s.add160 (book.out.account); + + // Return with quality 0. + return getQualityIndex (s.getSHA512Half ()); +} + +uint256 +getOfferIndex (Account const& account, std::uint32_t uSequence) +{ + Serializer s (26); + + s.add16 (spaceOffer); + s.add160 (account); + s.add32 (uSequence); + + return s.getSHA512Half (); +} + +uint256 +getOwnerDirIndex (Account const& account) +{ + Serializer s (22); + + s.add16 (spaceOwnerDir); + s.add160 (account); + + return s.getSHA512Half (); +} + + +uint256 +getDirNodeIndex (uint256 const& uDirRoot, const std::uint64_t uNodeIndex) +{ + if (uNodeIndex) + { + Serializer s (42); + + s.add16 (spaceDirNode); + s.add256 (uDirRoot); + s.add64 (uNodeIndex); + + return s.getSHA512Half (); + } + else + { + return uDirRoot; + } +} + +uint256 +getQualityIndex (uint256 const& uBase, const std::uint64_t uNodeDir) +{ + // Indexes are stored in big endian format: they print as hex as stored. + // Most significant bytes are first. Least significant bytes represent + // adjacent entries. We place uNodeDir in the 8 right most bytes to be + // adjacent. Want uNodeDir in big endian format so ++ goes to the next + // entry for indexes. + uint256 uNode (uBase); + + // TODO(tom): there must be a better way. + ((std::uint64_t*) uNode.end ())[-1] = htobe64 (uNodeDir); + + return uNode; +} + +uint256 +getQualityNext (uint256 const& uBase) +{ + static uint256 uNext ("10000000000000000"); + return uBase + uNext; +} + +std::uint64_t +getQuality (uint256 const& uBase) +{ + return be64toh (((std::uint64_t*) uBase.end ())[-1]); +} + +uint256 +getTicketIndex (Account const& account, std::uint32_t uSequence) +{ + Serializer s (26); + + s.add16 (spaceTicket); + s.add160 (account); + s.add32 (uSequence); + + return s.getSHA512Half (); +} + +uint256 +getRippleStateIndex (Account const& a, Account const& b, Currency const& currency) +{ + Serializer s (62); + + s.add16 (spaceRipple); + + if (a < b) + { + s.add160 (a); + s.add160 (b); + } + else + { + s.add160 (b); + s.add160 (a); + } + + s.add160 (currency); + + return s.getSHA512Half (); +} + +uint256 +getRippleStateIndex (Account const& a, Issue const& issue) +{ + return getRippleStateIndex (a, issue.account, issue.currency); +} + +} diff --git a/src/ripple/rpc/handlers/LedgerEntry.cpp b/src/ripple/rpc/handlers/LedgerEntry.cpp index 781eb3c160..16f83b494a 100644 --- a/src/ripple/rpc/handlers/LedgerEntry.cpp +++ b/src/ripple/rpc/handlers/LedgerEntry.cpp @@ -56,7 +56,7 @@ Json::Value doLedgerEntry (RPC::Context& context) else { uNodeIndex - = Ledger::getAccountRootIndex (naAccount.getAccountID ()); + = getAccountRootIndex (naAccount.getAccountID ()); } } else if (context.params.isMember ("directory")) @@ -82,7 +82,7 @@ Json::Value doLedgerEntry (RPC::Context& context) uDirRoot.SetHex (context.params["dir_root"].asString ()); - uNodeIndex = Ledger::getDirNodeIndex (uDirRoot, uSubIndex); + uNodeIndex = getDirNodeIndex (uDirRoot, uSubIndex); } else if (context.params["directory"].isMember ("owner")) { @@ -96,9 +96,9 @@ Json::Value doLedgerEntry (RPC::Context& context) else { uint256 uDirRoot - = Ledger::getOwnerDirIndex ( + = getOwnerDirIndex ( naOwnerID.getAccountID ()); - uNodeIndex = Ledger::getDirNodeIndex (uDirRoot, uSubIndex); + uNodeIndex = getDirNodeIndex (uDirRoot, uSubIndex); } } else @@ -132,7 +132,7 @@ Json::Value doLedgerEntry (RPC::Context& context) na0Public.setAccountPublic (naGenerator, 0); - uNodeIndex = Ledger::getGeneratorIndex (na0Public.getAccountID ()); + uNodeIndex = getGeneratorIndex (na0Public.getAccountID ()); } } else if (context.params.isMember ("offer")) @@ -156,9 +156,8 @@ Json::Value doLedgerEntry (RPC::Context& context) } else { - auto uSequence = context.params["offer"]["seq"].asUInt (); - uNodeIndex = Ledger::getOfferIndex ( - naAccountID.getAccountID (), uSequence); + uNodeIndex = getOfferIndex (naAccountID.getAccountID (), + context.params["offer"]["seq"].asUInt ()); } } else if (context.params.isMember ("ripple_state")) @@ -195,7 +194,7 @@ Json::Value doLedgerEntry (RPC::Context& context) } else { - uNodeIndex = Ledger::getRippleStateIndex ( + uNodeIndex = getRippleStateIndex ( naA.getAccountID (), naB.getAccountID (), uCurrency); } } diff --git a/src/ripple/rpc/impl/TransactionSign.cpp b/src/ripple/rpc/impl/TransactionSign.cpp index ffb2e9fdef..b891151b8f 100644 --- a/src/ripple/rpc/impl/TransactionSign.cpp +++ b/src/ripple/rpc/impl/TransactionSign.cpp @@ -290,7 +290,7 @@ transactionSign ( if (verify) { SLE::pointer sleAccountRoot = netOps.getSLEi (lSnapshot, - Ledger::getAccountRootIndex (raSrcAddressID.getAccountID ())); + getAccountRootIndex (raSrcAddressID.getAccountID ())); if (!sleAccountRoot) // XXX Ignore transactions for accounts not created. diff --git a/src/ripple/unity/app.h b/src/ripple/unity/app.h index 8282b75d58..089042f4d9 100644 --- a/src/ripple/unity/app.h +++ b/src/ripple/unity/app.h @@ -56,6 +56,8 @@ #include #include +#include + #include #include #include @@ -113,7 +115,7 @@ #include #include #include - #include - #include +#include +#include #endif diff --git a/src/ripple/unity/protocol.cpp b/src/ripple/unity/protocol.cpp index d2d0dc2729..19433933bd 100644 --- a/src/ripple/unity/protocol.cpp +++ b/src/ripple/unity/protocol.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include