From 936f52d65425cc6e287d6dbe37392dc4b19d3d83 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Mon, 3 Dec 2012 14:59:12 -0800 Subject: [PATCH] Refactor RPC unl_delete. --- src/cpp/ripple/CallRPC.cpp | 11 ++- src/cpp/ripple/CallRPC.h | 1 + src/cpp/ripple/RPCHandler.cpp | 139 +++++++++++++++++----------------- 3 files changed, 81 insertions(+), 70 deletions(-) diff --git a/src/cpp/ripple/CallRPC.cpp b/src/cpp/ripple/CallRPC.cpp index 5f9b1b9c39..8a17dec37b 100644 --- a/src/cpp/ripple/CallRPC.cpp +++ b/src/cpp/ripple/CallRPC.cpp @@ -161,6 +161,15 @@ Json::Value RPCParser::parseUnlAdd(const Json::Value& jvParams) return rpcError(rpcINVALID_PARAMS); } +// unl_delete | +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 }, diff --git a/src/cpp/ripple/CallRPC.h b/src/cpp/ripple/CallRPC.h index 2f41757679..81796733cf 100644 --- a/src/cpp/ripple/CallRPC.h +++ b/src/cpp/ripple/CallRPC.h @@ -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); diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index c37207b268..13dadb8f07 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1240,31 +1240,6 @@ Json::Value RPCHandler::doAccountTransactions(Json::Value jvRequest) #endif } -// { -// node: |, -// 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 [||] // // 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: |, +// 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: | +// } +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 | -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; @@ -2203,12 +2204,12 @@ Json::Value RPCHandler::doCommand(Json::Value& jvParams, int iRole) { "submit", &RPCHandler::doSubmit, -1, -1, false, false, optCurrent }, { "server_info", &RPCHandler::doServerInfo, -1, -1, true, false, optNone }, { "stop", &RPCHandler::doStop, -1, -1, true, false, optNone }, - { "transaction_entry", &RPCHandler::doTransactionEntry, -1, -1, false, false, optCurrent }, + { "transaction_entry", &RPCHandler::doTransactionEntry, -1, -1, false, false, optCurrent }, { "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 },