diff --git a/src/cpp/ripple/CallRPC.cpp b/src/cpp/ripple/CallRPC.cpp index 41ba8a749..5fba686ac 100644 --- a/src/cpp/ripple/CallRPC.cpp +++ b/src/cpp/ripple/CallRPC.cpp @@ -421,12 +421,24 @@ Json::Value RPCParser::parseLogLevel(const Json::Value& jvParams) // owner_info || [] // account_info || // account_info || [] -// account_lines || [] // account_offers || [] Json::Value RPCParser::parseAccountItems(const Json::Value& jvParams) +{ + return parseAccountRaw(jvParams, false); +} + +// account_lines |"" [] +Json::Value RPCParser::parseAccountLines(const Json::Value& jvParams) +{ + return parseAccountRaw(jvParams, true); +} + +// TODO: Get index from an alternate syntax: rXYZ: +Json::Value RPCParser::parseAccountRaw(const Json::Value& jvParams, bool bPeer) { std::string strIdent = jvParams[0u].asString(); - // TODO: Get index from an alternate syntax: rXYZ: + std::string strPeer = bPeer && jvParams.size() >= 2 ? jvParams[1u].asString() : ""; + int iIndex = 0; // int iIndex = jvParams.size() >= 2 ? lexical_cast_s(jvParams[1u].asString()) : 0; @@ -443,7 +455,17 @@ Json::Value RPCParser::parseAccountItems(const Json::Value& jvParams) if (iIndex) jvRequest["account_index"] = iIndex; - if (jvParams.size() == 2 && !jvParseLedger(jvRequest, jvParams[1u].asString())) + if (!strPeer.empty()) + { + RippleAddress raPeer; + + if (!raPeer.setAccountPublic(strPeer) && !raPeer.setAccountID(strPeer) && !raPeer.setSeedGeneric(strPeer)) + return rpcError(rpcACT_MALFORMED); + + jvRequest["peer"] = strPeer; + } + + if (jvParams.size() == (2+bPeer) && !jvParseLedger(jvRequest, jvParams[1u+bPeer].asString())) return rpcError(rpcLGR_IDX_MALFORMED); return jvRequest; @@ -655,7 +677,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams) // - Returns an error, or the request. // - To modify the method, provide a new method in the request. { "account_info", &RPCParser::parseAccountItems, 1, 2 }, - { "account_lines", &RPCParser::parseAccountItems, 1, 2 }, + { "account_lines", &RPCParser::parseAccountLines, 1, 3 }, { "account_offers", &RPCParser::parseAccountItems, 1, 2 }, { "account_tx", &RPCParser::parseAccountTransactions, 1, 8 }, { "book_offers", &RPCParser::parseBookOffers, 2, 7 }, diff --git a/src/cpp/ripple/CallRPC.h b/src/cpp/ripple/CallRPC.h index 586006941..ac726afdf 100644 --- a/src/cpp/ripple/CallRPC.h +++ b/src/cpp/ripple/CallRPC.h @@ -10,7 +10,10 @@ class RPCParser protected: typedef Json::Value (RPCParser::*parseFuncPtr)(const Json::Value &jvParams); + Json::Value parseAccountRaw(const Json::Value& jvParams, bool bPeer); + Json::Value parseAccountItems(const Json::Value& jvParams); + Json::Value parseAccountLines(const Json::Value& jvParams); Json::Value parseAccountTransactions(const Json::Value& jvParams); Json::Value parseAsIs(const Json::Value& jvParams); Json::Value parseBookOffers(const Json::Value& jvParams); diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 52462a39e..8f38484cc 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -899,11 +899,23 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost) if (!jvResult.empty()) return jvResult; - // Get info on account. + std::string strPeer = jvRequest.isMember("peer") ? jvRequest["peer"].asString() : ""; + bool bPeerIndex = jvRequest.isMember("peer_index"); + int iPeerIndex = bIndex ? jvRequest["peer_index"].asUInt() : 0; - jvResult["account"] = raAccount.humanAccountID(); - if (bIndex) - jvResult["account_index"] = iIndex; + RippleAddress raPeer; + + if (!strPeer.empty()) + { + jvResult["peer"] = raAccount.humanAccountID(); + if (bPeerIndex) + jvResult["peer_index"] = iPeerIndex; + + jvResult = accountFromString(lpLedger, raPeer, bPeerIndex, strPeer, iPeerIndex, false); + + if (!jvResult.empty()) + return jvResult; + } AccountState::pointer as = mNetOps->getAccountState(lpLedger, raAccount); if (as) @@ -912,7 +924,6 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost) jvResult["account"] = raAccount.humanAccountID(); - // XXX This is wrong, we do access the current ledger and do need to worry about changes. // We access a committed ledger and need not worry about changes. @@ -922,23 +933,26 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost) { RippleState* line=(RippleState*)item.get(); - STAmount saBalance = line->getBalance(); - STAmount saLimit = line->getLimit(); - STAmount saLimitPeer = line->getLimitPeer(); + if (!raPeer.isValid() || raPeer.getAccountID() == line->getAccountIDPeer()) + { + STAmount saBalance = line->getBalance(); + STAmount saLimit = line->getLimit(); + STAmount saLimitPeer = line->getLimitPeer(); - Json::Value jPeer = Json::Value(Json::objectValue); + Json::Value jPeer = Json::Value(Json::objectValue); - jPeer["account"] = RippleAddress::createHumanAccountID(line->getAccountIDPeer()); - // Amount reported is positive if current account holds other account's IOUs. - // Amount reported is negative if other account holds current account's IOUs. - jPeer["balance"] = saBalance.getText(); - jPeer["currency"] = saBalance.getHumanCurrency(); - jPeer["limit"] = saLimit.getText(); - jPeer["limit_peer"] = saLimitPeer.getText(); - jPeer["quality_in"] = static_cast(line->getQualityIn()); - jPeer["quality_out"] = static_cast(line->getQualityOut()); + jPeer["account"] = RippleAddress::createHumanAccountID(line->getAccountIDPeer()); + // Amount reported is positive if current account holds other account's IOUs. + // Amount reported is negative if other account holds current account's IOUs. + jPeer["balance"] = saBalance.getText(); + jPeer["currency"] = saBalance.getHumanCurrency(); + jPeer["limit"] = saLimit.getText(); + jPeer["limit_peer"] = saLimitPeer.getText(); + jPeer["quality_in"] = static_cast(line->getQualityIn()); + jPeer["quality_out"] = static_cast(line->getQualityOut()); - jsonLines.append(jPeer); + jsonLines.append(jPeer); + } } jvResult["lines"] = jsonLines; } diff --git a/src/cpp/ripple/main.cpp b/src/cpp/ripple/main.cpp index 284c7f5d1..a112843cd 100644 --- a/src/cpp/ripple/main.cpp +++ b/src/cpp/ripple/main.cpp @@ -71,7 +71,7 @@ void printHelp(const po::options_description& desc) cerr << "Commands: " << endl; cerr << " account_info |||| []" << endl; - cerr << " account_lines || []" << endl; + cerr << " account_lines |\"\" []" << endl; cerr << " account_offers || []" << endl; cerr << " account_tx accountID [ledger_min [ledger_max [limit [offset]]]] [binary] [count] [descending]" << endl; cerr << " book_offers [ [ [ []]]]]" << endl;