|
48 | 48 | #include <QVariant> |
49 | 49 |
|
50 | 50 | #include <chrono> |
| 51 | +#include <regex> |
51 | 52 |
|
52 | 53 | const int CONSOLE_HISTORY = 50; |
53 | 54 | const int INITIAL_TRAFFIC_GRAPH_MINS = 30; |
@@ -414,7 +415,34 @@ void RPCExecutor::request(const QString &command, const WalletModel* wallet_mode |
414 | 415 | { |
415 | 416 | std::string result; |
416 | 417 | std::string executableCommand = command.toStdString() + "\n"; |
417 | | - |
| 418 | + std::regex validRegex("generate\\s*[\\(]?\\s*(\\d+)?\\s*[,]?\\s*(\\d+)?\\s*[\\)]?\\s*"); |
| 419 | + std::regex invalidRegex("generate[\\s\\(]+.*"); |
| 420 | + std::smatch match; |
| 421 | + if (std::regex_match(executableCommand, match, validRegex)) { |
| 422 | + std::string nblocks=match[1]; |
| 423 | + std::string maxtries=match[2]; |
| 424 | + if (nblocks=="") nblocks = "1"; |
| 425 | + if (maxtries=="") maxtries = "1000000"; |
| 426 | + if (!RPCConsole::RPCExecuteCommandLine(m_node, result, "getnewaddress\n", nullptr, wallet_model)) { |
| 427 | + Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \"")); |
| 428 | + } |
| 429 | + else { |
| 430 | + std::string address = result; |
| 431 | + if (!RPCConsole::RPCExecuteCommandLine(m_node, result, "generatetoaddress " + nblocks + " " + address + " " + maxtries + "\n", nullptr, wallet_model)) { |
| 432 | + Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error: unbalanced ' or \"")); |
| 433 | + } else { |
| 434 | + std::string answer = "{\n \"address\": \"" + address + "\",\n \"blocks\": "+ result + "\n}"; |
| 435 | + Q_EMIT reply(RPCConsole::CMD_REPLY, QString::fromStdString( "\n" + answer + "\n\n" )); |
| 436 | + } |
| 437 | + } |
| 438 | + return; |
| 439 | + }else { |
| 440 | + //If the previous regex failed, but the following is valid - i.e. starts with 'generate' - there is a syntax error with parameters |
| 441 | + if (std::regex_search(executableCommand, match, invalidRegex)) { |
| 442 | + Q_EMIT reply(RPCConsole::CMD_ERROR, QString("Parse error.")); |
| 443 | + return; |
| 444 | + } |
| 445 | + } |
418 | 446 | // Catch the console-only-help command before RPC call is executed and reply with help text as-if a RPC reply. |
419 | 447 | if(executableCommand == "help-console\n") { |
420 | 448 | Q_EMIT reply(RPCConsole::CMD_REPLY, QString(("\n" |
|
0 commit comments