mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-24 04:55:52 +00:00
Refactor RPC unl_delete.
This commit is contained in:
@@ -161,6 +161,15 @@ Json::Value RPCParser::parseUnlAdd(const Json::Value& jvParams)
|
||||
return rpcError(rpcINVALID_PARAMS);
|
||||
}
|
||||
|
||||
// unl_delete <domain>|<public_key>
|
||||
Json::Value RPCParser::parseUnlDelete(const Json::Value& jvParams)
|
||||
{
|
||||
Json::Value jvRequest;
|
||||
|
||||
jvRequest["node"] = jvParams[0u].asString();
|
||||
|
||||
return jvRequest;
|
||||
}
|
||||
//
|
||||
// parseCommand
|
||||
//
|
||||
@@ -211,7 +220,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
|
||||
// { "tx_history", &RPCParser::doTxHistory, 1, 1, false, false, optNone },
|
||||
//
|
||||
{ "unl_add", &RPCParser::parseUnlAdd, 1, 2 },
|
||||
// { "unl_delete", &RPCParser::doUnlDelete, 1, 1, true, false, optNone },
|
||||
{ "unl_delete", &RPCParser::parseUnlDelete, 1, 1 },
|
||||
{ "unl_list", &RPCParser::parseAsIs, 0, 0 },
|
||||
{ "unl_load", &RPCParser::parseAsIs, 0, 0 },
|
||||
{ "unl_network", &RPCParser::parseAsIs, 0, 0 },
|
||||
|
||||
@@ -19,6 +19,7 @@ protected:
|
||||
Json::Value parseEvented(const Json::Value& jvParams);
|
||||
|
||||
Json::Value parseUnlAdd(const Json::Value& jvParams);
|
||||
Json::Value parseUnlDelete(const Json::Value& jvParams);
|
||||
|
||||
public:
|
||||
Json::Value parseCommand(std::string strMethod, Json::Value jvParams);
|
||||
|
||||
@@ -1240,31 +1240,6 @@ Json::Value RPCHandler::doAccountTransactions(Json::Value jvRequest)
|
||||
#endif
|
||||
}
|
||||
|
||||
// {
|
||||
// node: <domain>|<node_public>,
|
||||
// comment: <comment> // optional
|
||||
// }
|
||||
Json::Value RPCHandler::doUnlAdd(Json::Value jvParams)
|
||||
{
|
||||
std::string strNode = jvParams.isMember("node") ? jvParams["node"].asString() : "";
|
||||
std::string strComment = jvParams.isMember("comment") ? jvParams["comment"].asString() : "";
|
||||
|
||||
RippleAddress raNodePublic;
|
||||
|
||||
if (raNodePublic.setNodePublic(strNode))
|
||||
{
|
||||
theApp->getUNL().nodeAddPublic(raNodePublic, UniqueNodeList::vsManual, strComment);
|
||||
|
||||
return "adding node by public key";
|
||||
}
|
||||
else
|
||||
{
|
||||
theApp->getUNL().nodeAddDomain(strNode, UniqueNodeList::vsManual, strComment);
|
||||
|
||||
return "adding node by domain";
|
||||
}
|
||||
}
|
||||
|
||||
// validation_create [<pass_phrase>|<seed>|<seed_key>]
|
||||
//
|
||||
// NOTE: It is poor security to specify secret information on the command line. This information might be saved in the command
|
||||
@@ -1532,6 +1507,73 @@ Json::Value RPCHandler::doLogLevel(Json::Value params)
|
||||
return rpcError(rpcINVALID_PARAMS);
|
||||
}
|
||||
|
||||
// {
|
||||
// node: <domain>|<node_public>,
|
||||
// comment: <comment> // optional
|
||||
// }
|
||||
Json::Value RPCHandler::doUnlAdd(Json::Value jvParams)
|
||||
{
|
||||
std::string strNode = jvParams.isMember("node") ? jvParams["node"].asString() : "";
|
||||
std::string strComment = jvParams.isMember("comment") ? jvParams["comment"].asString() : "";
|
||||
|
||||
RippleAddress raNodePublic;
|
||||
|
||||
if (raNodePublic.setNodePublic(strNode))
|
||||
{
|
||||
theApp->getUNL().nodeAddPublic(raNodePublic, UniqueNodeList::vsManual, strComment);
|
||||
|
||||
return "adding node by public key";
|
||||
}
|
||||
else
|
||||
{
|
||||
theApp->getUNL().nodeAddDomain(strNode, UniqueNodeList::vsManual, strComment);
|
||||
|
||||
return "adding node by domain";
|
||||
}
|
||||
}
|
||||
|
||||
// {
|
||||
// node: <domain>|<public_key>
|
||||
// }
|
||||
Json::Value RPCHandler::doUnlDelete(Json::Value jvParams)
|
||||
{
|
||||
std::string strNode = jvParams[0u].asString();
|
||||
|
||||
RippleAddress raNodePublic;
|
||||
|
||||
if (raNodePublic.setNodePublic(strNode))
|
||||
{
|
||||
theApp->getUNL().nodeRemovePublic(raNodePublic);
|
||||
|
||||
return "removing node by public key";
|
||||
}
|
||||
else
|
||||
{
|
||||
theApp->getUNL().nodeRemoveDomain(strNode);
|
||||
|
||||
return "removing node by domain";
|
||||
}
|
||||
}
|
||||
|
||||
Json::Value RPCHandler::doUnlList(Json::Value params)
|
||||
{
|
||||
Json::Value obj(Json::objectValue);
|
||||
|
||||
obj["unl"]=theApp->getUNL().getUnlJson();
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Populate the UNL from a local validators.txt file.
|
||||
Json::Value RPCHandler::doUnlLoad(Json::Value params)
|
||||
{
|
||||
if (theConfig.VALIDATORS_FILE.empty() || !theApp->getUNL().nodeLoad(theConfig.VALIDATORS_FILE))
|
||||
{
|
||||
return rpcError(rpcLOAD_FAILED);
|
||||
}
|
||||
|
||||
return "loading";
|
||||
}
|
||||
|
||||
|
||||
// Populate the UNL from ripple.com's validators.txt file.
|
||||
@@ -1565,47 +1607,6 @@ Json::Value RPCHandler::doStop(Json::Value)
|
||||
return SYSTEM_NAME " server stopping";
|
||||
}
|
||||
|
||||
// unl_delete <domain>|<public_key>
|
||||
Json::Value RPCHandler::doUnlDelete(Json::Value params)
|
||||
{
|
||||
std::string strNode = params[0u].asString();
|
||||
|
||||
RippleAddress naNodePublic;
|
||||
|
||||
if (naNodePublic.setNodePublic(strNode))
|
||||
{
|
||||
theApp->getUNL().nodeRemovePublic(naNodePublic);
|
||||
|
||||
return "removing node by public key";
|
||||
}
|
||||
else
|
||||
{
|
||||
theApp->getUNL().nodeRemoveDomain(strNode);
|
||||
|
||||
return "removing node by domain";
|
||||
}
|
||||
}
|
||||
|
||||
Json::Value RPCHandler::doUnlList(Json::Value params)
|
||||
{
|
||||
Json::Value obj(Json::objectValue);
|
||||
|
||||
obj["unl"]=theApp->getUNL().getUnlJson();
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Populate the UNL from a local validators.txt file.
|
||||
Json::Value RPCHandler::doUnlLoad(Json::Value params)
|
||||
{
|
||||
if (theConfig.VALIDATORS_FILE.empty() || !theApp->getUNL().nodeLoad(theConfig.VALIDATORS_FILE))
|
||||
{
|
||||
return rpcError(rpcLOAD_FAILED);
|
||||
}
|
||||
|
||||
return "loading";
|
||||
}
|
||||
|
||||
Json::Value RPCHandler::doLedgerAccept(Json::Value)
|
||||
{
|
||||
Json::Value jvResult;
|
||||
@@ -2207,8 +2208,8 @@ Json::Value RPCHandler::doCommand(Json::Value& jvParams, int iRole)
|
||||
{ "tx", &RPCHandler::doTx, 1, 1, true, false, optNone },
|
||||
{ "tx_history", &RPCHandler::doTxHistory, 1, 1, false, false, optNone },
|
||||
|
||||
{ "unl_add", &RPCHandler::doUnlAdd, 1, 2, true, false, optNone },
|
||||
{ "unl_delete", &RPCHandler::doUnlDelete, 1, 1, true, false, optNone },
|
||||
{ "unl_add", &RPCHandler::doUnlAdd, -1, -1, true, false, optNone },
|
||||
{ "unl_delete", &RPCHandler::doUnlDelete, -1, -1, true, false, optNone },
|
||||
{ "unl_list", &RPCHandler::doUnlList, -1, -1, true, false, optNone },
|
||||
{ "unl_load", &RPCHandler::doUnlLoad, -1, -1, true, false, optNone },
|
||||
{ "unl_network", &RPCHandler::doUnlNetwork, -1, -1, true, false, optNone },
|
||||
|
||||
Reference in New Issue
Block a user