Bitcoin Core  22.0.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
void addWallet(WalletModel *const walletModel)
Local Bitcoin RPC console.
Definition: rpcconsole.h:38
RPC timer "driver".
Definition: server.h:60
QString cmdBeforeBrowsing
Definition: rpcconsole.h:160
void on_lineEdit_returnPressed()
Definition: rpcconsole.cpp:967
void showPeersTableContextMenu(const QPoint &point)
Show custom context menu on Peers tab.
WalletModel * m_last_wallet_model
Definition: rpcconsole.h:169
void updateDetailWidget()
show detailed information on ui about selected node
void setClientModel(ClientModel *model=nullptr, int bestblock_height=0, int64_t bestblock_date=0, double verification_progress=0.0)
Definition: rpcconsole.cpp:634
QStringList history
Definition: rpcconsole.h:158
interfaces::Node & m_node
Definition: rpcconsole.h:155
QThread thread
Definition: rpcconsole.h:168
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Definition: rpcconsole.cpp:944
void scrollToEnd()
Scroll console view to end.
void clearSelectedNode()
clear the selected node
RPCConsole(interfaces::Node &node, const PlatformStyle *platformStyle, QWidget *parent)
Definition: rpcconsole.cpp:470
void fontSmaller()
Definition: rpcconsole.cpp:795
void changeEvent(QEvent *e) override
Definition: rpcconsole.cpp:888
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
void on_tabWidget_currentChanged(int index)
QString tabTitle(TabTypes tab_type) const
void clear(bool keep_prompt=false)
Definition: rpcconsole.cpp:825
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:162
struct RPCConsole::TranslatedStrings ts
QMenu * peersTableContextMenu
Definition: rpcconsole.h:164
void browseHistory(int offset)
Go forward or back in history.
void resizeEvent(QResizeEvent *event) override
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:109
QString formatDurationStr(int secs)
Convert seconds into a QString with days, hours, mins, secs.
Definition: guiutil.cpp:689
QByteArray m_banlist_widget_header_state
Definition: rpcconsole.h:172
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
bool m_is_executing
Definition: rpcconsole.h:170
int historyPtr
Definition: rpcconsole.h:159
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:70
RPCTimerInterface * rpcTimerInterface
Definition: rpcconsole.h:163
void updateNetworkState()
Update UI with latest network info from model.
Definition: rpcconsole.cpp:923
QByteArray m_peer_widget_header_state
Definition: rpcconsole.h:171
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
Model for Bitcoin network client.
Definition: clientmodel.h:47
void unbanSelectedNode()
Unban a selected node on the Bans tab.
ClientModel * clientModel
Definition: rpcconsole.h:157
QMenu * banTableContextMenu
Definition: rpcconsole.h:165
void setTrafficGraphRange(int mins)
QKeySequence tabShortcut(TabTypes tab_type) const
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
void fontBigger()
Definition: rpcconsole.cpp:790
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:161
void setMempoolSize(long numberOfTxs, size_t dynUsage)
Set size (number of transactions and memory usage) of the mempool in the UI.
Definition: rpcconsole.cpp:957
void setFontSize(int newSize)
Definition: rpcconsole.cpp:800
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: rpcconsole.cpp:936
void startExecutor()
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
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
void on_sldGraphRange_valueChanged(int value)
change the time range of the network traffic graph
void banSelectedNode(int bantime)
Ban a selected node on the Peers tab.
Ui::RPCConsole *const ui
Definition: rpcconsole.h:156
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
void updateAlerts(const QString &warnings)
void removeWallet(WalletModel *const walletModel)
static int count
Definition: tests.c:41
int consoleFontSize
Definition: rpcconsole.h:166
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
void cmdRequest(const QString &command, const WalletModel *wallet_model)
void showEvent(QShowEvent *event) override
QCompleter * autoCompleter
Definition: rpcconsole.h:167
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:54
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:949
void showBanTableContextMenu(const QPoint &point)
Show custom context menu on Bans tab.
void keyPressEvent(QKeyEvent *) override
Definition: rpcconsole.cpp:880
void hideEvent(QHideEvent *event) override
virtual bool eventFilter(QObject *obj, QEvent *event) override
Definition: rpcconsole.cpp:589