From 35ec01d5587524d4ce03dffb436e512fbcb6bd88 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 12 Jun 2013 11:16:28 -0700 Subject: [PATCH] Tidy up AccountState --- .../containers/ripple_RangeSet.h | 3 +- modules/ripple_client/ripple_client.cpp | 2 +- modules/ripple_main/ripple_main.cpp | 6 +- newcoin.vcxproj | 5 +- newcoin.vcxproj.filters | 36 +++++----- src/cpp/ripple/AccountState.h | 52 -------------- src/cpp/ripple/RPCHandler.cpp | 7 -- ...countState.cpp => ripple_AccountState.cpp} | 21 ++++-- src/cpp/ripple/ripple_AccountState.h | 71 +++++++++++++++++++ 9 files changed, 112 insertions(+), 91 deletions(-) delete mode 100644 src/cpp/ripple/AccountState.h rename src/cpp/ripple/{AccountState.cpp => ripple_AccountState.cpp} (55%) create mode 100644 src/cpp/ripple/ripple_AccountState.h diff --git a/modules/ripple_basics/containers/ripple_RangeSet.h b/modules/ripple_basics/containers/ripple_RangeSet.h index 44dfa4045e..985d65792f 100644 --- a/modules/ripple_basics/containers/ripple_RangeSet.h +++ b/modules/ripple_basics/containers/ripple_RangeSet.h @@ -22,8 +22,7 @@ protected: void simplify(); public: - - RangeSet() { ; } + RangeSet () { } bool hasValue(uint32) const; uint32 getFirst() const; diff --git a/modules/ripple_client/ripple_client.cpp b/modules/ripple_client/ripple_client.cpp index eeb3011ca7..90c5b64150 100644 --- a/modules/ripple_client/ripple_client.cpp +++ b/modules/ripple_client/ripple_client.cpp @@ -50,7 +50,7 @@ #include "src/cpp/ripple/ripple_SerializedLedger.h" #include "src/cpp/ripple/TransactionMeta.h" #include "src/cpp/ripple/Transaction.h" - #include "src/cpp/ripple/AccountState.h" + #include "src/cpp/ripple/ripple_AccountState.h" #include "src/cpp/ripple/NicknameState.h" #include "src/cpp/ripple/Ledger.h" #include "src/cpp/ripple/LedgerEntrySet.h" diff --git a/modules/ripple_main/ripple_main.cpp b/modules/ripple_main/ripple_main.cpp index bfd8d103d5..21253513ba 100644 --- a/modules/ripple_main/ripple_main.cpp +++ b/modules/ripple_main/ripple_main.cpp @@ -43,6 +43,7 @@ // VFALCO NOTE Holy smokes...that's a lot of boost!!! #include +#include #include #include #include @@ -82,6 +83,7 @@ #include #include +#include #include #include @@ -124,7 +126,7 @@ #include "src/cpp/ripple/ripple_SerializedLedger.h" #include "src/cpp/ripple/TransactionMeta.h" #include "src/cpp/ripple/Transaction.h" -#include "src/cpp/ripple/AccountState.h" +#include "src/cpp/ripple/ripple_AccountState.h" #include "src/cpp/ripple/NicknameState.h" #include "src/cpp/ripple/Ledger.h" @@ -271,7 +273,7 @@ static const uint64 tenTo17m1 = tenTo17 - 1; #include "src/cpp/ripple/ripple_AccountItem.cpp" #include "src/cpp/ripple/ripple_AccountItems.cpp" #include "src/cpp/ripple/AccountSetTransactor.cpp" -#include "src/cpp/ripple/AccountState.cpp" // no log +#include "src/cpp/ripple/ripple_AccountState.cpp" #include "src/cpp/ripple/CallRPC.cpp" #include "src/cpp/ripple/ripple_CanonicalTXSet.cpp" #include "src/cpp/ripple/ChangeTransactor.cpp" // no log diff --git a/newcoin.vcxproj b/newcoin.vcxproj index c71656b388..beb84d2a0e 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -743,7 +743,7 @@ true true - + true true true @@ -1735,7 +1735,7 @@ - + @@ -1802,7 +1802,6 @@ - diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters index c11f49a0d1..bc2d5c770f 100644 --- a/newcoin.vcxproj.filters +++ b/newcoin.vcxproj.filters @@ -79,9 +79,6 @@ {095d33d8-dbf7-44d0-a675-6722b02bb3be} - - {9f8ed40a-9f16-42fe-82fd-caf72d3d6a2b} - {786657f9-b1b3-483c-a8e6-863cc2e02eb8} @@ -139,6 +136,9 @@ {5b22fcf9-c9f0-4260-9a17-7b448e30bb57} + + {82b7f371-8bc6-474b-b10c-18c004467b46} + @@ -582,9 +582,6 @@ 1. Modules\ripple_basics\utility - - 1. Modules\ripple_data\protobuf - 1. Modules\ripple_main\_unfactored\main @@ -636,9 +633,6 @@ 1. Modules\ripple_main\refactored - - 1. Modules\ripple_main\_unfactored\ledger - 1. Modules\ripple_main\_unfactored\ledger @@ -870,6 +864,12 @@ 1. Modules\ripple_main\_unfactored\network + + 1. Modules\ripple_main\refactored + + + 1. Modules\ripple_data\protocol + @@ -1343,9 +1343,6 @@ 1. Modules\ripple_basics\utility - - 1. Modules\ripple_data\protobuf - 1. Modules\ripple_main\_unfactored\main @@ -1397,9 +1394,6 @@ 1. Modules\ripple_main\refactored - - 1. Modules\ripple_main\_unfactored\ledger - 1. Modules\ripple_main\_unfactored\ledger @@ -1532,9 +1526,6 @@ 1. Modules\ripple_main\refactored - - 1. Modules\ripple_main\refactored - 1. Modules\ripple_main\refactored @@ -1622,6 +1613,15 @@ 1. Modules\ripple_main\refactored\shamap + + 1. Modules\ripple_main\refactored + + + 1. Modules\ripple_data\utility + + + 1. Modules\ripple_data\protocol + diff --git a/src/cpp/ripple/AccountState.h b/src/cpp/ripple/AccountState.h deleted file mode 100644 index 462db2ef70..0000000000 --- a/src/cpp/ripple/AccountState.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef RIPPLE_ACCOUNTSTATE_H -#define RIPPLE_ACCOUNTSTATE_H - -// -// Provide abstract access to an account's state, such that access to the serialized format is hidden. -// - -class AccountState -{ -public: - typedef boost::shared_ptr pointer; - -public: - // For new accounts - explicit AccountState (const RippleAddress& naAccountID); - - // For accounts in a ledger - AccountState (SLE::ref ledgerEntry, const RippleAddress& naAccountI); - - bool haveAuthorizedKey () - { - return mLedgerEntry->isFieldPresent(sfRegularKey); - } - - RippleAddress getAuthorizedKey() - { - return mLedgerEntry->getFieldAccount(sfRegularKey); - } - - STAmount getBalance() const { return mLedgerEntry->getFieldAmount(sfBalance); } - uint32 getSeq() const { return mLedgerEntry->getFieldU32(sfSequence); } - - SerializedLedgerEntry::pointer getSLE() { return mLedgerEntry; } - const SerializedLedgerEntry& peekSLE() const { return *mLedgerEntry; } - SerializedLedgerEntry& peekSLE() { return *mLedgerEntry; } - - Blob getRaw() const; - void addJson(Json::Value& value); - void dump(); - - static std::string createGravatarUrl(uint128 uEmailHash); - -private: - RippleAddress mAccountID; - RippleAddress mAuthorizedKey; - SerializedLedgerEntry::pointer mLedgerEntry; - - bool mValid; -}; - -#endif -// vim:ts=4 diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index ad194542cd..3fe8933b1c 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -2,19 +2,12 @@ // Carries out the RPC. // -#include - -#include -#include -#include - #include "Pathfinder.h" #include "RPCHandler.h" #include "RPCSub.h" #include "Wallet.h" #include "RippleCalc.h" #include "RPCErr.h" -#include "AccountState.h" #include "NicknameState.h" #include "Offer.h" diff --git a/src/cpp/ripple/AccountState.cpp b/src/cpp/ripple/ripple_AccountState.cpp similarity index 55% rename from src/cpp/ripple/AccountState.cpp rename to src/cpp/ripple/ripple_AccountState.cpp index ed4cc9a776..6117736e61 100644 --- a/src/cpp/ripple/AccountState.cpp +++ b/src/cpp/ripple/ripple_AccountState.cpp @@ -1,12 +1,17 @@ -AccountState::AccountState(const RippleAddress& naAccountID) : mAccountID(naAccountID), mValid(false) +AccountState::AccountState (RippleAddress const& naAccountID) + : mAccountID (naAccountID) + , mValid (false) { - if (!naAccountID.isValid()) return; + if (naAccountID.isValid ()) + { + mValid = true; - mLedgerEntry = boost::make_shared(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(naAccountID)); - mLedgerEntry->setFieldAccount(sfAccount, naAccountID.getAccountID()); + mLedgerEntry = boost::make_shared ( + ltACCOUNT_ROOT, Ledger::getAccountRootIndex (naAccountID)); - mValid = true; + mLedgerEntry->setFieldAccount (sfAccount, naAccountID.getAccountID()); + } } AccountState::AccountState(SLE::ref ledgerEntry, const RippleAddress& naAccountID) : @@ -20,13 +25,17 @@ AccountState::AccountState(SLE::ref ledgerEntry, const RippleAddress& naAccountI mValid = true; } +// VFALCO TODO Make this a generic utility function of some container class +// std::string AccountState::createGravatarUrl(uint128 uEmailHash) { Blob vucMD5(uEmailHash.begin(), uEmailHash.end()); std::string strMD5Lower = strHex(vucMD5); boost::to_lower(strMD5Lower); - return str(boost::format("https://www.gravatar.com/avatar/%s") % strMD5Lower); + // VFALCO TODO Give a name and move this constant to a more visible location. + // Also shouldn't this be https? + return str(boost::format("http://www.gravatar.com/avatar/%s") % strMD5Lower); } void AccountState::addJson(Json::Value& val) diff --git a/src/cpp/ripple/ripple_AccountState.h b/src/cpp/ripple/ripple_AccountState.h new file mode 100644 index 0000000000..06a47c9c12 --- /dev/null +++ b/src/cpp/ripple/ripple_AccountState.h @@ -0,0 +1,71 @@ +#ifndef RIPPLE_ACCOUNTSTATE_H +#define RIPPLE_ACCOUNTSTATE_H + +// +// Provide abstract access to an account's state, such that access to the serialized format is hidden. +// + +class AccountState +{ +public: + typedef boost::shared_ptr pointer; + +public: + // For new accounts + explicit AccountState (RippleAddress const& naAccountID); + + // For accounts in a ledger + AccountState (SLE::ref ledgerEntry, RippleAddress const& naAccountI); + + bool haveAuthorizedKey () + { + return mLedgerEntry->isFieldPresent (sfRegularKey); + } + + RippleAddress getAuthorizedKey () + { + return mLedgerEntry->getFieldAccount (sfRegularKey); + } + + STAmount getBalance () const + { + return mLedgerEntry->getFieldAmount (sfBalance); + } + + uint32 getSeq () const + { + return mLedgerEntry->getFieldU32 (sfSequence); + } + + SerializedLedgerEntry::pointer getSLE () + { + return mLedgerEntry; + } + + SerializedLedgerEntry const& peekSLE () const + { + return *mLedgerEntry; + } + + SerializedLedgerEntry& peekSLE() + { + return *mLedgerEntry; + } + + Blob getRaw () const; + + void addJson (Json::Value& value); + + void dump (); + + static std::string createGravatarUrl (uint128 uEmailHash); + +private: + RippleAddress const mAccountID; + RippleAddress mAuthorizedKey; + SerializedLedgerEntry::pointer mLedgerEntry; + + bool mValid; +}; + +#endif