RPC account_info support specifying ledger.

This commit is contained in:
Arthur Britto
2013-03-19 21:15:08 -07:00
parent d5a2c96907
commit 9c0310280b

View File

@@ -65,19 +65,11 @@ std::string EncodeBase64(const std::string& s)
// TODO New routine for parsing ledger parameters, other routines should standardize on this. // TODO New routine for parsing ledger parameters, other routines should standardize on this.
static bool jvParseLedger(Json::Value& jvRequest, const std::string& strLedger) static bool jvParseLedger(Json::Value& jvRequest, const std::string& strLedger)
{ {
if (strLedger == "closed") if (strLedger == "current" || strLedger == "closed" || strLedger == "validated")
{ {
jvRequest["ledger_index"] = -1; jvRequest["ledger_index"] = strLedger;
} }
else if (strLedger == "current") else if (strLedger.length() == 32)
{
jvRequest["ledger_index"] = -2;
}
else if (strLedger == "validated")
{
jvRequest["ledger_index"] = -3;
}
else if (strLedger.length() > 12)
{ {
// YYY Could confirm this is a uint256. // YYY Could confirm this is a uint256.
jvRequest["ledger_hash"] = strLedger; jvRequest["ledger_hash"] = strLedger;
@@ -143,7 +135,7 @@ Json::Value RPCParser::parseInternal(const Json::Value& jvParams)
} }
// account_info <account>|<nickname>|<account_public_key> // account_info <account>|<nickname>|<account_public_key>
// account_info <seed>|<pass_phrase>|<key> [<index>] // account_info <seed>|<pass_phrase>|<key> [[<index>] <ledger>]
Json::Value RPCParser::parseAccountInfo(const Json::Value& jvParams) Json::Value RPCParser::parseAccountInfo(const Json::Value& jvParams)
{ {
Json::Value jvRequest(Json::objectValue); Json::Value jvRequest(Json::objectValue);
@@ -159,6 +151,9 @@ Json::Value RPCParser::parseAccountInfo(const Json::Value& jvParams)
jvRequest["ident"] = strIdent; jvRequest["ident"] = strIdent;
jvRequest["account_index"] = iIndex; jvRequest["account_index"] = iIndex;
if (jvParams.size() == 3 && !jvParseLedger(jvRequest, jvParams[2u].asString()))
return rpcError(rpcLGR_IDX_MALFORMED);
return jvRequest; return jvRequest;
} }
@@ -343,20 +338,7 @@ Json::Value RPCParser::parseLedger(const Json::Value& jvParams)
return jvRequest; return jvRequest;
} }
std::string strLedger = jvParams[0u].asString(); jvParseLedger(jvRequest, jvParams[0u].asString());
if (strLedger == "current" || strLedger == "closed" || strLedger == "validated")
{
jvRequest["ledger_index"] = strLedger;
}
else if (strLedger.length() > 12)
{
jvRequest["ledger_hash"] = strLedger;
}
else
{
jvRequest["ledger_index"] = lexical_cast_s<uint32>(strLedger);
}
if (2 == jvParams.size() && jvParams[1u].asString() == "full") if (2 == jvParams.size() && jvParams[1u].asString() == "full")
{ {
@@ -373,7 +355,7 @@ Json::Value RPCParser::parseLedgerId(const Json::Value& jvParams)
std::string strLedger = jvParams[0u].asString(); std::string strLedger = jvParams[0u].asString();
if (strLedger.length() > 32) if (strLedger.length() == 32)
{ {
jvRequest["ledger_hash"] = strLedger; jvRequest["ledger_hash"] = strLedger;
} }
@@ -641,7 +623,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
// Request-response methods // Request-response methods
// - Returns an error, or the request. // - Returns an error, or the request.
// - To modify the method, provide a new method in the request. // - To modify the method, provide a new method in the request.
{ "account_info", &RPCParser::parseAccountInfo, 1, 2 }, { "account_info", &RPCParser::parseAccountInfo, 1, 3 },
{ "account_lines", &RPCParser::parseAccountItems, 1, 2 }, { "account_lines", &RPCParser::parseAccountItems, 1, 2 },
{ "account_offers", &RPCParser::parseAccountItems, 1, 2 }, { "account_offers", &RPCParser::parseAccountItems, 1, 2 },
{ "account_tx", &RPCParser::parseAccountTransactions, 2, 4 }, { "account_tx", &RPCParser::parseAccountTransactions, 2, 4 },