Changeset View
Changeset View
Standalone View
Standalone View
src/qt/rpcconsole.cpp
Show First 20 Lines • Show All 408 Lines • ▼ Show 20 Lines | switch (state) // final state | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
void RPCExecutor::request(const QString &command) { | void RPCExecutor::request(const QString &command) { | ||||
try { | try { | ||||
std::string result; | std::string result; | ||||
std::string executableCommand = command.toStdString() + "\n"; | std::string executableCommand = command.toStdString() + "\n"; | ||||
// Catch the console-only-help command before RPC call is executed and | |||||
// reply with help text as-if a RPC reply. | |||||
if (executableCommand == "help-console\n") { | |||||
Q_EMIT reply( | |||||
RPCConsole::CMD_REPLY, | |||||
QString(("\n" | |||||
"This console accepts RPC commands using the standard " | |||||
"syntax.\n" | |||||
" example: getblockhash 0\n\n" | |||||
"This console can also accept RPC commands using " | |||||
"parenthesized syntax.\n" | |||||
" example: getblockhash(0)\n\n" | |||||
"Commands may be nested when specified with the " | |||||
"parenthesized syntax.\n" | |||||
" example: getblock(getblockhash(0) 1)\n\n" | |||||
"A space or a comma can be used to delimit arguments " | |||||
"for either syntax.\n" | |||||
" example: getblockhash 0\n" | |||||
" getblockhash,0\n\n" | |||||
"Named results can be queried with a non-quoted key " | |||||
"string in brackets.\n" | |||||
" example: getblock(getblockhash(0) true)[tx]\n\n" | |||||
"Results without keys can be queried using an integer " | |||||
"in brackets.\n" | |||||
" example: " | |||||
"getblock(getblockhash(0),true)[tx][0]\n\n"))); | |||||
return; | |||||
} | |||||
if (!RPCConsole::RPCExecuteCommandLine(result, executableCommand)) { | if (!RPCConsole::RPCExecuteCommandLine(result, executableCommand)) { | ||||
Q_EMIT reply(RPCConsole::CMD_ERROR, | Q_EMIT reply(RPCConsole::CMD_ERROR, | ||||
QString("Parse error: unbalanced ' or \"")); | QString("Parse error: unbalanced ' or \"")); | ||||
return; | return; | ||||
} | } | ||||
Q_EMIT reply(RPCConsole::CMD_REPLY, QString::fromStdString(result)); | Q_EMIT reply(RPCConsole::CMD_REPLY, QString::fromStdString(result)); | ||||
} catch (UniValue &objError) { | } catch (UniValue &objError) { | ||||
try // Nice formatting for standard-format error | try // Nice formatting for standard-format error | ||||
{ | { | ||||
int code = find_value(objError, "code").get_int(); | int code = find_value(objError, "code").get_int(); | ||||
std::string message = find_value(objError, "message").get_str(); | std::string message = find_value(objError, "message").get_str(); | ||||
Q_EMIT reply(RPCConsole::CMD_ERROR, | Q_EMIT reply(RPCConsole::CMD_ERROR, | ||||
QString::fromStdString(message) + " (code " + | QString::fromStdString(message) + " (code " + | ||||
▲ Show 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | if (model && clientModel->getPeerTableModel() && | ||||
// Setup autocomplete and attach it | // Setup autocomplete and attach it | ||||
QStringList wordList; | QStringList wordList; | ||||
std::vector<std::string> commandList = tableRPC.listCommands(); | std::vector<std::string> commandList = tableRPC.listCommands(); | ||||
for (size_t i = 0; i < commandList.size(); ++i) { | for (size_t i = 0; i < commandList.size(); ++i) { | ||||
wordList << commandList[i].c_str(); | wordList << commandList[i].c_str(); | ||||
wordList << ("help " + commandList[i]).c_str(); | wordList << ("help " + commandList[i]).c_str(); | ||||
} | } | ||||
wordList << "help-console"; | |||||
wordList.sort(); | wordList.sort(); | ||||
autoCompleter = new QCompleter(wordList, this); | autoCompleter = new QCompleter(wordList, this); | ||||
autoCompleter->setModelSorting(QCompleter::CaseSensitivelySortedModel); | autoCompleter->setModelSorting(QCompleter::CaseSensitivelySortedModel); | ||||
ui->lineEdit->setCompleter(autoCompleter); | ui->lineEdit->setCompleter(autoCompleter); | ||||
autoCompleter->popup()->installEventFilter(this); | autoCompleter->popup()->installEventFilter(this); | ||||
// Start thread to execute RPC commands. | // Start thread to execute RPC commands. | ||||
startExecutor(); | startExecutor(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | #endif | ||||
message(CMD_REPLY, | message(CMD_REPLY, | ||||
(tr("Welcome to the %1 RPC console.").arg(tr(PACKAGE_NAME)) + | (tr("Welcome to the %1 RPC console.").arg(tr(PACKAGE_NAME)) + | ||||
"<br>" + | "<br>" + | ||||
tr("Use up and down arrows to navigate history, and " | tr("Use up and down arrows to navigate history, and " | ||||
"%1 to clear screen.") | "%1 to clear screen.") | ||||
.arg("<b>" + clsKey + "</b>") + | .arg("<b>" + clsKey + "</b>") + | ||||
"<br>" + | "<br>" + | ||||
tr("Type <b>help</b> for an overview of available commands.")) + | tr("Type %1 for an overview of available commands.") | ||||
"<br><span class=\"secwarning\">" + | .arg("<b>help</b>") + | ||||
"<br>" + | |||||
tr("For more information on using this console type %1.") | |||||
.arg("<b>help-console</b>") + | |||||
"<br><span class=\"secwarning\"><br>" + | |||||
tr("WARNING: Scammers have been active, telling users to type " | tr("WARNING: Scammers have been active, telling users to type " | ||||
"commands here, stealing their wallet contents. Do not use " | "commands here, stealing their wallet contents. Do not use " | ||||
"this console without fully understanding the ramification " | "this console without fully understanding the ramification " | ||||
"of a command.") + | "of a command.") + | ||||
"</span>", | "</span>"), | ||||
true); | true); | ||||
} | } | ||||
void RPCConsole::keyPressEvent(QKeyEvent *event) { | void RPCConsole::keyPressEvent(QKeyEvent *event) { | ||||
if (windowType() != Qt::Widget && event->key() == Qt::Key_Escape) { | if (windowType() != Qt::Widget && event->key() == Qt::Key_Escape) { | ||||
close(); | close(); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 450 Lines • Show Last 20 Lines |