Bitcoin Core  0.18.99
P2P Digital Currency
rpcconsole.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2019 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 QMenu;
32 class QItemSelection;
33 QT_END_NAMESPACE
34 
36 class RPCConsole: public QWidget
37 {
38  Q_OBJECT
39 
40 public:
41  explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
42  ~RPCConsole();
43 
44  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);
45  static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const WalletModel* wallet_model = nullptr) {
46  return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_model);
47  }
48 
49  void setClientModel(ClientModel *model);
50  void addWallet(WalletModel * const walletModel);
51  void removeWallet(WalletModel* const walletModel);
52 
53  enum MessageClass {
58  CMD_ERROR
59  };
60 
61  enum TabTypes {
62  TAB_INFO = 0,
63  TAB_CONSOLE = 1,
64  TAB_GRAPH = 2,
65  TAB_PEERS = 3
66  };
67 
68  std::vector<TabTypes> tabs() const { return {TAB_INFO, TAB_CONSOLE, TAB_GRAPH, TAB_PEERS}; }
69 
70  QString tabTitle(TabTypes tab_type) const;
71 
72 protected:
73  virtual bool eventFilter(QObject* obj, QEvent *event);
74  void keyPressEvent(QKeyEvent *);
75 
76 private Q_SLOTS:
77  void on_lineEdit_returnPressed();
78  void on_tabWidget_currentChanged(int index);
80  void on_openDebugLogfileButton_clicked();
82  void on_sldGraphRange_valueChanged(int value);
84  void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
85  void resizeEvent(QResizeEvent *event);
86  void showEvent(QShowEvent *event);
87  void hideEvent(QHideEvent *event);
89  void showPeersTableContextMenu(const QPoint& point);
91  void showBanTableContextMenu(const QPoint& point);
93  void showOrHideBanTableIfRequired();
95  void clearSelectedNode();
96 
97 public Q_SLOTS:
98  void clear(bool clearHistory = true);
99  void fontBigger();
100  void fontSmaller();
101  void setFontSize(int newSize);
103  void message(int category, const QString &msg) { message(category, msg, false); }
104  void message(int category, const QString &message, bool html);
106  void setNumConnections(int count);
108  void setNetworkActive(bool networkActive);
110  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
112  void setMempoolSize(long numberOfTxs, size_t dynUsage);
114  void browseHistory(int offset);
116  void scrollToEnd();
118  void peerSelected(const QItemSelection &selected, const QItemSelection &deselected);
120  void peerLayoutAboutToChange();
122  void peerLayoutChanged();
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:
137  void startExecutor();
138  void setTrafficGraphRange(int mins);
140  void updateNodeDetail(const CNodeCombinedStats *stats);
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 
172 #endif // BITCOIN_QT_RPCCONSOLE_H
Local Bitcoin RPC console.
Definition: rpcconsole.h:36
RPC timer "driver".
Definition: server.h:58
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:103
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:68
Model for Bitcoin network client.
Definition: clientmodel.h:44
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:158
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:125
Ui::RPCConsole *const ui
Definition: rpcconsole.h:153
static int count
Definition: tests.c:45
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:45
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:36