diff --git a/src/AccountState.cpp b/src/AccountState.cpp index 72442317ff..5e56bd9965 100644 --- a/src/AccountState.cpp +++ b/src/AccountState.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "../json/writer.h" @@ -27,16 +28,31 @@ AccountState::AccountState(SerializedLedgerEntry::pointer ledgerEntry) : mLedger mValid = true; } +std::string AccountState::createGravatarUrl(uint128 uEmailHash) +{ + std::vector 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); } diff --git a/src/AccountState.h b/src/AccountState.h index 6d40bb855e..d51898e5dd 100644 --- a/src/AccountState.h +++ b/src/AccountState.h @@ -52,6 +52,8 @@ public: std::vector getRaw() const; void addJson(Json::Value& value); void dump(); + + static std::string createGravatarUrl(uint128 uEmailHash); }; #endif