Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QKeyEvent>
#include <QMenu>
#include <QMessageBox>
#include <QRegExp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this warrants adding QRegExp to the project

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have it. Maybe you are thinking of QRegularExpression?

#include <QScreen>
#include <QScrollBar>
#include <QSettings>
Expand Down Expand Up @@ -81,7 +82,7 @@ class RPCExecutor : public QObject
explicit RPCExecutor(interfaces::Node& node) : m_node(node) {}

public Q_SLOTS:
void request(const QString &command, const WalletModel* wallet_model);
void request(QString command, const WalletModel* wallet_model);

Q_SIGNALS:
void reply(int category, const QString &command);
Expand Down Expand Up @@ -383,10 +384,13 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
}
}

void RPCExecutor::request(const QString &command, const WalletModel* wallet_model)
void RPCExecutor::request(QString command, const WalletModel* wallet_model)
{
try
{
command.replace(QRegExp("@best"), "getbestblockhash()");
command.replace(QRegExp("@([\\d]+)"), "getblockhash(\\1)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to have "\b@best\b" (and likewise for digits) so you don't replace "[email protected]" in a label or similar?

Comment on lines +391 to +392
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The opening word boundary doesn't work with a "word" that starts with the @ character. But the closing word boundary indeed improves behavior and error handling:

Suggested change
command.replace(QRegExp("@best"), "getbestblockhash()");
command.replace(QRegExp("@([\\d]+)"), "getblockhash(\\1)");
command.replace(QRegExp("@best\\b"), "getbestblockhash()");
command.replace(QRegExp("@([\\d]+)\\b"), "getblockhash(\\1)");

Comment on lines +391 to +392
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think RPCParseCommandLine would be the proper place to do this.


std::string result;
std::string executableCommand = command.toStdString() + "\n";

Expand All @@ -410,7 +414,11 @@ void RPCExecutor::request(const QString &command, const WalletModel* wallet_mode
" example: getblock(getblockhash(0) 1)[tx]\n\n"

"Results without keys can be queried with an integer in brackets using the parenthesized syntax.\n"
" example: getblock(getblockhash(0),1)[tx][0]\n\n")));
" example: getblock(getblockhash(0),1)[tx][0]\n\n"

"Aliases for block hash can be used."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Aliases for block hash can be used."
"Aliases for block hash can be used.\n"

" example: getblockheader @best\n"
" getblockheader @123\n\n")));
return;
}
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_model)) {
Expand Down