From a8e65ce045794ece45afadfea240ea74b2c08cc8 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sat, 2 Jun 2012 14:56:13 -0700 Subject: [PATCH] Add RPC command account_wallet_set. --- src/RPCServer.cpp | 145 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 137 insertions(+), 8 deletions(-) diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 14f4b3189e..d43bde4680 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -394,19 +394,17 @@ Json::Value RPCServer::doAccountEmailSet(Json::Value ¶ms) (void) mNetOps->processTransaction(trans); - Json::Value ret(Json::objectValue); - 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); + obj["Email"] = strEmail; + obj["EmailHash"] = strHex(vucMD5); + obj["UrlGravatar"] = AccountState::createGravatarUrl(uEmailHash); } - return ret; + return obj; } // account_info || @@ -557,12 +555,143 @@ Json::Value RPCServer::doAccountLines(Json::Value ¶ms) } } +// account_message_set Json::Value RPCServer::doAccountMessageSet(Json::Value& params) { - return "not implemented"; + NewcoinAddress naSrcAccountID; + NewcoinAddress naSeed; + uint256 uLedger; + + if (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"); + } + + std::string strMessageKey = params[2u].asString(); + + Transaction::pointer trans = Transaction::sharedAccountSet( + naAccountPublic, naAccountPrivate, + naSrcAccountID, + asSrc->getSeq(), + theConfig.FEE_DEFAULT, + 0, // YYY No source tag + false, + uint128(), + false, + uint256(), + std::vector()); + + (void) mNetOps->processTransaction(trans); + + obj["transaction"] = trans->getSTransaction()->getJson(0); + obj["status"] = trans->getStatus(); + // ret["MessageKey"] = strHex(vucMessageKey); + + return obj; } +// account_wallet_set [] Json::Value RPCServer::doAccountWalletSet(Json::Value& params) { - return "not implemented"; + 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"); + } + + std::string strWalletLocator = params.size() == 3 ? params[2u].asString() : ""; + uint256 uWalletLocator; + + uWalletLocator.SetHex(strWalletLocator); + + Transaction::pointer trans = Transaction::sharedAccountSet( + naAccountPublic, naAccountPrivate, + naSrcAccountID, + asSrc->getSeq(), + theConfig.FEE_DEFAULT, + 0, // YYY No source tag + false, + uint128(), + strWalletLocator.empty(), + uWalletLocator, + std::vector()); + + (void) mNetOps->processTransaction(trans); + + obj["transaction"] = trans->getSTransaction()->getJson(0); + obj["status"] = trans->getStatus(); + + if (!strWalletLocator.empty()) + obj["WalletLocator"] = uWalletLocator.GetHex(); + + return obj; } Json::Value RPCServer::doConnect(Json::Value& params)