Skip to content

Commit 7e04b09

Browse files
committed
gui: Support block hash alias in console
Add support to use @best or @height instead of block hash in the RPC console. The approach used is to simply replace those expressions with the relevant RPC method.
1 parent 564e1ab commit 7e04b09

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/qt/rpcconsole.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <QKeyEvent>
3333
#include <QMenu>
3434
#include <QMessageBox>
35+
#include <QRegularExpression>
3536
#include <QScreen>
3637
#include <QScrollBar>
3738
#include <QSettings>
@@ -81,7 +82,7 @@ class RPCExecutor : public QObject
8182
explicit RPCExecutor(interfaces::Node& node) : m_node(node) {}
8283

8384
public Q_SLOTS:
84-
void request(const QString &command, const WalletModel* wallet_model);
85+
void request(QString command, const WalletModel* wallet_model);
8586

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

386-
void RPCExecutor::request(const QString &command, const WalletModel* wallet_model)
387+
void RPCExecutor::request(QString command, const WalletModel* wallet_model)
387388
{
388389
try
389390
{
391+
command.replace(QRegularExpression("@best"), "getbestblockhash()");
392+
command.replace(QRegularExpression("@([\\d]+)"), "getblockhash(\\1)");
393+
390394
std::string result;
391395
std::string executableCommand = command.toStdString() + "\n";
392396

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

412416
"Results without keys can be queried with an integer in brackets using the parenthesized syntax.\n"
413-
" example: getblock(getblockhash(0),1)[tx][0]\n\n")));
417+
" example: getblock(getblockhash(0),1)[tx][0]\n\n"
418+
419+
"Aliases for block hash can be used."
420+
" example: getblockheader @best\n"
421+
" getblockheader @123\n\n")));
414422
return;
415423
}
416424
if (!RPCConsole::RPCExecuteCommandLine(m_node, result, executableCommand, nullptr, wallet_model)) {

0 commit comments

Comments
 (0)