From 2e7803144234c292ac7132fc7b86b51c999bd1d2 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 2 Jun 2012 14:25:44 -0700 Subject: [PATCH] Add RPC command account_email_set. --- src/RPCServer.cpp | 153 +++++++++++++++++++++++++++++++--------------- src/RPCServer.h | 2 + src/main.cpp | 2 + 3 files changed, 108 insertions(+), 49 deletions(-) diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index a6d31dac4f..14f4b3189e 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -328,33 +328,83 @@ Json::Value RPCServer::accountFromString(const uint256& uLedger, NewcoinAddress& // account_email_set [] Json::Value RPCServer::doAccountEmailSet(Json::Value ¶ms) { + NewcoinAddress naSrcAccountID; + NewcoinAddress naSeed; + uint256 uLedger; + if (params.size() < 2 || params.size() > 3) { return "invalid params"; } + else if (!naSeed.setFamilySeedGeneric(params[0u].asString())) + { + return "disallowed seed"; + } + else if (!naSrcAccountID.setAccountID(params[1u].asString())) + { + return "source account id needed"; + } else if (!mNetOps->available()) { return JSONRPCError(503, "network not available"); } + else if ((uLedger = mNetOps->getClosedLedger()).isZero()) + { + return JSONRPCError(503, "no closed ledger"); + } + + NewcoinAddress naMasterGenerator; + NewcoinAddress naAccountPublic; + NewcoinAddress naAccountPrivate; + AccountState::pointer asSrc; + Json::Value obj = authorize(uLedger, naSeed, naSrcAccountID, naAccountPublic, naAccountPrivate, asSrc, naMasterGenerator); + + STAmount saSrcBalance = asSrc->getBalance(); + + if (!obj.empty()) + { + return obj; + } + else if (saSrcBalance < theConfig.FEE_DEFAULT) + { + return JSONRPCError(500, "insufficent funds"); + } // Hash as per: http://en.gravatar.com/site/implement/hash/ std::string strEmail = 3 == params.size() ? params[2u].asString() : ""; + boost::trim(strEmail); + boost::to_lower(strEmail); + std::vector vucMD5(128/8, 0); - std::string strMD5Lower; + MD5(reinterpret_cast(strEmail.c_str()), strEmail.size(), &vucMD5.front()); - boost::trim(strEmail); - boost::to_lower(strEmail); + uint128 uEmailHash(vucMD5); - MD5(reinterpret_cast(strEmail.c_str()), strEmail.size(), &vucMD5.front()); + Transaction::pointer trans = Transaction::sharedAccountSet( + naAccountPublic, naAccountPrivate, + naSrcAccountID, + asSrc->getSeq(), + theConfig.FEE_DEFAULT, + 0, // YYY No source tag + strEmail.empty(), + uEmailHash, + false, + uint256(), + std::vector()); - strMD5Lower = strHex(vucMD5); - boost::to_lower(strMD5Lower); + (void) mNetOps->processTransaction(trans); Json::Value ret(Json::objectValue); - ret["email"] = strEmail; - ret["hash"] = strHex(vucMD5); - ret["url_gravatar"] = str(boost::format("http://www.gravatar.com/avatar/%s") % strMD5Lower); + obj["transaction"] = trans->getSTransaction()->getJson(0); + obj["status"] = trans->getStatus(); + + if (!strEmail.empty()) + { + ret["Email"] = strEmail; + ret["EmailHash"] = strHex(vucMD5); + ret["UrlGravatar"] = AccountState::createGravatarUrl(uEmailHash); + } return ret; } @@ -507,6 +557,14 @@ Json::Value RPCServer::doAccountLines(Json::Value ¶ms) } } +Json::Value RPCServer::doAccountMessageSet(Json::Value& params) { + return "not implemented"; +} + +Json::Value RPCServer::doAccountWalletSet(Json::Value& params) { + return "not implemented"; +} + Json::Value RPCServer::doConnect(Json::Value& params) { // connect [port] @@ -1263,48 +1321,43 @@ Json::Value RPCServer::doWalletCreate(Json::Value& params) { return "account already exists"; } - else + + // Trying to build: + // peer_wallet_create [] [] + + NewcoinAddress naMasterGenerator; + NewcoinAddress naAccountPublic; + NewcoinAddress naAccountPrivate; + AccountState::pointer asSrc; + Json::Value obj = authorize(uLedger, naSeed, naSrcAccountID, naAccountPublic, naAccountPrivate, asSrc, naMasterGenerator); + + STAmount saSrcBalance = asSrc->getBalance(); + STAmount saInitialFunds = (params.size() < 4) ? 0 : boost::lexical_cast(params[3u].asString()); + + if (!obj.empty()) { - // Trying to build: - // peer_wallet_create [] [] - - NewcoinAddress naMasterGenerator; - NewcoinAddress naAccountPublic; - NewcoinAddress naAccountPrivate; - AccountState::pointer asSrc; - uint256 uLedger = mNetOps->getClosedLedger(); - Json::Value obj = authorize(uLedger, naSeed, naSrcAccountID, naAccountPublic, naAccountPrivate, asSrc, naMasterGenerator); - - STAmount saSrcBalance = asSrc->getBalance(); - STAmount saInitialFunds = (params.size() < 4) ? 0 : boost::lexical_cast(params[3u].asString()); - - if (!obj.empty()) - { - return obj; - } - else if (saSrcBalance < (saInitialFunds + theConfig.FEE_CREATE)) - { - return JSONRPCError(500, "insufficent funds"); - } - else - { - Transaction::pointer trans = Transaction::sharedCreate( - naAccountPublic, naAccountPrivate, - naSrcAccountID, - asSrc->getSeq(), - theConfig.FEE_CREATE, - 0, // YYY No source tag - naDstAccountID, - saInitialFunds); // Initial funds in XNC. - - (void) mNetOps->processTransaction(trans); - - obj["transaction"] = trans->getSTransaction()->getJson(0); - obj["status"] = trans->getStatus(); - - return obj; - } + return obj; } + else if (saSrcBalance < (saInitialFunds + theConfig.FEE_CREATE)) + { + return JSONRPCError(500, "insufficent funds"); + } + + Transaction::pointer trans = Transaction::sharedCreate( + naAccountPublic, naAccountPrivate, + naSrcAccountID, + asSrc->getSeq(), + theConfig.FEE_CREATE, + 0, // YYY No source tag + naDstAccountID, + saInitialFunds); // Initial funds in XNC. + + (void) mNetOps->processTransaction(trans); + + obj["transaction"] = trans->getSTransaction()->getJson(0); + obj["status"] = trans->getStatus(); + + return obj; } // wallet_propose @@ -1502,6 +1555,8 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params if (command == "account_email_set") return doAccountEmailSet(params); if (command == "account_info") return doAccountInfo(params); if (command == "account_lines") return doAccountLines(params); + if (command == "account_message_set") return doAccountMessageSet(params); + if (command == "account_wallet_set") return doAccountWalletSet(params); if (command == "connect") return doConnect(params); if (command == "credit_set") return doCreditSet(params); if (command == "peers") return doPeers(params); diff --git a/src/RPCServer.h b/src/RPCServer.h index e9e0085b90..79f80099a7 100644 --- a/src/RPCServer.h +++ b/src/RPCServer.h @@ -51,6 +51,8 @@ private: Json::Value doAccountEmailSet(Json::Value ¶ms); Json::Value doAccountInfo(Json::Value& params); Json::Value doAccountLines(Json::Value ¶ms); + Json::Value doAccountMessageSet(Json::Value ¶ms); + Json::Value doAccountWalletSet(Json::Value ¶ms); Json::Value doConnect(Json::Value& params); Json::Value doCreditSet(Json::Value& params); Json::Value doLedger(Json::Value& params); diff --git a/src/main.cpp b/src/main.cpp index f9abab2788..f35aba83bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -41,6 +41,8 @@ void printHelp(const po::options_description& desc) cout << " account_info |" << endl; cout << " account_info || []" << endl; cout << " account_lines |" << endl; + cout << " account_message_set " << endl; + cout << " account_wallet_set []" << endl; cout << " connect []" << endl; cout << " credit_set []" << endl; cout << " ledger" << endl;