Make RPC account_lines support specify the peer account.

This commit is contained in:
Arthur Britto
2013-04-14 23:15:58 -07:00
parent f102097ef3
commit ec081cd2dc
4 changed files with 63 additions and 24 deletions

View File

@@ -421,12 +421,24 @@ Json::Value RPCParser::parseLogLevel(const Json::Value& jvParams)
// owner_info <seed>|<pass_phrase>|<key> [<ledfer>]
// account_info <account>|<nickname>|<account_public_key>
// account_info <seed>|<pass_phrase>|<key> [<ledger>]
// account_lines <account>|<nickname>|<account_public_key> [<ledger>]
// account_offers <account>|<nickname>|<account_public_key> [<ledger>]
Json::Value RPCParser::parseAccountItems(const Json::Value& jvParams)
{
return parseAccountRaw(jvParams, false);
}
// account_lines <account> <account>|"" [<ledger>]
Json::Value RPCParser::parseAccountLines(const Json::Value& jvParams)
{
return parseAccountRaw(jvParams, true);
}
// TODO: Get index from an alternate syntax: rXYZ:<index>
Json::Value RPCParser::parseAccountRaw(const Json::Value& jvParams, bool bPeer)
{
std::string strIdent = jvParams[0u].asString();
// TODO: Get index from an alternate syntax: rXYZ:<index>
std::string strPeer = bPeer && jvParams.size() >= 2 ? jvParams[1u].asString() : "";
int iIndex = 0;
// int iIndex = jvParams.size() >= 2 ? lexical_cast_s<int>(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 },

View File

@@ -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);

View File

@@ -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<Json::UInt>(line->getQualityIn());
jPeer["quality_out"] = static_cast<Json::UInt>(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<Json::UInt>(line->getQualityIn());
jPeer["quality_out"] = static_cast<Json::UInt>(line->getQualityOut());
jsonLines.append(jPeer);
jsonLines.append(jPeer);
}
}
jvResult["lines"] = jsonLines;
}

View File

@@ -71,7 +71,7 @@ void printHelp(const po::options_description& desc)
cerr << "Commands: " << endl;
cerr << " account_info <account>|<nickname>|<seed>|<pass_phrase>|<key> [<ledger>]" << endl;
cerr << " account_lines <account>|<nickname>|<account_public_key> [<ledger>]" << endl;
cerr << " account_lines <account> <account>|\"\" [<ledger>]" << endl;
cerr << " account_offers <account>|<nickname>|<account_public_key> [<ledger>]" << endl;
cerr << " account_tx accountID [ledger_min [ledger_max [limit [offset]]]] [binary] [count] [descending]" << endl;
cerr << " book_offers <taker_pays> <taker_gets> [<taker [<ledger> [<limit> [<proof> [<marker>]]]]]" << endl;