From eb4708528bf668f599d8d664984d0edf34d36684 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Tue, 26 Mar 2013 18:58:26 -0700 Subject: [PATCH] Get rid of account index from CLI RPC. --- src/cpp/ripple/CallRPC.cpp | 67 ++++++++++++++------------------------ src/cpp/ripple/CallRPC.h | 1 - src/cpp/ripple/main.cpp | 7 ++-- 3 files changed, 27 insertions(+), 48 deletions(-) diff --git a/src/cpp/ripple/CallRPC.cpp b/src/cpp/ripple/CallRPC.cpp index 662170f2a8..705d6fe6ba 100644 --- a/src/cpp/ripple/CallRPC.cpp +++ b/src/cpp/ripple/CallRPC.cpp @@ -134,29 +134,6 @@ Json::Value RPCParser::parseInternal(const Json::Value& jvParams) return v; } -// account_info || -// account_info || [[] ] -Json::Value RPCParser::parseAccountInfo(const Json::Value& jvParams) -{ - Json::Value jvRequest(Json::objectValue); - std::string strIdent = jvParams[0u].asString(); - // YYY This could be more strict and report casting errors. - int iIndex = 2 == jvParams.size() ? lexical_cast_s(jvParams[1u].asString()) : 0; - - RippleAddress raAddress; - - if (!raAddress.setAccountPublic(strIdent) && !raAddress.setAccountID(strIdent) && !raAddress.setSeedGeneric(strIdent)) - return rpcError(rpcACT_MALFORMED); - - jvRequest["ident"] = strIdent; - jvRequest["account_index"] = iIndex; - - if (jvParams.size() == 3 && !jvParseLedger(jvRequest, jvParams[2u].asString())) - return rpcError(rpcLGR_IDX_MALFORMED); - - return jvRequest; -} - // account_tx // account_tx // account_tx binary @@ -420,30 +397,34 @@ Json::Value RPCParser::parseLogLevel(const Json::Value& jvParams) } // owner_info || -// owner_info || [] -Json::Value RPCParser::parseOwnerInfo(const Json::Value& jvParams) -{ - return parseAccountInfo(jvParams); -} - -// account_lines || [] -// account_offers || [] +// owner_info || [] +// account_info || +// account_info || [] +// account_lines || [] +// account_offers || [] Json::Value RPCParser::parseAccountItems(const Json::Value& jvParams) { std::string strIdent = jvParams[0u].asString(); - bool bIndex = 2 == jvParams.size(); - int iIndex = bIndex ? lexical_cast_s(jvParams[1u].asString()) : 0; + // TODO: Get index from an alternate syntax: rXYZ: + int iIndex = 0; +// int iIndex = jvParams.size() >= 2 ? lexical_cast_s(jvParams[1u].asString()) : 0; - if (bIndex && !iIndex) // Don't send default. - bIndex = false; + RippleAddress raAddress; + + if (!raAddress.setAccountPublic(strIdent) && !raAddress.setAccountID(strIdent) && !raAddress.setSeedGeneric(strIdent)) + return rpcError(rpcACT_MALFORMED); // Get info on account. Json::Value jvRequest(Json::objectValue); jvRequest["account"] = strIdent; - if (bIndex) + + if (iIndex) jvRequest["account_index"] = iIndex; + if (jvParams.size() == 2 && !jvParseLedger(jvRequest, jvParams[1u].asString())) + return rpcError(rpcLGR_IDX_MALFORMED); + return jvRequest; } @@ -456,13 +437,13 @@ Json::Value RPCParser::parseRipplePathFind(const Json::Value& jvParams) cLog(lsTRACE) << "RPC json: " << jvParams[0u]; - if (bLedger) - { - jvParseLedger(jvRequest, jvParams[1u].asString()); - } - if (reader.parse(jvParams[0u].asString(), jvRequest)) { + if (bLedger) + { + jvParseLedger(jvRequest, jvParams[1u].asString()); + } + return jvRequest; } @@ -642,7 +623,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams) // Request-response methods // - Returns an error, or the request. // - To modify the method, provide a new method in the request. - { "account_info", &RPCParser::parseAccountInfo, 1, 3 }, + { "account_info", &RPCParser::parseAccountItems, 1, 2 }, { "account_lines", &RPCParser::parseAccountItems, 1, 2 }, { "account_offers", &RPCParser::parseAccountItems, 1, 2 }, { "account_tx", &RPCParser::parseAccountTransactions, 2, 4 }, @@ -660,7 +641,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams) { "log_level", &RPCParser::parseLogLevel, 0, 2 }, { "logrotate", &RPCParser::parseAsIs, 0, 0 }, // { "nickname_info", &RPCParser::parseNicknameInfo, 1, 1 }, - { "owner_info", &RPCParser::parseOwnerInfo, 1, 2 }, + { "owner_info", &RPCParser::parseAccountItems, 1, 2 }, { "peers", &RPCParser::parseAsIs, 0, 0 }, { "ping", &RPCParser::parseAsIs, 0, 0 }, // { "profile", &RPCParser::parseProfile, 1, 9 }, diff --git a/src/cpp/ripple/CallRPC.h b/src/cpp/ripple/CallRPC.h index c87ffbe958..4bc3e8439d 100644 --- a/src/cpp/ripple/CallRPC.h +++ b/src/cpp/ripple/CallRPC.h @@ -10,7 +10,6 @@ class RPCParser protected: typedef Json::Value (RPCParser::*parseFuncPtr)(const Json::Value &jvParams); - Json::Value parseAccountInfo(const Json::Value& jvParams); Json::Value parseAccountItems(const Json::Value& jvParams); Json::Value parseAccountTransactions(const Json::Value& jvParams); Json::Value parseAsIs(const Json::Value& jvParams); diff --git a/src/cpp/ripple/main.cpp b/src/cpp/ripple/main.cpp index e717d20be3..f3ebac2643 100644 --- a/src/cpp/ripple/main.cpp +++ b/src/cpp/ripple/main.cpp @@ -70,10 +70,9 @@ void printHelp(const po::options_description& desc) cerr << desc << endl; cerr << "Commands: " << endl; - cerr << " account_info |" << endl; - cerr << " account_info || []" << endl; - cerr << " account_lines || []" << endl; - cerr << " account_offers || []" << endl; + cerr << " account_info |||| []" << endl; + cerr << " account_lines || []" << endl; + cerr << " account_offers || []" << endl; cerr << " account_tx || |( )" << endl; cerr << " book_offers [ [ [ []]]]]" << endl; cerr << " connect []" << endl;