Bitcoin ABC  0.22.13
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 <QCompleter>
14 #include <QThread>
15 #include <QWidget>
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  Q_OBJECT
38 
39 public:
40  explicit RPCConsole(interfaces::Node &node,
41  const PlatformStyle *platformStyle, QWidget *parent);
42  ~RPCConsole();
43 
44  static bool
45  RPCParseCommandLine(interfaces::Node *node, std::string &strResult,
46  const std::string &strCommand, bool fExecute,
47  std::string *const pstrFilteredOut = nullptr,
48  const WalletModel *wallet_model = nullptr);
49  static bool
50  RPCExecuteCommandLine(interfaces::Node &node, std::string &strResult,
51  const std::string &strCommand,
52  std::string *const pstrFilteredOut = nullptr,
53  const WalletModel *wallet_model = nullptr) {
54  return RPCParseCommandLine(&node, strResult, strCommand, true,
55  pstrFilteredOut, wallet_model);
56  }
57 
58  void setClientModel(ClientModel *model);
59  void addWallet(WalletModel *const walletModel);
60  void removeWallet(WalletModel *const walletModel);
61 
62  enum MessageClass { MC_ERROR, MC_DEBUG, CMD_REQUEST, CMD_REPLY, CMD_ERROR };
63 
64  enum class TabTypes { INFO, CONSOLE, GRAPH, PEERS };
65 
66  std::vector<TabTypes> tabs() const {
67  return {TabTypes::INFO, TabTypes::CONSOLE, TabTypes::GRAPH,
68  TabTypes::PEERS};
69  }
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();
98 
99 public Q_SLOTS:
100  void clear(bool clearHistory = true);
101  void fontBigger();
102  void fontSmaller();
103  void setFontSize(int newSize);
105  void message(int category, const QString &msg) {
106  message(category, msg, false);
107  }
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,
115  double nVerificationProgress, bool headers);
118  void setMempoolSize(long numberOfTxs, size_t dynUsage);
120  void browseHistory(int offset);
122  void scrollToEnd();
124  void peerSelected(const QItemSelection &selected,
125  const QItemSelection &deselected);
127  void peerLayoutAboutToChange();
129  void peerLayoutChanged();
131  void disconnectSelectedNode();
133  void banSelectedNode(int bantime);
135  void unbanSelectedNode();
137  void setTabFocus(enum TabTypes tabType);
138 
139 Q_SIGNALS:
140  // For RPC command executor
141  void cmdRequest(const QString &command, const WalletModel *wallet_model);
142 
143 private:
144  void startExecutor();
145  void setTrafficGraphRange(int mins);
147  void updateNodeDetail(const CNodeCombinedStats *stats);
148 
150  ADDRESS_COLUMN_WIDTH = 200,
151  SUBVERSION_COLUMN_WIDTH = 150,
152  PING_COLUMN_WIDTH = 80,
153  BANSUBNET_COLUMN_WIDTH = 200,
154  BANTIME_COLUMN_WIDTH = 250
155 
156  };
157 
159  Ui::RPCConsole *const ui;
160  ClientModel *clientModel = nullptr;
161  QStringList history;
162  int historyPtr = 0;
164  QList<NodeId> cachedNodeids;
166  RPCTimerInterface *rpcTimerInterface = nullptr;
167  QMenu *peersTableContextMenu = nullptr;
168  QMenu *banTableContextMenu = nullptr;
169  int consoleFontSize = 0;
170  QCompleter *autoCompleter = nullptr;
171  QThread thread;
172  WalletModel *m_last_wallet_model{nullptr};
173 
175  void updateNetworkState();
176 
177 private Q_SLOTS:
178  void updateAlerts(const QString &warnings);
179 };
180 
181 #endif // BITCOIN_QT_RPCCONSOLE_H
Local Bitcoin RPC console.
Definition: rpcconsole.h:36
RPC timer "driver".
Definition: server.h:98
QString cmdBeforeBrowsing
Definition: rpcconsole.h:163
QStringList history
Definition: rpcconsole.h:161
interfaces::Node & m_node
Definition: rpcconsole.h:158
QThread thread
Definition: rpcconsole.h:171
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:165
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:105
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:66
Model for Bitcoin network client.
Definition: clientmodel.h:34
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:164
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:47
Ui::RPCConsole *const ui
Definition: rpcconsole.h:159
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:50
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:45