Files
rippled/src/AccountState.cpp
2012-06-02 14:21:49 -07:00

61 lines
1.5 KiB
C++

#include "AccountState.h"
#include <boost/lexical_cast.hpp>
#include <boost/make_shared.hpp>
#include <boost/algorithm/string.hpp>
#include "../json/writer.h"
#include "Ledger.h"
#include "Serializer.h"
AccountState::AccountState(const NewcoinAddress& id) : mAccountID(id), mValid(false)
{
if (!id.isValid()) return;
mLedgerEntry = boost::make_shared<SerializedLedgerEntry>(ltACCOUNT_ROOT);
mLedgerEntry->setIndex(Ledger::getAccountRootIndex(id));
mLedgerEntry->setIFieldAccount(sfAccount, id);
mValid = true;
}
AccountState::AccountState(SerializedLedgerEntry::pointer ledgerEntry) : mLedgerEntry(ledgerEntry), mValid(false)
{
if (!mLedgerEntry) return;
if (mLedgerEntry->getType() != ltACCOUNT_ROOT) return;
mAccountID = mLedgerEntry->getIValueFieldAccount(sfAccount);
if (mAccountID.isValid())
mValid = true;
}
std::string AccountState::createGravatarUrl(uint128 uEmailHash)
{
std::vector<unsigned char> vucMD5(uEmailHash.begin(), uEmailHash.end());
std::string strMD5Lower = strHex(vucMD5);
boost::to_lower(strMD5Lower);
return str(boost::format("http://www.gravatar.com/avatar/%s") % strMD5Lower);
}
void AccountState::addJson(Json::Value& val)
{
val = mLedgerEntry->getJson(0);
if (!mValid) val["Invalid"] = true;
if (mLedgerEntry->getIFieldPresent(sfEmailHash))
val["UrlGravatar"] = createGravatarUrl(mLedgerEntry->getIFieldH128(sfEmailHash));
}
void AccountState::dump()
{
Json::Value j(Json::objectValue);
addJson(j);
Json::StyledStreamWriter ssw;
ssw.write(std::cerr, j);
}
// vim:ts=4