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

@@ -0,0 +1,63 @@
AccountState::AccountState (RippleAddress const& naAccountID)
: mAccountID (naAccountID)
, mValid (false)
{
if (naAccountID.isValid ())
{
mValid = true;
mLedgerEntry = boost::make_shared <SerializedLedgerEntry> (
ltACCOUNT_ROOT, Ledger::getAccountRootIndex (naAccountID));
mLedgerEntry->setFieldAccount (sfAccount, naAccountID.getAccountID());
}
}
AccountState::AccountState(SLE::ref ledgerEntry, const RippleAddress& naAccountID) :
mAccountID(naAccountID), mLedgerEntry(ledgerEntry), mValid(false)
{
if (!mLedgerEntry)
return;
if (mLedgerEntry->getType() != ltACCOUNT_ROOT)
return;
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);
// 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)
{
val = mLedgerEntry->getJson(0);
if (mValid)
{
if (mLedgerEntry->isFieldPresent(sfEmailHash))
val["urlgravatar"] = createGravatarUrl(mLedgerEntry->getFieldH128(sfEmailHash));
}
else
{
val["Invalid"] = true;
}
}
void AccountState::dump()
{
Json::Value j(Json::objectValue);
addJson(j);
Log(lsINFO) << j;
}
// vim:ts=4