From a532bfb402c36909fe21b5f47d587f1f8b65ea7d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 3 Jan 2012 20:31:11 -0800 Subject: [PATCH] Add 'accountinfo' RPC command. Change 'info' to 'familyinfo'. Spec out 'sendto'. --- RPCServer.cpp | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/RPCServer.cpp b/RPCServer.cpp index 8c044ca5e2..8ac83e8433 100644 --- a/RPCServer.cpp +++ b/RPCServer.cpp @@ -93,8 +93,6 @@ std::string RPCServer::handleRequest(const std::string& requestStr) return(HTTPReply(400, "")); std::string strMethod = valMethod.asString(); - - // Parse params Json::Value valParams = valRequest["params"]; if (valParams.isNull()) @@ -165,13 +163,26 @@ Json::Value RPCServer::doCreateFamily(Json::Value& params) return ret; } -Json::Value RPCServer::doGetAccount(Json::Value ¶ms) -{ // getaccount +Json::Value RPCServer::doAccountInfo(Json::Value ¶ms) +{ // accountinfo : + if(params.isArray()) params=params[0u]; + if(!params.isConvertibleTo(Json::stringValue)) + return JSONRPCError(500, "Invalid account identifier"); + LocalAccount::pointer account=theApp->getWallet().parseAccount(params.asString()); + if(!account) + return JSONRPCError(500, "Account not found"); + + Json::Value ret(Json::objectValue); + ret["ShortName"]=account->getShortName(); + ret["FullName"]=account->getFullName(); + ret["AccountID"]=NewcoinAddress(account->getAddress()).GetString(); + ret["Issued"]=Json::Value(account->isIssued()); + return ret; } -Json::Value RPCServer::doGetNewAccount(Json::Value ¶ms) -{ // getnewaccount +Json::Value RPCServer::doNewAccount(Json::Value ¶ms) +{ // newaccount } Json::Value RPCServer::doLock(Json::Value ¶ms) @@ -184,11 +195,11 @@ Json::Value RPCServer::doUnlock(Json::Value ¶ms) // unlock "" } -Json::Value RPCServer::doInfo(Json::Value ¶ms) +Json::Value RPCServer::doFamilyInfo(Json::Value ¶ms) { - // info - // info - // info + // familyinfo + // familyinfo + // familyinfo int paramCount=0; std::string fParam; @@ -253,7 +264,7 @@ Json::Value RPCServer::doInfo(Json::Value ¶ms) if(!comment.empty()) obj["Comment"]=comment; obj["PublicGenerator"]=pubGen; - obj["Locked"]=isLocked ? "true" : "false"; + obj["Locked"]=Json::Value(isLocked); if(paramCount==2) { @@ -275,6 +286,12 @@ Json::Value RPCServer::doInfo(Json::Value ¶ms) return obj; } +Json::Value RPCServer::doSendTo(Json::Value& params) +{ // Implement simple sending without gathering + // sendto + // sendto +} + Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params) { std::cerr << "RPC:" << command << std::endl; @@ -301,11 +318,12 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params return(str.c_str()); } if(command=="createfamily") return doCreateFamily(params); - if(command=="getaccount") return doGetAccount(params); - if(command=="getnewaccount") return doGetNewAccount(params); + if(command=="familyinfo") return doFamilyInfo(params); + if(command=="accountinfo") return doAccountInfo(params); + if(command=="newaccount") return doNewAccount(params); if(command=="lock") return doLock(params); if(command=="unlock") return doUnlock(params); - if(command=="info") return doInfo(params); + if(command=="sendto") return doSendTo(params); return "unknown command"; }