aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2016-11-16 10:56:32 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2016-12-29 11:43:29 +0000
commite2d9213c32e51fe197756709e24c6694f28bf842 (patch)
tree24a4bedc19ccf827689099b27d3449bef6658935
parent1755c04576eb42467ba16af9f2658e12b707b7d0 (diff)
Qt/RPCConsole: Make it possible to parse a command without executing it
-rw-r--r--src/qt/rpcconsole.cpp24
-rw-r--r--src/qt/rpcconsole.h5
2 files changed, 17 insertions, 12 deletions
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
index c53ae53c64..f453833416 100644
--- a/src/qt/rpcconsole.cpp
+++ b/src/qt/rpcconsole.cpp
@@ -136,10 +136,10 @@ public:
#include "rpcconsole.moc"
/**
- * Split shell command line into a list of arguments and execute the command(s).
+ * Split shell command line into a list of arguments and optionally execute the command(s).
* Aims to emulate \c bash and friends.
*
- * - Command nesting is possible with brackets [example: validateaddress(getnewaddress())]
+ * - Command nesting is possible with parenthesis; for example: validateaddress(getnewaddress())
* - Arguments are delimited with whitespace or comma
* - Extra whitespace at the beginning and end and between arguments will be ignored
* - Text can be "double" or 'single' quoted
@@ -150,9 +150,10 @@ public:
*
* @param[out] result stringified Result from the executed command(chain)
* @param[in] strCommand Command line to split
+ * @param[in] fExecute set true if you want the command to be executed
*/
-bool RPCConsole::RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand)
+bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &strCommand, const bool fExecute)
{
std::vector< std::vector<std::string> > stack;
stack.push_back(std::vector<std::string>());
@@ -196,7 +197,7 @@ bool RPCConsole::RPCExecuteCommandLine(std::string &strResult, const std::string
curarg += ch;
break;
}
- if (curarg.size())
+ if (curarg.size() && fExecute)
{
// if we have a value query, query arrays with index and objects with a string key
UniValue subelement;
@@ -271,13 +272,14 @@ bool RPCConsole::RPCExecuteCommandLine(std::string &strResult, const std::string
}
if ((ch == ')' || ch == '\n') && stack.size() > 0)
{
- std::string strPrint;
- // Convert argument list to JSON objects in method-dependent way,
- // and pass it along with the method name to the dispatcher.
- JSONRPCRequest req;
- req.params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
- req.strMethod = stack.back()[0];
- lastResult = tableRPC.execute(req);
+ if (fExecute) {
+ // Convert argument list to JSON objects in method-dependent way,
+ // and pass it along with the method name to the dispatcher.
+ JSONRPCRequest req;
+ req.params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
+ req.strMethod = stack.back()[0];
+ lastResult = tableRPC.execute(req);
+ }
state = STATE_COMMAND_EXECUTED;
curarg.clear();
diff --git a/src/qt/rpcconsole.h b/src/qt/rpcconsole.h
index e1698711da..9567341ae2 100644
--- a/src/qt/rpcconsole.h
+++ b/src/qt/rpcconsole.h
@@ -36,7 +36,10 @@ public:
explicit RPCConsole(const PlatformStyle *platformStyle, QWidget *parent);
~RPCConsole();
- static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand);
+ static bool RPCParseCommandLine(std::string &strResult, const std::string &strCommand, bool fExecute);
+ static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand) {
+ return RPCParseCommandLine(strResult, strCommand, true);
+ }
void setClientModel(ClientModel *model);