From 398095a66782c22499fc26695d68483c3405364c Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Tue, 5 Aug 2014 19:13:38 -0700 Subject: [PATCH] Cleanups and performance optimizations (RIPD-450): * Remove AccountItems and AccountItem * Restructure RippleLineCache to not require shared_ptr * Avoid expensive copies of base_uint<160> in RippleState --- Builds/VisualStudio2013/RippleD.vcxproj | 41 +++------ .../VisualStudio2013/RippleD.vcxproj.filters | 54 ++++-------- src/ripple/module/app/misc/AccountItem.cpp | 28 ------ src/ripple/module/app/misc/AccountItem.h | 87 ------------------- src/ripple/module/app/misc/AccountItems.cpp | 85 ------------------ src/ripple/module/app/misc/AccountItems.h | 60 ------------- src/ripple/module/app/misc/Offer.cpp | 49 ----------- src/ripple/module/app/misc/Offer.h | 71 --------------- src/ripple/module/app/paths/Pathfinder.cpp | 12 +-- .../module/app/paths/RippleLineCache.cpp | 13 ++- src/ripple/module/app/paths/RippleLineCache.h | 5 +- src/ripple/module/app/paths/RippleState.cpp | 61 +++++++------ src/ripple/module/app/paths/RippleState.h | 28 +++--- .../module/rpc/handlers/AccountCurrencies.cpp | 5 +- .../module/rpc/handlers/AccountLines.cpp | 6 +- src/ripple/unity/app.h | 7 +- src/ripple/unity/app2.cpp | 1 - src/ripple/unity/app3.cpp | 1 - src/ripple/unity/app6.cpp | 1 - 19 files changed, 100 insertions(+), 515 deletions(-) delete mode 100644 src/ripple/module/app/misc/AccountItem.cpp delete mode 100644 src/ripple/module/app/misc/AccountItem.h delete mode 100644 src/ripple/module/app/misc/AccountItems.cpp delete mode 100644 src/ripple/module/app/misc/AccountItems.h delete mode 100644 src/ripple/module/app/misc/Offer.cpp delete mode 100644 src/ripple/module/app/misc/Offer.h diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index 7bf42c2ba5..f484fc498c 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -126,8 +126,6 @@ - - @@ -304,14 +302,14 @@ True - - True - True + + True + True @@ -825,14 +823,6 @@ - - - - - - - - True @@ -845,6 +835,14 @@ + + + + + + + + True @@ -1187,6 +1185,8 @@ + + True @@ -2179,16 +2179,6 @@ - - True - - - - - True - - - True @@ -2224,11 +2214,6 @@ - - True - - - diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index 8239a22f42..fd9b97fedf 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -624,9 +624,6 @@ build\proto - - . - beast @@ -858,15 +855,15 @@ beast\crypto\impl - - beast\crypto\impl - beast\crypto\impl\sha2 beast\crypto\impl\sha2 + + beast\crypto\impl + beast\crypto\impl @@ -1509,18 +1506,6 @@ beast\module\core\text - - beast\module\core\threads - - - beast\module\core\threads - - - beast\module\core\threads - - - beast\module\core\threads - beast\module\core\thread @@ -1536,6 +1521,18 @@ beast\module\core\thread + + beast\module\core\threads + + + beast\module\core\threads + + + beast\module\core\threads + + + beast\module\core\threads + beast\module\core\time @@ -1974,6 +1971,9 @@ beast + + . + hyperleveldb\db @@ -3201,18 +3201,6 @@ ripple\module\app\main - - ripple\module\app\misc - - - ripple\module\app\misc - - - ripple\module\app\misc - - - ripple\module\app\misc - ripple\module\app\misc @@ -3255,12 +3243,6 @@ ripple\module\app\misc - - ripple\module\app\misc - - - ripple\module\app\misc - ripple\module\app\misc diff --git a/src/ripple/module/app/misc/AccountItem.cpp b/src/ripple/module/app/misc/AccountItem.cpp deleted file mode 100644 index e450ef4e8c..0000000000 --- a/src/ripple/module/app/misc/AccountItem.cpp +++ /dev/null @@ -1,28 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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. -*/ -//============================================================================== - -namespace ripple { - -AccountItem::AccountItem (SerializedLedgerEntry::ref ledger) - : mLedgerEntry (ledger) -{ - -} - -} // ripple diff --git a/src/ripple/module/app/misc/AccountItem.h b/src/ripple/module/app/misc/AccountItem.h deleted file mode 100644 index 23d0ca537f..0000000000 --- a/src/ripple/module/app/misc/AccountItem.h +++ /dev/null @@ -1,87 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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_ACCOUNTITEM_H -#define RIPPLE_ACCOUNTITEM_H - -namespace ripple { - -// -// Fetch ledger entries from an account's owner dir. -// -/** Base class representing account items. - - Account items include: - - - Offers - - Trust Lines - - NOTE these are deprecated and will go away, to be replaced with - simple visitor patterns. -*/ -class AccountItem -{ -public: - typedef std::shared_ptr pointer; - typedef const pointer& ref; - -public: - /** Construct from a flat ledger entry. - */ - explicit AccountItem (SerializedLedgerEntry::ref ledger); - - AccountItem () {} - virtual ~AccountItem () {} - - virtual AccountItem::pointer makeItem ( - Account const& accountID, SerializedLedgerEntry::ref ledgerEntry) = 0; - - // VFALCO TODO Make this const and change derived classes - virtual LedgerEntryType getType () = 0; - - // VFALCO TODO Document the int parameter - virtual Json::Value getJson (int) = 0; - - SerializedLedgerEntry::pointer getSLE () - { - return mLedgerEntry; - } - - const SerializedLedgerEntry& peekSLE () const - { - return *mLedgerEntry; - } - - SerializedLedgerEntry& peekSLE () - { - return *mLedgerEntry; - } - - Blob getRaw () const; - - // VFALCO TODO Make this private and use the existing accessors - // -protected: - // VFALCO TODO Research making the object pointed to const - SerializedLedgerEntry::pointer mLedgerEntry; -}; - -} // ripple - -#endif diff --git a/src/ripple/module/app/misc/AccountItems.cpp b/src/ripple/module/app/misc/AccountItems.cpp deleted file mode 100644 index fad841f735..0000000000 --- a/src/ripple/module/app/misc/AccountItems.cpp +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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. -*/ -//============================================================================== - -namespace ripple { - -AccountItems::AccountItems (Account const& accountID, - Ledger::ref ledger, - AccountItem::pointer ofType) -{ - mOfType = ofType; - - fillItems (accountID, ledger); -} - -void AccountItems::fillItems (Account const& accountID, Ledger::ref ledger) -{ - uint256 const rootIndex = Ledger::getOwnerDirIndex (accountID); - uint256 currentIndex = rootIndex; - - // VFALCO TODO Rewrite all infinite loops to have clear terminating - // conditions defined in one location. - // - while (1) - { - SLE::pointer ownerDir = ledger->getDirNode (currentIndex); - - // VFALCO TODO Rewrite to not return from the middle of the function - if (!ownerDir) - return; - - for (auto const& uNode: ownerDir->getFieldV256 (sfIndexes).peekValue ()) - { - // VFALCO TODO rename getSLEi() to something legible. - SLE::pointer sleCur = ledger->getSLEi (uNode); - - if (sleCur) - { - // The item in the directory is in ledger - auto item = mOfType->makeItem (accountID, sleCur); - - // makeItem() returns nullptr if the item wasn't one this - // particular AccountItems was interested in - for example, if - // the owner is only interested in ripple lines and this is an - // offer. - if (item) - mItems.push_back (item); - } - } - - std::uint64_t uNodeNext = ownerDir->getFieldU64 (sfIndexNext); - - if (!uNodeNext) - return; - - currentIndex = Ledger::getDirNodeIndex (rootIndex, uNodeNext); - } -} - -Json::Value AccountItems::getJson (int v) -{ - Json::Value ret (Json::arrayValue); - - for (auto ai: mItems) - ret.append (ai->getJson (v)); - - return ret; -} - -} // ripple diff --git a/src/ripple/module/app/misc/AccountItems.h b/src/ripple/module/app/misc/AccountItems.h deleted file mode 100644 index 2a7e50a232..0000000000 --- a/src/ripple/module/app/misc/AccountItems.h +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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_ACCOUNTITEMS_H -#define RIPPLE_ACCOUNTITEMS_H - -namespace ripple { - -/** A set of AccountItem objects. */ -class AccountItems : beast::LeakChecked -{ -public: - typedef std::shared_ptr pointer; - - typedef std::vector Container; - - AccountItems (Account const& accountID, - Ledger::ref ledger, - AccountItem::pointer ofType); - - // VFALCO TODO rename to getContainer and make this change in every interface - // that exposes the caller to the type of container. - // - Container& getItems () - { - return mItems; - } - - // VFALCO TODO What is the int for? - Json::Value getJson (int); - -private: - void fillItems (Account const& accountID, Ledger::ref ledger); - -private: - // VFALCO TODO This looks like its used as an exemplar, rename appropriately - AccountItem::pointer mOfType; - - Container mItems; -}; - -} // ripple - -#endif diff --git a/src/ripple/module/app/misc/Offer.cpp b/src/ripple/module/app/misc/Offer.cpp deleted file mode 100644 index 2c70887ed7..0000000000 --- a/src/ripple/module/app/misc/Offer.cpp +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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. -*/ -//============================================================================== - -namespace ripple { - -AccountItem::pointer Offer::makeItem ( - Account const& , SerializedLedgerEntry::ref ledgerEntry) -{ - if (!ledgerEntry || ledgerEntry->getType () != ltOFFER) return (AccountItem::pointer ()); - - Offer* offer = new Offer (ledgerEntry); - return (AccountItem::pointer (offer)); -} - -Offer::Offer (SerializedLedgerEntry::pointer ledgerEntry) : AccountItem (ledgerEntry), - mAccount (mLedgerEntry->getFieldAccount (sfAccount)), - mTakerGets (mLedgerEntry->getFieldAmount (sfTakerGets)), - mTakerPays (mLedgerEntry->getFieldAmount (sfTakerPays)), - mSeq (mLedgerEntry->getFieldU32 (sfSequence)) -{ - ; -} - -Json::Value Offer::getJson (int) -{ - Json::Value ret (Json::objectValue); - ret["account"] = mAccount.humanAccountID (); - ret["taker_gets"] = getTakerGets ().getFullText (); - ret["taker_pays"] = getTakerPays ().getFullText (); - return ret; -} - -} // ripple diff --git a/src/ripple/module/app/misc/Offer.h b/src/ripple/module/app/misc/Offer.h deleted file mode 100644 index 9e8b4a6d0f..0000000000 --- a/src/ripple/module/app/misc/Offer.h +++ /dev/null @@ -1,71 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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_OFFER_H -#define RIPPLE_OFFER_H - -namespace ripple { - -class Offer : public AccountItem -{ -public: - Offer () {} - - virtual ~Offer () {} - - AccountItem::pointer makeItem ( - Account const&, SerializedLedgerEntry::ref ledgerEntry); - - LedgerEntryType getType () - { - return (ltOFFER); - } - - STAmount const& getTakerPays () - { - return (mTakerPays); - } - STAmount const& getTakerGets () - { - return (mTakerGets); - } - RippleAddress const& getAccount () - { - return (mAccount); - } - int getSeq () - { - return (mSeq); - } - Json::Value getJson (int); - -private: - // For accounts in a ledger - explicit Offer (SerializedLedgerEntry::pointer ledgerEntry); - -private: - RippleAddress mAccount; - STAmount mTakerGets; - STAmount mTakerPays; - int mSeq; -}; - -} // ripple - -#endif diff --git a/src/ripple/module/app/paths/Pathfinder.cpp b/src/ripple/module/app/paths/Pathfinder.cpp index ce0b712ab0..45e1ba7849 100644 --- a/src/ripple/module/app/paths/Pathfinder.cpp +++ b/src/ripple/module/app/paths/Pathfinder.cpp @@ -431,7 +431,7 @@ CurrencySet usAccountSourceCurrencies ( // List of ripple lines. auto& rippleLines (lrCache->getRippleLines (raAccountID.getAccountID ())); - for (auto const& item: rippleLines.getItems ()) + for (auto const& item : rippleLines) { auto rspEntry = (RippleState*) item.get (); auto& saBalance = rspEntry->getBalance (); @@ -465,7 +465,7 @@ CurrencySet usAccountDestCurrencies ( // List of ripple lines. auto& rippleLines (lrCache->getRippleLines (raAccountID.getAccountID ())); - for (auto item: rippleLines.getItems ()) + for (auto const& item : rippleLines) { RippleState* rspEntry = (RippleState*) item.get (); STAmount const& saBalance = rspEntry->getBalance (); @@ -513,8 +513,8 @@ int Pathfinder::getPathsOut ( if (!bFrozen) { count = getApp().getOrderBookDB().getBookSize({currencyID, accountID}); - AccountItems& rippleLines = mRLCache->getRippleLines (accountID); - for (auto const& item : rippleLines.getItems ()) + + for (auto const& item : mRLCache->getRippleLines (accountID)) { RippleState* rspEntry = (RippleState*) item.get (); @@ -704,9 +704,9 @@ void Pathfinder::addLink( auto& rippleLines (mRLCache->getRippleLines(uEndAccount)); AccountCandidates candidates; - candidates.reserve(rippleLines.getItems().size()); + candidates.reserve(rippleLines.size()); - for(auto const& item : rippleLines.getItems()) + for(auto const& item : rippleLines) { auto* rs = dynamic_cast (item.get()); if (!rs) diff --git a/src/ripple/module/app/paths/RippleLineCache.cpp b/src/ripple/module/app/paths/RippleLineCache.cpp index 056ab61a83..fb13a7b337 100644 --- a/src/ripple/module/app/paths/RippleLineCache.cpp +++ b/src/ripple/module/app/paths/RippleLineCache.cpp @@ -24,19 +24,18 @@ RippleLineCache::RippleLineCache (Ledger::ref l) { } -AccountItems& RippleLineCache::getRippleLines (Account const& accountID) +std::vector const& +RippleLineCache::getRippleLines (Account const& accountID) { ScopedLockType sl (mLock); auto it = mRLMap.find (accountID); if (it == mRLMap.end ()) - { - auto accountItems = std::make_shared ( - accountID, mLedger, AccountItem::pointer (new RippleState ())); - it = mRLMap.insert ({accountID, accountItems}).first; - } - return *it->second; + it = mRLMap.insert (std::make_pair ( + accountID, ripple::getRippleStateItems (accountID, mLedger))).first; + + return it->second; } } // ripple diff --git a/src/ripple/module/app/paths/RippleLineCache.h b/src/ripple/module/app/paths/RippleLineCache.h index 0be2219f0e..9e5370f700 100644 --- a/src/ripple/module/app/paths/RippleLineCache.h +++ b/src/ripple/module/app/paths/RippleLineCache.h @@ -36,7 +36,8 @@ public: return mLedger; } - AccountItems& getRippleLines (Account const& accountID); + std::vector const& + getRippleLines (Account const& accountID); private: typedef RippleMutex LockType; @@ -45,7 +46,7 @@ private: Ledger::pointer mLedger; - hash_map mRLMap; + hash_map > mRLMap; }; } // ripple diff --git a/src/ripple/module/app/paths/RippleState.cpp b/src/ripple/module/app/paths/RippleState.cpp index a32ccabc4e..fdb0ae9f46 100644 --- a/src/ripple/module/app/paths/RippleState.cpp +++ b/src/ripple/module/app/paths/RippleState.cpp @@ -19,30 +19,24 @@ namespace ripple { -AccountItem::pointer RippleState::makeItem ( +RippleState::pointer RippleState::makeItem ( Account const& accountID, SerializedLedgerEntry::ref ledgerEntry) { if (!ledgerEntry || ledgerEntry->getType () != ltRIPPLE_STATE) - return AccountItem::pointer (); + return pointer (); - RippleState* rs = new RippleState (ledgerEntry); - rs->setViewAccount (accountID); - - return AccountItem::pointer (rs); + return pointer (new RippleState (ledgerEntry, accountID)); } -RippleState::RippleState (SerializedLedgerEntry::ref ledgerEntry) - : AccountItem (ledgerEntry), - mValid (false), - mViewLowest (true), - - mLowLimit (ledgerEntry->getFieldAmount (sfLowLimit)), - mHighLimit (ledgerEntry->getFieldAmount (sfHighLimit)), - - mLowID (mLowLimit.getIssuer ()), - mHighID (mHighLimit.getIssuer ()), - - mBalance (ledgerEntry->getFieldAmount (sfBalance)) +RippleState::RippleState ( + SerializedLedgerEntry::ref ledgerEntry, + Account const& viewAccount) + : mLedgerEntry (ledgerEntry) + , mLowLimit (ledgerEntry->getFieldAmount (sfLowLimit)) + , mHighLimit (ledgerEntry->getFieldAmount (sfHighLimit)) + , mLowID (mLowLimit.getIssuer ()) + , mHighID (mHighLimit.getIssuer ()) + , mBalance (ledgerEntry->getFieldAmount (sfBalance)) { mFlags = mLedgerEntry->getFieldU32 (sfFlags); @@ -52,18 +46,10 @@ RippleState::RippleState (SerializedLedgerEntry::ref ledgerEntry) mHighQualityIn = mLedgerEntry->getFieldU32 (sfHighQualityIn); mHighQualityOut = mLedgerEntry->getFieldU32 (sfHighQualityOut); - mValid = true; -} + mViewLowest = (mLowID == viewAccount); -void RippleState::setViewAccount (Account const& accountID) -{ - bool bViewLowestNew = mLowID == accountID; - - if (bViewLowestNew != mViewLowest) - { - mViewLowest = bViewLowestNew; + if (!mViewLowest) mBalance.negate (); - } } Json::Value RippleState::getJson (int) @@ -74,4 +60,23 @@ Json::Value RippleState::getJson (int) return ret; } +std::vector +getRippleStateItems ( + Account const& accountID, + Ledger::ref ledger) +{ + std::vector items; + + ledger->visitAccountItems (accountID, + [&items,&accountID](SLE::ref sleCur) + { + auto ret = RippleState::makeItem (accountID, sleCur); + + if (ret) + items.push_back (ret); + }); + + return items; +} + } // ripple diff --git a/src/ripple/module/app/paths/RippleState.h b/src/ripple/module/app/paths/RippleState.h index 312c6ce043..a1dde560a7 100644 --- a/src/ripple/module/app/paths/RippleState.h +++ b/src/ripple/module/app/paths/RippleState.h @@ -27,17 +27,17 @@ namespace ripple { // - Isolate ledger entry format. // -class RippleState : public AccountItem +class RippleState { public: typedef std::shared_ptr pointer; public: - RippleState () { } + RippleState () = delete; virtual ~RippleState () { } - AccountItem::pointer makeItem ( + static RippleState::pointer makeItem ( Account const& accountID, SerializedLedgerEntry::ref ledgerEntry); LedgerEntryType getType () @@ -45,8 +45,6 @@ public: return ltRIPPLE_STATE; } - void setViewAccount (Account const& accountID); - Account const& getAccountID () const { return mViewLowest ? mLowID : mHighID; @@ -136,19 +134,22 @@ public: Blob getRaw () const; private: - explicit RippleState (SerializedLedgerEntry::ref ledgerEntry); // For accounts in a ledger + RippleState ( + SerializedLedgerEntry::ref ledgerEntry, + Account const& viewAccount); private: - bool mValid; + SerializedLedgerEntry::pointer mLedgerEntry; + bool mViewLowest; std::uint32_t mFlags; - STAmount mLowLimit; - STAmount mHighLimit; + STAmount const& mLowLimit; + STAmount const& mHighLimit; - Account mLowID; - Account mHighID; + Account const& mLowID; + Account const& mHighID; std::uint64_t mLowQualityIn; std::uint64_t mLowQualityOut; @@ -158,6 +159,11 @@ private: STAmount mBalance; }; +std::vector +getRippleStateItems ( + Account const& accountID, + Ledger::ref ledger); + } // ripple #endif diff --git a/src/ripple/module/rpc/handlers/AccountCurrencies.cpp b/src/ripple/module/rpc/handlers/AccountCurrencies.cpp index 14694c6b02..2118a9575e 100644 --- a/src/ripple/module/rpc/handlers/AccountCurrencies.cpp +++ b/src/ripple/module/rpc/handlers/AccountCurrencies.cpp @@ -53,10 +53,7 @@ Json::Value doAccountCurrencies (RPC::Context& context) return jvAccepted; std::set send, receive; - AccountItems rippleLines ( - naAccount.getAccountID (), ledger, - AccountItem::pointer (new RippleState ())); - for (auto item: rippleLines.getItems ()) + for (auto const& item : getRippleStateItems (naAccount.getAccountID (), ledger)) { RippleState* rspEntry = (RippleState*) item.get (); STAmount const& saBalance = rspEntry->getBalance (); diff --git a/src/ripple/module/rpc/handlers/AccountLines.cpp b/src/ripple/module/rpc/handlers/AccountLines.cpp index 167af4d43f..7d6decc2f4 100644 --- a/src/ripple/module/rpc/handlers/AccountLines.cpp +++ b/src/ripple/module/rpc/handlers/AccountLines.cpp @@ -75,14 +75,10 @@ Json::Value doAccountLines (RPC::Context& context) if (ledger->hasAccount (raAccount)) { - AccountItems rippleLines (raAccount.getAccountID (), ledger, - AccountItem::pointer (new RippleState ())); - result[jss::account] = raAccount.humanAccountID (); Json::Value& jsonLines = (result[jss::lines] = Json::arrayValue); - - for (auto& item: rippleLines.getItems ()) + for (auto const& item : getRippleStateItems (raAccount.getAccountID (), ledger)) { RippleState* line = (RippleState*)item.get (); diff --git a/src/ripple/unity/app.h b/src/ripple/unity/app.h index 99f28961f3..2627e0f697 100644 --- a/src/ripple/unity/app.h +++ b/src/ripple/unity/app.h @@ -89,8 +89,6 @@ #include #include #include -#include -#include #include #include #include @@ -113,15 +111,14 @@ #include #include #include -#include +#include #include #include #include #include - #include #include #include #include -#include + #endif diff --git a/src/ripple/unity/app2.cpp b/src/ripple/unity/app2.cpp index b4cd7bdaee..2cec33282c 100644 --- a/src/ripple/unity/app2.cpp +++ b/src/ripple/unity/app2.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include #include diff --git a/src/ripple/unity/app3.cpp b/src/ripple/unity/app3.cpp index a2aa3111fc..69c14c7aa1 100644 --- a/src/ripple/unity/app3.cpp +++ b/src/ripple/unity/app3.cpp @@ -25,5 +25,4 @@ #include #include #include -#include #include diff --git a/src/ripple/unity/app6.cpp b/src/ripple/unity/app6.cpp index 388fec5973..93731f2b0d 100644 --- a/src/ripple/unity/app6.cpp +++ b/src/ripple/unity/app6.cpp @@ -29,6 +29,5 @@ #include #include #include -#include #include #include