Bitcoin Core  21.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 <QWidget>
14 #include <QCompleter>
15 #include <QThread>
16 
17 class ClientModel;
18 class PlatformStyle;
19 class RPCTimerInterface;
20 class WalletModel;
21 
22 namespace interfaces {
23  class Node;
24 }
25 
26 namespace Ui {
27  class RPCConsole;
28 }
29 
30 QT_BEGIN_NAMESPACE
31 class QDateTime;
32 class QMenu;
33 class QItemSelection;
34 QT_END_NAMESPACE
35 
37 class RPCConsole: public QWidget
38 {
39  Q_OBJECT
40 
41 public:
42  explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
43  ~RPCConsole();
44 
45  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);
46  static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const WalletModel* wallet_model = nullptr) {
47  return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_model);
48  }
49 
50  void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);
51  void addWallet(WalletModel * const walletModel);
52  void removeWallet(WalletModel* const walletModel);
53 
54  enum MessageClass {
59  CMD_ERROR
60  };
61 
62  enum class TabTypes {
63  INFO,
64  CONSOLE,
65  GRAPH,
66  PEERS
67  };
68 
69  std::vector<TabTypes> tabs() const { return {TabTypes::INFO, TabTypes::CONSOLE, TabTypes::GRAPH, TabTypes::PEERS}; }
70 
71  QString tabTitle(TabTypes tab_type) const;
72  QKeySequence tabShortcut(TabTypes tab_type) const;
73 
74 protected:
75  virtual bool eventFilter(QObject* obj, QEvent *event) override;
76  void keyPressEvent(QKeyEvent *) override;
77 
78 private Q_SLOTS:
79  void on_lineEdit_returnPressed();
80  void on_tabWidget_currentChanged(int index);
82  void on_openDebugLogfileButton_clicked();
84  void on_sldGraphRange_valueChanged(int value);
86  void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
87  void resizeEvent(QResizeEvent *event) override;
88  void showEvent(QShowEvent *event) override;
89  void hideEvent(QHideEvent *event) override;
91  void showPeersTableContextMenu(const QPoint& point);
93  void showBanTableContextMenu(const QPoint& point);
95  void showOrHideBanTableIfRequired();
97  void clearSelectedNode();
99  void updateDetailWidget();
100 
101 public Q_SLOTS:
102  void clear(bool clearHistory = true);
103  void fontBigger();
104  void fontSmaller();
105  void setFontSize(int newSize);
107  void message(int category, const QString &msg) { message(category, msg, false); }
108  void message(int category, const QString &message, bool html);
110  void setNumConnections(int count);
112  void setNetworkActive(bool networkActive);
114  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
116  void setMempoolSize(long numberOfTxs, size_t dynUsage);
118  void browseHistory(int offset);
120  void scrollToEnd();
122  void peerLayoutAboutToChange();
124  void peerLayoutChanged();
126  void disconnectSelectedNode();
128  void banSelectedNode(int bantime);
130  void unbanSelectedNode();
132  void setTabFocus(enum TabTypes tabType);
133 
134 Q_SIGNALS:
135  // For RPC command executor
136  void cmdRequest(const QString &command, const WalletModel* wallet_model);
137 
138 private:
139  void startExecutor();
140  void setTrafficGraphRange(int mins);
141 
143  {
144  ADDRESS_COLUMN_WIDTH = 200,
145  SUBVERSION_COLUMN_WIDTH = 150,
146  PING_COLUMN_WIDTH = 80,
147  BANSUBNET_COLUMN_WIDTH = 200,
148  BANTIME_COLUMN_WIDTH = 250
149 
150  };
151 
153  Ui::RPCConsole* const ui;
154  ClientModel *clientModel = nullptr;
155  QStringList history;
156  int historyPtr = 0;
158  QList<NodeId> cachedNodeids;
160  RPCTimerInterface *rpcTimerInterface = nullptr;
161  QMenu *peersTableContextMenu = nullptr;
162  QMenu *banTableContextMenu = nullptr;
163  int consoleFontSize = 0;
164  QCompleter *autoCompleter = nullptr;
165  QThread thread;
166  WalletModel* m_last_wallet_model{nullptr};
167 
169  void updateNetworkState();
170 
171 private Q_SLOTS:
172  void updateAlerts(const QString& warnings);
173 };
174 
175 #endif // BITCOIN_QT_RPCCONSOLE_H
Local Bitcoin RPC console.
Definition: rpcconsole.h:37
RPC timer "driver".
Definition: server.h:60
QString cmdBeforeBrowsing
Definition: rpcconsole.h:157
QStringList history
Definition: rpcconsole.h:155
interfaces::Node & m_node
Definition: rpcconsole.h:152
QThread thread
Definition: rpcconsole.h:165
disconnectpool queuedTx clear()
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:159
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:107
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:69
Model for Bitcoin network client.
Definition: clientmodel.h:46
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:158
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
Ui::RPCConsole *const ui
Definition: rpcconsole.h:153
static int count
Definition: tests.c:35
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:46
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:52