Skip to content

Commit

Permalink
Merge 684e687 into merged_master (Bitcoin PR bitcoin-core/gui#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
apoelstra committed Jul 19, 2021
2 parents 7f55243 + 684e687 commit c2b9c35
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 43 deletions.
104 changes: 62 additions & 42 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,57 +930,71 @@ void RPCConsole::setMempoolSize(long numberOfTxs, size_t dynUsage)

void RPCConsole::on_lineEdit_returnPressed()
{
QString cmd = ui->lineEdit->text();
QString cmd = ui->lineEdit->text().trimmed();

if(!cmd.isEmpty())
{
std::string strFilteredCmd;
try {
std::string dummy;
if (!RPCParseCommandLine(nullptr, dummy, cmd.toStdString(), false, &strFilteredCmd)) {
// Failed to parse command, so we cannot even filter it for the history
throw std::runtime_error("Invalid command line");
}
} catch (const std::exception& e) {
QMessageBox::critical(this, "Error", QString("Error: ") + QString::fromStdString(e.what()));
return;
if (cmd.isEmpty()) {
return;
}

std::string strFilteredCmd;
try {
std::string dummy;
if (!RPCParseCommandLine(nullptr, dummy, cmd.toStdString(), false, &strFilteredCmd)) {
// Failed to parse command, so we cannot even filter it for the history
throw std::runtime_error("Invalid command line");
}
} catch (const std::exception& e) {
QMessageBox::critical(this, "Error", QString("Error: ") + QString::fromStdString(e.what()));
return;
}

// A special case allows to request shutdown even a long-running command is executed.
if (cmd == QLatin1String("stop")) {
std::string dummy;
RPCExecuteCommandLine(m_node, dummy, cmd.toStdString());
return;
}

ui->lineEdit->clear();
if (m_is_executing) {
return;
}

cmdBeforeBrowsing = QString();
ui->lineEdit->clear();

#ifdef ENABLE_WALLET
WalletModel* wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
WalletModel* wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();

if (m_last_wallet_model != wallet_model) {
if (wallet_model) {
message(CMD_REQUEST, tr("Executing command using \"%1\" wallet").arg(wallet_model->getWalletName()));
} else {
message(CMD_REQUEST, tr("Executing command without any wallet"));
}
m_last_wallet_model = wallet_model;
if (m_last_wallet_model != wallet_model) {
if (wallet_model) {
message(CMD_REQUEST, tr("Executing command using \"%1\" wallet").arg(wallet_model->getWalletName()));
} else {
message(CMD_REQUEST, tr("Executing command without any wallet"));
}
#endif

message(CMD_REQUEST, QString::fromStdString(strFilteredCmd));
Q_EMIT cmdRequest(cmd, m_last_wallet_model);

cmd = QString::fromStdString(strFilteredCmd);

// Remove command, if already in history
history.removeOne(cmd);
// Append command to history
history.append(cmd);
// Enforce maximum history size
while(history.size() > CONSOLE_HISTORY)
history.removeFirst();
// Set pointer to end of history
historyPtr = history.size();
m_last_wallet_model = wallet_model;
}
#endif // ENABLE_WALLET

// Scroll console view to end
scrollToEnd();
message(CMD_REQUEST, QString::fromStdString(strFilteredCmd));
//: A console message indicating an entered command is currently being executed.
message(CMD_REPLY, tr("Executing…"));
m_is_executing = true;
Q_EMIT cmdRequest(cmd, m_last_wallet_model);

cmd = QString::fromStdString(strFilteredCmd);

// Remove command, if already in history
history.removeOne(cmd);
// Append command to history
history.append(cmd);
// Enforce maximum history size
while (history.size() > CONSOLE_HISTORY) {
history.removeFirst();
}
// Set pointer to end of history
historyPtr = history.size();

// Scroll console view to end
scrollToEnd();
}

void RPCConsole::browseHistory(int offset)
Expand Down Expand Up @@ -1010,7 +1024,13 @@ void RPCConsole::startExecutor()
executor->moveToThread(&thread);

// Replies from executor object must go to this object
connect(executor, &RPCExecutor::reply, this, qOverload<int, const QString&>(&RPCConsole::message));
connect(executor, &RPCExecutor::reply, this, [this](int category, const QString& command) {
// Remove "Executing…" message.
ui->messagesWidget->undo();
message(category, command);
scrollToEnd();
m_is_executing = false;
});

// Requests from this object must go to executor
connect(this, &RPCConsole::cmdRequest, executor, &RPCExecutor::request);
Expand Down
1 change: 1 addition & 0 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public Q_SLOTS:
QCompleter *autoCompleter = nullptr;
QThread thread;
WalletModel* m_last_wallet_model{nullptr};
bool m_is_executing{false};

/** Update UI with latest network info from model. */
void updateNetworkState();
Expand Down
2 changes: 1 addition & 1 deletion src/qt/test/apptests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void TestRpcCommand(RPCConsole* console)
QTest::keyClicks(lineEdit, "getblockchaininfo");
QTest::keyClick(lineEdit, Qt::Key_Return);
QVERIFY(mw_spy.wait(1000));
QCOMPARE(mw_spy.count(), 2);
QCOMPARE(mw_spy.count(), 4);
QString output = messagesWidget->toPlainText();
UniValue value;
value.read(output.right(output.size() - output.lastIndexOf(QChar::ObjectReplacementCharacter) - 1).toStdString());
Expand Down

0 comments on commit c2b9c35

Please sign in to comment.