Tidy up AccountState

This commit is contained in:
Vinnie Falco
2013-06-12 11:16:28 -07:00
parent d90a1276a8
commit 35ec01d558
9 changed files with 112 additions and 91 deletions

View File

@@ -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<AccountState> 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

View File

@@ -2,19 +2,12 @@
// Carries out the RPC.
//
#include <openssl/md5.h>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/pointer_cast.hpp>
#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"

View File

@@ -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<SerializedLedgerEntry>(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(naAccountID));
mLedgerEntry->setFieldAccount(sfAccount, naAccountID.getAccountID());
mLedgerEntry = boost::make_shared <SerializedLedgerEntry> (
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)

View File

@@ -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<AccountState> 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