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  TabTypes tabFocus() const;
71  QString tabTitle(TabTypes tab_type) const;
72 
73 protected:
74  virtual bool eventFilter(QObject* obj, QEvent *event);
75  void keyPressEvent(QKeyEvent *);
76 
77 private Q_SLOTS:
78  void on_lineEdit_returnPressed();
79  void on_tabWidget_currentChanged(int index);
81  void on_openDebugLogfileButton_clicked();
83  void on_sldGraphRange_valueChanged(int value);
85  void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
86  void resizeEvent(QResizeEvent *event);
87  void showEvent(QShowEvent *event);
88  void hideEvent(QHideEvent *event);
90  void showPeersTableContextMenu(const QPoint& point);
92  void showBanTableContextMenu(const QPoint& point);
94  void showOrHideBanTableIfRequired();
96  void clearSelectedNode();
97 
98 public Q_SLOTS:
99  void clear(bool clearHistory = true);
100  void fontBigger();
101  void fontSmaller();
102  void setFontSize(int newSize);
104  void message(int category, const QString &msg) { message(category, msg, false); }
105  void message(int category, const QString &message, bool html);
107  void setNumConnections(int count);
109  void setNetworkActive(bool networkActive);
111  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
113  void setMempoolSize(long numberOfTxs, size_t dynUsage);
115  void browseHistory(int offset);
117  void scrollToEnd();
119  void peerSelected(const QItemSelection &selected, const QItemSelection &deselected);
121  void peerLayoutAboutToChange();
123  void peerLayoutChanged();
125  void disconnectSelectedNode();
127  void banSelectedNode(int bantime);
129  void unbanSelectedNode();
131  void setTabFocus(enum TabTypes tabType);
132 
133 Q_SIGNALS:
134  // For RPC command executor
135  void cmdRequest(const QString &command, const WalletModel* wallet_model);
136 
137 private:
138  void startExecutor();
139  void setTrafficGraphRange(int mins);
141  void updateNodeDetail(const CNodeCombinedStats *stats);
142 
144  {
145  ADDRESS_COLUMN_WIDTH = 200,
146  SUBVERSION_COLUMN_WIDTH = 150,
147  PING_COLUMN_WIDTH = 80,
148  BANSUBNET_COLUMN_WIDTH = 200,
149  BANTIME_COLUMN_WIDTH = 250
150 
151  };
152 
154  Ui::RPCConsole* const ui;
155  ClientModel *clientModel = nullptr;
156  QStringList history;
157  int historyPtr = 0;
159  QList<NodeId> cachedNodeids;
161  RPCTimerInterface *rpcTimerInterface = nullptr;
162  QMenu *peersTableContextMenu = nullptr;
163  QMenu *banTableContextMenu = nullptr;
164  int consoleFontSize = 0;
165  QCompleter *autoCompleter = nullptr;
166  QThread thread;
167  WalletModel* m_last_wallet_model{nullptr};
168 
170  void updateNetworkState();
171 };
172 
173 #endif // BITCOIN_QT_RPCCONSOLE_H
Local Bitcoin RPC console.
Definition: rpcconsole.h:36
RPC timer "driver".
Definition: server.h:72
QString cmdBeforeBrowsing
Definition: rpcconsole.h:158
QStringList history
Definition: rpcconsole.h:156
interfaces::Node & m_node
Definition: rpcconsole.h:153
QThread thread
Definition: rpcconsole.h:166
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:160
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:104
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:68
Model for Bitcoin network client.
Definition: clientmodel.h:44
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:159
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:125
Ui::RPCConsole *const ui
Definition: rpcconsole.h:154
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