Bitcoin Core  22.99.0
P2P Digital Currency
rpcconsole.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_QT_RPCCONSOLE_H
6 #define BITCOIN_QT_RPCCONSOLE_H
7 
8 #include <qt/guiutil.h>
9 #include <qt/peertablemodel.h>
10 
11 #include <net.h>
12 
13 #include <QByteArray>
14 #include <QCompleter>
15 #include <QThread>
16 #include <QWidget>
17 
18 class ClientModel;
19 class PlatformStyle;
20 class RPCTimerInterface;
21 class WalletModel;
22 
23 namespace interfaces {
24  class Node;
25 }
26 
27 namespace Ui {
28  class RPCConsole;
29 }
30 
31 QT_BEGIN_NAMESPACE
32 class QDateTime;
33 class QMenu;
34 class QItemSelection;
35 QT_END_NAMESPACE
36 
38 class RPCConsole: public QWidget
39 {
40  Q_OBJECT
41 
42 public:
43  explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
44  ~RPCConsole();
45 
46  static bool RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr, const WalletModel* wallet_model = nullptr);
47  static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const WalletModel* wallet_model = nullptr) {
48  return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_model);
49  }
50 
51  void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);
52  void addWallet(WalletModel * const walletModel);
53  void removeWallet(WalletModel* const walletModel);
54 
55  enum MessageClass {
61  };
62 
63  enum class TabTypes {
64  INFO,
65  CONSOLE,
66  GRAPH,
67  PEERS
68  };
69 
70  std::vector<TabTypes> tabs() const { return {TabTypes::INFO, TabTypes::CONSOLE, TabTypes::GRAPH, TabTypes::PEERS}; }
71 
72  QString tabTitle(TabTypes tab_type) const;
73  QKeySequence tabShortcut(TabTypes tab_type) const;
74 
75 protected:
76  virtual bool eventFilter(QObject* obj, QEvent *event) override;
77  void keyPressEvent(QKeyEvent *) override;
78  void changeEvent(QEvent* e) override;
79 
80 private Q_SLOTS:
82  void on_tabWidget_currentChanged(int index);
86  void on_sldGraphRange_valueChanged(int value);
88  void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
89  void resizeEvent(QResizeEvent *event) override;
90  void showEvent(QShowEvent *event) override;
91  void hideEvent(QHideEvent *event) override;
93  void showPeersTableContextMenu(const QPoint& point);
95  void showBanTableContextMenu(const QPoint& point);
99  void clearSelectedNode();
101  void updateDetailWidget();
102 
103 public Q_SLOTS:
104  void clear(bool keep_prompt = false);
105  void fontBigger();
106  void fontSmaller();
107  void setFontSize(int newSize);
109  void message(int category, const QString &msg) { message(category, msg, false); }
110  void message(int category, const QString &message, bool html);
112  void setNumConnections(int count);
114  void setNetworkActive(bool networkActive);
116  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
118  void setMempoolSize(long numberOfTxs, size_t dynUsage);
120  void browseHistory(int offset);
122  void scrollToEnd();
124  void disconnectSelectedNode();
126  void banSelectedNode(int bantime);
128  void unbanSelectedNode();
130  void setTabFocus(enum TabTypes tabType);
131 
132 Q_SIGNALS:
133  // For RPC command executor
134  void cmdRequest(const QString &command, const WalletModel* wallet_model);
135 
136 private:
138  const QString yes{tr("Yes")}, no{tr("No")}, to{tr("To")}, from{tr("From")},
139  ban_for{tr("Ban for")}, na{tr("N/A")}, unknown{tr("Unknown")};
140  } const ts;
141 
142  void startExecutor();
143  void setTrafficGraphRange(int mins);
144 
146  {
152 
153  };
154 
156  Ui::RPCConsole* const ui;
158  QStringList history;
159  int historyPtr = 0;
161  QList<NodeId> cachedNodeids;
164  QMenu *peersTableContextMenu = nullptr;
165  QMenu *banTableContextMenu = nullptr;
167  QCompleter *autoCompleter = nullptr;
168  QThread thread;
170  bool m_is_executing{false};
173 
175  void updateNetworkState();
176 
178  QString TimeDurationField(uint64_t time_now, uint64_t time_at_event) const {
179  return time_at_event ? GUIUtil::formatDurationStr(time_now - time_at_event) : tr("Never");
180  }
181 
182 private Q_SLOTS:
183  void updateAlerts(const QString& warnings);
184 };
185 
186 #endif // BITCOIN_QT_RPCCONSOLE_H
RPCConsole::TabTypes::CONSOLE
@ CONSOLE
interfaces
Definition: dummywallet.cpp:11
RPCConsole::TranslatedStrings::yes
const QString yes
Definition: rpcconsole.h:138
RPCConsole::setNumConnections
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: rpcconsole.cpp:948
count
static int count
Definition: tests.c:41
RPCConsole::ADDRESS_COLUMN_WIDTH
@ ADDRESS_COLUMN_WIDTH
Definition: rpcconsole.h:147
RPCConsole::TranslatedStrings::from
const QString from
Definition: rpcconsole.h:138
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
RPCConsole::TimeDurationField
QString TimeDurationField(uint64_t time_now, uint64_t time_at_event) const
Helper for the output of a time duration field.
Definition: rpcconsole.h:178
RPCConsole::startExecutor
void startExecutor()
Definition: rpcconsole.cpp:1069
RPCTimerInterface
RPC timer "driver".
Definition: server.h:60
RPCConsole::m_peer_widget_header_state
QByteArray m_peer_widget_header_state
Definition: rpcconsole.h:171
RPCConsole::resizeEvent
void resizeEvent(QResizeEvent *event) override
Definition: rpcconsole.cpp:1204
RPCConsole::clearSelectedNode
void clearSelectedNode()
clear the selected node
Definition: rpcconsole.cpp:1302
RPCConsole::TranslatedStrings::ban_for
const QString ban_for
Definition: rpcconsole.h:139
RPCConsole::keyPressEvent
void keyPressEvent(QKeyEvent *) override
Definition: rpcconsole.cpp:892
RPCConsole::platformStyle
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:162
RPCConsole::updateNetworkState
void updateNetworkState()
Update UI with latest network info from model.
Definition: rpcconsole.cpp:935
RPCConsole::CMD_REQUEST
@ CMD_REQUEST
Definition: rpcconsole.h:58
RPCConsole::showOrHideBanTableIfRequired
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
Definition: rpcconsole.cpp:1309
RPCConsole::autoCompleter
QCompleter * autoCompleter
Definition: rpcconsole.h:167
RPCConsole::CMD_ERROR
@ CMD_ERROR
Definition: rpcconsole.h:60
RPCConsole::setTrafficGraphRange
void setTrafficGraphRange(int mins)
Definition: rpcconsole.cpp:1122
RPCConsole::RPCParseCommandLine
static bool RPCParseCommandLine(interfaces::Node *node, std::string &strResult, const std::string &strCommand, bool fExecute, std::string *const pstrFilteredOut=nullptr, const WalletModel *wallet_model=nullptr)
Split shell command line into a list of arguments and optionally execute the command(s).
Definition: rpcconsole.cpp:173
RPCConsole::ui
Ui::RPCConsole *const ui
Definition: rpcconsole.h:156
RPCConsole::fontSmaller
void fontSmaller()
Definition: rpcconsole.cpp:807
RPCConsole::m_is_executing
bool m_is_executing
Definition: rpcconsole.h:170
RPCConsole::setMempoolSize
void setMempoolSize(long numberOfTxs, size_t dynUsage)
Set size (number of transactions and memory usage) of the mempool in the UI.
Definition: rpcconsole.cpp:969
RPCConsole::tabShortcut
QKeySequence tabShortcut(TabTypes tab_type) const
Definition: rpcconsole.cpp:1329
RPCConsole::cachedNodeids
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:161
RPCConsole::addWallet
void addWallet(WalletModel *const walletModel)
RPCConsole::updateTrafficStats
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
Definition: rpcconsole.cpp:1128
RPCConsole::MC_DEBUG
@ MC_DEBUG
Definition: rpcconsole.h:57
RPCConsole::consoleFontSize
int consoleFontSize
Definition: rpcconsole.h:166
RPCConsole::updateAlerts
void updateAlerts(const QString &warnings)
Definition: rpcconsole.cpp:1341
RPCConsole::setNetworkActive
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Definition: rpcconsole.cpp:956
RPCConsole::scrollToEnd
void scrollToEnd()
Scroll console view to end.
Definition: rpcconsole.cpp:1109
RPCConsole::removeWallet
void removeWallet(WalletModel *const walletModel)
RPCConsole::showPeersTableContextMenu
void showPeersTableContextMenu(const QPoint &point)
Show custom context menu on Peers tab.
Definition: rpcconsole.cpp:1236
RPCConsole::TranslatedStrings
Definition: rpcconsole.h:137
RPCConsole::setFontSize
void setFontSize(int newSize)
Definition: rpcconsole.cpp:812
RPCConsole::RPCConsole
RPCConsole(interfaces::Node &node, const PlatformStyle *platformStyle, QWidget *parent)
Definition: rpcconsole.cpp:470
RPCConsole::cmdRequest
void cmdRequest(const QString &command, const WalletModel *wallet_model)
RPCConsole::m_last_wallet_model
WalletModel * m_last_wallet_model
Definition: rpcconsole.h:169
RPCConsole::setClientModel
void setClientModel(ClientModel *model=nullptr, int bestblock_height=0, int64_t bestblock_date=0, double verification_progress=0.0)
Definition: rpcconsole.cpp:634
RPCConsole::CMD_REPLY
@ CMD_REPLY
Definition: rpcconsole.h:59
RPCConsole::showEvent
void showEvent(QShowEvent *event) override
Definition: rpcconsole.cpp:1209
RPCConsole::on_tabWidget_currentChanged
void on_tabWidget_currentChanged(int index)
Definition: rpcconsole.cpp:1097
RPCConsole::disconnectSelectedNode
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
Definition: rpcconsole.cpp:1250
RPCConsole
Local Bitcoin RPC console.
Definition: rpcconsole.h:38
RPCConsole::MessageClass
MessageClass
Definition: rpcconsole.h:55
RPCConsole::TranslatedStrings::to
const QString to
Definition: rpcconsole.h:138
RPCConsole::ColumnWidths
ColumnWidths
Definition: rpcconsole.h:145
RPCConsole::BANSUBNET_COLUMN_WIDTH
@ BANSUBNET_COLUMN_WIDTH
Definition: rpcconsole.h:150
guiutil.h
RPCConsole::MC_ERROR
@ MC_ERROR
Definition: rpcconsole.h:56
RPCConsole::clear
void clear(bool keep_prompt=false)
Definition: rpcconsole.cpp:837
RPCConsole::PING_COLUMN_WIDTH
@ PING_COLUMN_WIDTH
Definition: rpcconsole.h:149
RPCConsole::showBanTableContextMenu
void showBanTableContextMenu(const QPoint &point)
Show custom context menu on Bans tab.
Definition: rpcconsole.cpp:1243
RPCConsole::SUBVERSION_COLUMN_WIDTH
@ SUBVERSION_COLUMN_WIDTH
Definition: rpcconsole.h:148
RPCConsole::BANTIME_COLUMN_WIDTH
@ BANTIME_COLUMN_WIDTH
Definition: rpcconsole.h:151
RPCConsole::hideEvent
void hideEvent(QHideEvent *event) override
Definition: rpcconsole.cpp:1220
RPCConsole::updateDetailWidget
void updateDetailWidget()
show detailed information on ui about selected node
Definition: rpcconsole.cpp:1134
RPCConsole::m_banlist_widget_header_state
QByteArray m_banlist_widget_header_state
Definition: rpcconsole.h:172
RPCConsole::m_node
interfaces::Node & m_node
Definition: rpcconsole.h:155
RPCConsole::thread
QThread thread
Definition: rpcconsole.h:168
RPCConsole::TabTypes::GRAPH
@ GRAPH
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:54
RPCConsole::tabTitle
QString tabTitle(TabTypes tab_type) const
Definition: rpcconsole.cpp:1324
RPCConsole::TranslatedStrings::na
const QString na
Definition: rpcconsole.h:139
RPCConsole::~RPCConsole
~RPCConsole()
Definition: rpcconsole.cpp:566
RPCConsole::history
QStringList history
Definition: rpcconsole.h:158
RPCConsole::TranslatedStrings::unknown
const QString unknown
Definition: rpcconsole.h:139
RPCConsole::TabTypes
TabTypes
Definition: rpcconsole.h:63
RPCConsole::cmdBeforeBrowsing
QString cmdBeforeBrowsing
Definition: rpcconsole.h:160
ClientModel
Model for Bitcoin network client.
Definition: clientmodel.h:47
RPCConsole::eventFilter
virtual bool eventFilter(QObject *obj, QEvent *event) override
Definition: rpcconsole.cpp:589
Ui
Definition: addressbookpage.h:14
RPCConsole::setTabFocus
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
Definition: rpcconsole.cpp:1319
RPCConsole::on_lineEdit_returnPressed
void on_lineEdit_returnPressed()
Definition: rpcconsole.cpp:979
RPCConsole::peersTableContextMenu
QMenu * peersTableContextMenu
Definition: rpcconsole.h:164
RPCConsole::RPCExecuteCommandLine
static bool RPCExecuteCommandLine(interfaces::Node &node, std::string &strResult, const std::string &strCommand, std::string *const pstrFilteredOut=nullptr, const WalletModel *wallet_model=nullptr)
Definition: rpcconsole.h:47
RPCConsole::message
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:109
node
Definition: interfaces.cpp:68
RPCConsole::on_openDebugLogfileButton_clicked
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
Definition: rpcconsole.cpp:1104
GUIUtil::formatDurationStr
QString formatDurationStr(int secs)
Convert seconds into a QString with days, hours, mins, secs.
Definition: guiutil.cpp:689
RPCConsole::browseHistory
void browseHistory(int offset)
Go forward or back in history.
Definition: rpcconsole.cpp:1048
RPCConsole::historyPtr
int historyPtr
Definition: rpcconsole.h:159
RPCConsole::on_sldGraphRange_valueChanged
void on_sldGraphRange_valueChanged(int value)
change the time range of the network traffic graph
Definition: rpcconsole.cpp:1115
RPCConsole::setNumBlocks
void setNumBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, bool headers)
Set number of blocks and last block date shown in the UI.
Definition: rpcconsole.cpp:961
RPCConsole::fontBigger
void fontBigger()
Definition: rpcconsole.cpp:802
RPCConsole::TranslatedStrings::no
const QString no
Definition: rpcconsole.h:138
RPCConsole::changeEvent
void changeEvent(QEvent *e) override
Definition: rpcconsole.cpp:900
peertablemodel.h
PlatformStyle
Definition: platformstyle.h:13
RPCConsole::unbanSelectedNode
void unbanSelectedNode()
Unban a selected node on the Bans tab.
Definition: rpcconsole.cpp:1281
RPCConsole::ts
struct RPCConsole::TranslatedStrings ts
RPCConsole::tabs
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:70
RPCConsole::rpcTimerInterface
RPCTimerInterface * rpcTimerInterface
Definition: rpcconsole.h:163
RPCConsole::banSelectedNode
void banSelectedNode(int bantime)
Ban a selected node on the Peers tab.
Definition: rpcconsole.cpp:1264
RPCConsole::clientModel
ClientModel * clientModel
Definition: rpcconsole.h:157
RPCConsole::banTableContextMenu
QMenu * banTableContextMenu
Definition: rpcconsole.h:165
RPCConsole::TabTypes::INFO
@ INFO
RPCConsole::TabTypes::PEERS
@ PEERS