Bitcoin ABC  0.26.3
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 = nullptr, int bestblock_height = 0,
59  int64_t bestblock_date = 0,
60  double verification_progress = 0.0);
61  void addWallet(WalletModel *const walletModel);
62  void removeWallet(WalletModel *const walletModel);
63 
65 
66  enum class TabTypes { INFO, CONSOLE, GRAPH, PEERS };
67 
68  std::vector<TabTypes> tabs() const {
71  }
72 
73  QString tabTitle(TabTypes tab_type) const;
74  QKeySequence tabShortcut(TabTypes tab_type) const;
75 
76 protected:
77  virtual bool eventFilter(QObject *obj, QEvent *event) override;
78  void keyPressEvent(QKeyEvent *) 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 clearHistory = true);
105  void fontBigger();
106  void fontSmaller();
107  void setFontSize(int newSize);
109  void message(int category, const QString &msg) {
110  message(category, msg, false);
111  }
112  void message(int category, const QString &message, bool html);
114  void setNumConnections(int count);
116  void setNetworkActive(bool networkActive);
118  void setNumBlocks(int count, const QDateTime &blockDate,
119  double nVerificationProgress, bool headers);
122  void setMempoolSize(long numberOfTxs, size_t dynUsage);
124  void browseHistory(int offset);
126  void scrollToEnd();
130  void peerLayoutChanged();
132  void disconnectSelectedNode();
134  void banSelectedNode(int bantime);
136  void unbanSelectedNode();
138  void setTabFocus(enum TabTypes tabType);
139 
140 Q_SIGNALS:
141  // For RPC command executor
142  void cmdRequest(const QString &command, const WalletModel *wallet_model);
143 
144 private:
145  void startExecutor();
146  void setTrafficGraphRange(int mins);
147 
154 
155  };
156 
158  Ui::RPCConsole *const ui;
160  QStringList history;
161  int historyPtr = 0;
163  QList<NodeId> cachedNodeids;
166  QMenu *peersTableContextMenu = nullptr;
167  QMenu *banTableContextMenu = nullptr;
169  QCompleter *autoCompleter = nullptr;
170  QThread thread;
172 
174  void updateNetworkState();
175 
180  QString TimeDurationField(std::chrono::seconds time_now,
181  std::chrono::seconds time_at_event) const {
182  return time_at_event.count()
183  ? GUIUtil::formatDurationStr(time_now - time_at_event)
184  : tr("Never");
185  }
186 
187 private Q_SLOTS:
188  void updateAlerts(const QString &warnings);
189 };
190 
191 #endif // BITCOIN_QT_RPCCONSOLE_H
Model for Bitcoin network client.
Definition: clientmodel.h:36
Local Bitcoin RPC console.
Definition: rpcconsole.h:36
QMenu * peersTableContextMenu
Definition: rpcconsole.h:166
RPCConsole(interfaces::Node &node, const PlatformStyle *platformStyle, QWidget *parent)
Definition: rpcconsole.cpp:509
void cmdRequest(const QString &command, const WalletModel *wallet_model)
void browseHistory(int offset)
Go forward or back in history.
void fontSmaller()
Definition: rpcconsole.cpp:876
RPCTimerInterface * rpcTimerInterface
Definition: rpcconsole.h:165
QString TimeDurationField(std::chrono::seconds time_now, std::chrono::seconds time_at_event) const
Helper for the output of a time duration field.
Definition: rpcconsole.h:180
void on_lineEdit_returnPressed()
QStringList history
Definition: rpcconsole.h:160
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:109
void setFontSize(int newSize)
Definition: rpcconsole.cpp:880
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
void setTrafficGraphRange(int mins)
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:146
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:164
void updateDetailWidget()
show detailed information on ui about selected node
void showEvent(QShowEvent *event) override
void resizeEvent(QResizeEvent *event) override
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
QString tabTitle(TabTypes tab_type) const
void updateNetworkState()
Update UI with latest network info from model.
Definition: rpcconsole.cpp:993
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:68
@ BANTIME_COLUMN_WIDTH
Definition: rpcconsole.h:153
@ ADDRESS_COLUMN_WIDTH
Definition: rpcconsole.h:149
@ SUBVERSION_COLUMN_WIDTH
Definition: rpcconsole.h:150
@ PING_COLUMN_WIDTH
Definition: rpcconsole.h:151
@ BANSUBNET_COLUMN_WIDTH
Definition: rpcconsole.h:152
QCompleter * autoCompleter
Definition: rpcconsole.h:169
void setMempoolSize(long numberOfTxs, size_t dynUsage)
Set size (number of transactions and memory usage) of the mempool in the UI.
void setNumBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, bool headers)
Set number of blocks and last block date shown in the UI.
void clear(bool clearHistory=true)
Definition: rpcconsole.cpp:910
void hideEvent(QHideEvent *event) override
QKeySequence tabShortcut(TabTypes tab_type) const
void showPeersTableContextMenu(const QPoint &point)
Show custom context menu on Peers tab.
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:163
interfaces::Node & m_node
Definition: rpcconsole.h:157
void unbanSelectedNode()
Unban a selected node on the Bans tab.
void updateAlerts(const QString &warnings)
void clearSelectedNode()
clear the selected node
void on_sldGraphRange_valueChanged(int value)
change the time range of the network traffic graph
int consoleFontSize
Definition: rpcconsole.h:168
void setNumConnections(int count)
Set number of connections shown in the UI.
ClientModel * clientModel
Definition: rpcconsole.h:159
void banSelectedNode(int bantime)
Ban a selected node on the Peers tab.
int historyPtr
Definition: rpcconsole.h:161
void scrollToEnd()
Scroll console view to end.
void keyPressEvent(QKeyEvent *) override
Definition: rpcconsole.cpp:969
void on_tabWidget_currentChanged(int index)
Ui::RPCConsole *const ui
Definition: rpcconsole.h:158
void startExecutor()
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
void fontBigger()
Definition: rpcconsole.cpp:872
QString cmdBeforeBrowsing
Definition: rpcconsole.h:162
void addWallet(WalletModel *const walletModel)
virtual bool eventFilter(QObject *obj, QEvent *event) override
Definition: rpcconsole.cpp:598
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
void removeWallet(WalletModel *const walletModel)
void showBanTableContextMenu(const QPoint &point)
Show custom context menu on Bans tab.
void peerLayoutAboutToChange()
Handle selection caching before update.
void setClientModel(ClientModel *model=nullptr, int bestblock_height=0, int64_t bestblock_date=0, double verification_progress=0.0)
Definition: rpcconsole.cpp:653
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
WalletModel * m_last_wallet_model
Definition: rpcconsole.h:171
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
QMenu * banTableContextMenu
Definition: rpcconsole.h:167
QThread thread
Definition: rpcconsole.h:170
void peerLayoutChanged()
Handle updated peer information.
RPC timer "driver".
Definition: server.h:99
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:47
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:55
QString formatDurationStr(std::chrono::seconds dur)
Convert seconds into a QString with days, hours, mins, secs.
Definition: guiutil.cpp:804
static int count
Definition: tests.c:31