mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-01 08:25:51 +00:00
Refactor RPC account_info.
This commit is contained in:
@@ -56,6 +56,26 @@ Json::Value RPCParser::parseAsIs(const Json::Value ¶ms)
|
|||||||
return Json::Value(Json::objectValue);
|
return Json::Value(Json::objectValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// account_info <account>|<nickname>|<account_public_key>
|
||||||
|
// account_info <seed>|<pass_phrase>|<key> [<index>]
|
||||||
|
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<int>(jvParams[1u].asString()) : 0;
|
||||||
|
|
||||||
|
RippleAddress raAddress;
|
||||||
|
|
||||||
|
if (!raAddress.setAccountPublic(strIdent) && !raAddress.setAccountID(strIdent) && !raAddress.setSeedGeneric(strIdent))
|
||||||
|
return rpcError(rpcACT_MALFORMED);
|
||||||
|
|
||||||
|
jvRequest["ident"] = strIdent;
|
||||||
|
jvRequest["index"] = iIndex;
|
||||||
|
|
||||||
|
return jvRequest;
|
||||||
|
}
|
||||||
|
|
||||||
// Convert a rpc method and params to a request.
|
// Convert a rpc method and params to a request.
|
||||||
// <-- { method: xyz, params: [... ] } or { error: ..., ... }
|
// <-- { method: xyz, params: [... ] } or { error: ..., ... }
|
||||||
Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
|
Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
|
||||||
@@ -70,9 +90,11 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
|
|||||||
int iMaxParams;
|
int iMaxParams;
|
||||||
} commandsA[] = {
|
} commandsA[] = {
|
||||||
// Request-response methods
|
// Request-response methods
|
||||||
{ "accept_ledger", &RPCParser::parseAsIs, 0, 0 },
|
// - Returns an error, or the request.
|
||||||
|
// - To modify the method, provide a new method in the request.
|
||||||
|
{ "accept_ledger", &RPCParser::parseAsIs, 0, 0 },
|
||||||
|
{ "account_info", &RPCParser::parseAccountInfo, 1, 2 },
|
||||||
#if 0
|
#if 0
|
||||||
{ "account_info", &RPCParser::doAccountInfo, 1, 2, false, false, optCurrent },
|
|
||||||
{ "account_tx", &RPCParser::doAccountTransactions, 2, 3, false, false, optNetwork },
|
{ "account_tx", &RPCParser::doAccountTransactions, 2, 3, false, false, optNetwork },
|
||||||
{ "connect", &RPCParser::doConnect, 1, 2, true, false, optNone },
|
{ "connect", &RPCParser::doConnect, 1, 2, true, false, optNone },
|
||||||
{ "data_delete", &RPCParser::doDataDelete, 1, 1, true, false, optNone },
|
{ "data_delete", &RPCParser::doDataDelete, 1, 1, true, false, optNone },
|
||||||
@@ -175,11 +197,15 @@ int commandLineRPC(const std::vector<std::string>& vCmd)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Json::Value jvParams(Json::arrayValue);
|
||||||
|
|
||||||
|
jvParams.append(jvRequest);
|
||||||
|
|
||||||
jvOutput = callRPC(
|
jvOutput = callRPC(
|
||||||
jvRequest.isMember("method")
|
jvRequest.isMember("method") // Allow parser to rewrite method.
|
||||||
? jvRequest["method"].asString()
|
? jvRequest["method"].asString()
|
||||||
: vCmd[0],
|
: vCmd[0],
|
||||||
jvRequest["params"]); // Parsed, execute.
|
jvParams); // Parsed, execute.
|
||||||
|
|
||||||
if (jvOutput.isMember("error"))
|
if (jvOutput.isMember("error"))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ protected:
|
|||||||
typedef Json::Value (RPCParser::*parseFuncPtr)(const Json::Value &jvParams);
|
typedef Json::Value (RPCParser::*parseFuncPtr)(const Json::Value &jvParams);
|
||||||
|
|
||||||
Json::Value parseAsIs(const Json::Value &jvParams);
|
Json::Value parseAsIs(const Json::Value &jvParams);
|
||||||
|
Json::Value parseAccountInfo(const Json::Value &jvParams);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Json::Value parseCommand(std::string strMethod, Json::Value jvParams);
|
Json::Value parseCommand(std::string strMethod, Json::Value jvParams);
|
||||||
|
|||||||
@@ -260,23 +260,27 @@ Json::Value RPCHandler::doAcceptLedger(Json::Value jvRequest)
|
|||||||
if (!theConfig.RUN_STANDALONE)
|
if (!theConfig.RUN_STANDALONE)
|
||||||
return rpcError(rpcNOT_STANDALONE);
|
return rpcError(rpcNOT_STANDALONE);
|
||||||
|
|
||||||
Json::Value obj(Json::objectValue);
|
Json::Value jvResult(Json::objectValue);
|
||||||
|
|
||||||
jvRequest["newLedger"] = theApp->getOPs().acceptLedger();
|
jvResult["newLedger"] = theApp->getOPs().acceptLedger();
|
||||||
|
|
||||||
return jvRequest;
|
return jvResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
// account_info <account>|<nickname>|<account_public_key>
|
// { 'ident' : _indent_, 'index' : _index_ // optional }
|
||||||
// account_info <seed>|<pass_phrase>|<key> [<index>]
|
Json::Value RPCHandler::doAccountInfo(Json::Value jvRequest)
|
||||||
Json::Value RPCHandler::doAccountInfo(Json::Value params)
|
|
||||||
{
|
{
|
||||||
std::string strIdent = params[0u].asString();
|
// cLog(lsDEBUG) << "doAccountInfo: " << jvRequest;
|
||||||
|
|
||||||
|
if (!jvRequest.isMember("ident"))
|
||||||
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
|
std::string strIdent = jvRequest["ident"].asString();
|
||||||
bool bIndex;
|
bool bIndex;
|
||||||
int iIndex = 2 == params.size() ? lexical_cast_s<int>(params[1u].asString()) : 0;
|
int iIndex = jvRequest.isMember("index") ? jvRequest["index"].asUInt() : 0;
|
||||||
RippleAddress naAccount;
|
RippleAddress naAccount;
|
||||||
|
|
||||||
Json::Value ret;
|
Json::Value jvResult;
|
||||||
|
|
||||||
// Get info on account.
|
// Get info on account.
|
||||||
|
|
||||||
@@ -291,7 +295,7 @@ Json::Value RPCHandler::doAccountInfo(Json::Value params)
|
|||||||
asAccepted->addJson(jAccepted);
|
asAccepted->addJson(jAccepted);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret["accepted"] = jAccepted;
|
jvResult["accepted"] = jAccepted;
|
||||||
|
|
||||||
Json::Value jCurrent = accountFromString(uint256(0), naAccount, bIndex, strIdent, iIndex);
|
Json::Value jCurrent = accountFromString(uint256(0), naAccount, bIndex, strIdent, iIndex);
|
||||||
|
|
||||||
@@ -303,18 +307,18 @@ Json::Value RPCHandler::doAccountInfo(Json::Value params)
|
|||||||
asCurrent->addJson(jCurrent);
|
asCurrent->addJson(jCurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret["current"] = jCurrent;
|
jvResult["current"] = jCurrent;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (!jAccepted && !asCurrent)
|
if (!jAccepted && !asCurrent)
|
||||||
{
|
{
|
||||||
ret["account"] = naAccount.humanAccountID();
|
jvResult["account"] = naAccount.humanAccountID();
|
||||||
ret["status"] = "NotFound";
|
jvResult["status"] = "NotFound";
|
||||||
if (bIndex)
|
if (bIndex)
|
||||||
ret["index"] = iIndex;
|
jvResult["index"] = iIndex;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return jvResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value RPCHandler::doConnect(Json::Value params)
|
Json::Value RPCHandler::doConnect(Json::Value params)
|
||||||
@@ -2138,6 +2142,8 @@ Json::Value RPCHandler::doUnsubscribe(Json::Value jvRequest)
|
|||||||
|
|
||||||
Json::Value RPCHandler::doRpcCommand(const std::string& strCommand, Json::Value& jvParams, int iRole)
|
Json::Value RPCHandler::doRpcCommand(const std::string& strCommand, Json::Value& jvParams, int iRole)
|
||||||
{
|
{
|
||||||
|
// cLog(lsTRACE) << "doRpcCommand:" << strCommand << ":" << jvParams;
|
||||||
|
|
||||||
if (!jvParams.isArray() || jvParams.size() > 1)
|
if (!jvParams.isArray() || jvParams.size() > 1)
|
||||||
return rpcError(rpcINVALID_PARAMS);
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
@@ -2172,8 +2178,8 @@ Json::Value RPCHandler::doCommand(Json::Value& jvParams, int iRole)
|
|||||||
unsigned int iOptions;
|
unsigned int iOptions;
|
||||||
} commandsA[] = {
|
} commandsA[] = {
|
||||||
// Request-response methods
|
// Request-response methods
|
||||||
{ "accept_ledger", &RPCHandler::doAcceptLedger, -1, -1, true, false, optNone },
|
{ "accept_ledger", &RPCHandler::doAcceptLedger, -1, -1, true, false, optCurrent },
|
||||||
{ "account_info", &RPCHandler::doAccountInfo, 1, 2, false, false, optCurrent },
|
{ "account_info", &RPCHandler::doAccountInfo, -1, -1, false, false, optCurrent },
|
||||||
{ "account_tx", &RPCHandler::doAccountTransactions, 2, 3, false, false, optNetwork },
|
{ "account_tx", &RPCHandler::doAccountTransactions, 2, 3, false, false, optNetwork },
|
||||||
{ "connect", &RPCHandler::doConnect, 1, 2, true, false, optNone },
|
{ "connect", &RPCHandler::doConnect, 1, 2, true, false, optNone },
|
||||||
{ "data_delete", &RPCHandler::doDataDelete, 1, 1, true, false, optNone },
|
{ "data_delete", &RPCHandler::doDataDelete, 1, 1, true, false, optNone },
|
||||||
|
|||||||
Reference in New Issue
Block a user