Skip to content

Commit e2d9213

Browse files
committed
Qt/RPCConsole: Make it possible to parse a command without executing it
1 parent 1755c04 commit e2d9213

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/qt/rpcconsole.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ class QtRPCTimerInterface: public RPCTimerInterface
136136
#include "rpcconsole.moc"
137137

138138
/**
139-
* Split shell command line into a list of arguments and execute the command(s).
139+
* Split shell command line into a list of arguments and optionally execute the command(s).
140140
* Aims to emulate \c bash and friends.
141141
*
142-
* - Command nesting is possible with brackets [example: validateaddress(getnewaddress())]
142+
* - Command nesting is possible with parenthesis; for example: validateaddress(getnewaddress())
143143
* - Arguments are delimited with whitespace or comma
144144
* - Extra whitespace at the beginning and end and between arguments will be ignored
145145
* - Text can be "double" or 'single' quoted
@@ -150,9 +150,10 @@ class QtRPCTimerInterface: public RPCTimerInterface
150150
*
151151
* @param[out] result stringified Result from the executed command(chain)
152152
* @param[in] strCommand Command line to split
153+
* @param[in] fExecute set true if you want the command to be executed
153154
*/
154155

155-
bool RPCConsole::RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand)
156+
bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &strCommand, const bool fExecute)
156157
{
157158
std::vector< std::vector<std::string> > stack;
158159
stack.push_back(std::vector<std::string>());
@@ -196,7 +197,7 @@ bool RPCConsole::RPCExecuteCommandLine(std::string &strResult, const std::string
196197
curarg += ch;
197198
break;
198199
}
199-
if (curarg.size())
200+
if (curarg.size() && fExecute)
200201
{
201202
// if we have a value query, query arrays with index and objects with a string key
202203
UniValue subelement;
@@ -271,13 +272,14 @@ bool RPCConsole::RPCExecuteCommandLine(std::string &strResult, const std::string
271272
}
272273
if ((ch == ')' || ch == '\n') && stack.size() > 0)
273274
{
274-
std::string strPrint;
275-
// Convert argument list to JSON objects in method-dependent way,
276-
// and pass it along with the method name to the dispatcher.
277-
JSONRPCRequest req;
278-
req.params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
279-
req.strMethod = stack.back()[0];
280-
lastResult = tableRPC.execute(req);
275+
if (fExecute) {
276+
// Convert argument list to JSON objects in method-dependent way,
277+
// and pass it along with the method name to the dispatcher.
278+
JSONRPCRequest req;
279+
req.params = RPCConvertValues(stack.back()[0], std::vector<std::string>(stack.back().begin() + 1, stack.back().end()));
280+
req.strMethod = stack.back()[0];
281+
lastResult = tableRPC.execute(req);
282+
}
281283

282284
state = STATE_COMMAND_EXECUTED;
283285
curarg.clear();

src/qt/rpcconsole.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ class RPCConsole: public QWidget
3636
explicit RPCConsole(const PlatformStyle *platformStyle, QWidget *parent);
3737
~RPCConsole();
3838

39-
static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand);
39+
static bool RPCParseCommandLine(std::string &strResult, const std::string &strCommand, bool fExecute);
40+
static bool RPCExecuteCommandLine(std::string &strResult, const std::string &strCommand) {
41+
return RPCParseCommandLine(strResult, strCommand, true);
42+
}
4043

4144
void setClientModel(ClientModel *model);
4245

0 commit comments

Comments
 (0)