Bitcoin ABC  0.24.7
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();
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) {
108  message(category, msg, false);
109  }
110  void message(int category, const QString &message, bool html);
112  void setNumConnections(int count);
114  void setNetworkActive(bool networkActive);
116  void setNumBlocks(int count, const QDateTime &blockDate,
117  double nVerificationProgress, bool headers);
120  void setMempoolSize(long numberOfTxs, size_t dynUsage);
122  void browseHistory(int offset);
124  void scrollToEnd();
126  void peerSelected(const QItemSelection &selected,
127  const QItemSelection &deselected);
131  void peerLayoutChanged();
133  void disconnectSelectedNode();
135  void banSelectedNode(int bantime);
137  void unbanSelectedNode();
139  void setTabFocus(enum TabTypes tabType);
140 
141 Q_SIGNALS:
142  // For RPC command executor
143  void cmdRequest(const QString &command, const WalletModel *wallet_model);
144 
145 private:
146  void startExecutor();
147  void setTrafficGraphRange(int mins);
149  void updateNodeDetail(const CNodeCombinedStats *stats);
150 
157 
158  };
159 
161  Ui::RPCConsole *const ui;
163  QStringList history;
164  int historyPtr = 0;
166  QList<NodeId> cachedNodeids;
169  QMenu *peersTableContextMenu = nullptr;
170  QMenu *banTableContextMenu = nullptr;
172  QCompleter *autoCompleter = nullptr;
173  QThread thread;
175 
177  void updateNetworkState();
178 
179 private Q_SLOTS:
180  void updateAlerts(const QString &warnings);
181 };
182 
183 #endif // BITCOIN_QT_RPCCONSOLE_H
RPCConsole::TabTypes::CONSOLE
@ CONSOLE
interfaces
Definition: dummywallet.cpp:12
RPCConsole::setNumConnections
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: rpcconsole.cpp:1006
count
static int count
Definition: tests.c:41
RPCConsole::ADDRESS_COLUMN_WIDTH
@ ADDRESS_COLUMN_WIDTH
Definition: rpcconsole.h:152
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:47
RPCConsole::startExecutor
void startExecutor()
Definition: rpcconsole.cpp:1121
RPCTimerInterface
RPC timer "driver".
Definition: server.h:100
RPCConsole::resizeEvent
void resizeEvent(QResizeEvent *event) override
Definition: rpcconsole.cpp:1343
RPCConsole::clearSelectedNode
void clearSelectedNode()
clear the selected node
Definition: rpcconsole.cpp:1448
RPCConsole::keyPressEvent
void keyPressEvent(QKeyEvent *) override
Definition: rpcconsole.cpp:963
RPCConsole::platformStyle
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:167
RPCConsole::updateNetworkState
void updateNetworkState()
Update UI with latest network info from model.
Definition: rpcconsole.cpp:987
RPCConsole::CMD_REQUEST
@ CMD_REQUEST
Definition: rpcconsole.h:64
RPCConsole::showOrHideBanTableIfRequired
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
Definition: rpcconsole.cpp:1455
RPCConsole::autoCompleter
QCompleter * autoCompleter
Definition: rpcconsole.h:172
RPCConsole::CMD_ERROR
@ CMD_ERROR
Definition: rpcconsole.h:64
RPCConsole::setTrafficGraphRange
void setTrafficGraphRange(int mins)
Definition: rpcconsole.cpp:1164
RPCConsole::RPCParseCommandLine
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
RPCConsole::ui
Ui::RPCConsole *const ui
Definition: rpcconsole.h:161
RPCConsole::fontSmaller
void fontSmaller()
Definition: rpcconsole.cpp:870
RPCConsole::setMempoolSize
void setMempoolSize(long numberOfTxs, size_t dynUsage)
Set size (number of transactions and memory usage) of the mempool in the UI.
Definition: rpcconsole.cpp:1026
RPCConsole::tabShortcut
QKeySequence tabShortcut(TabTypes tab_type) const
Definition: rpcconsole.cpp:1473
RPCConsole::peerLayoutChanged
void peerLayoutChanged()
Handle updated peer information.
Definition: rpcconsole.cpp:1204
RPCConsole::cachedNodeids
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:166
RPCConsole::addWallet
void addWallet(WalletModel *const walletModel)
RPCConsole::updateTrafficStats
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
Definition: rpcconsole.cpp:1169
RPCConsole::MC_DEBUG
@ MC_DEBUG
Definition: rpcconsole.h:64
RPCConsole::consoleFontSize
int consoleFontSize
Definition: rpcconsole.h:171
RPCConsole::updateAlerts
void updateAlerts(const QString &warnings)
Definition: rpcconsole.cpp:1488
RPCConsole::setNetworkActive
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Definition: rpcconsole.cpp:1014
RPCConsole::scrollToEnd
void scrollToEnd()
Scroll console view to end.
Definition: rpcconsole.cpp:1153
RPCConsole::removeWallet
void removeWallet(WalletModel *const walletModel)
RPCConsole::showPeersTableContextMenu
void showPeersTableContextMenu(const QPoint &point)
Show custom context menu on Peers tab.
Definition: rpcconsole.cpp:1369
RPCConsole::setFontSize
void setFontSize(int newSize)
Definition: rpcconsole.cpp:874
RPCConsole::RPCConsole
RPCConsole(interfaces::Node &node, const PlatformStyle *platformStyle, QWidget *parent)
Definition: rpcconsole.cpp:510
RPCConsole::cmdRequest
void cmdRequest(const QString &command, const WalletModel *wallet_model)
RPCConsole::m_last_wallet_model
WalletModel * m_last_wallet_model
Definition: rpcconsole.h:174
RPCConsole::setClientModel
void setClientModel(ClientModel *model=nullptr, int bestblock_height=0, int64_t bestblock_date=0, double verification_progress=0.0)
Definition: rpcconsole.cpp:647
RPCConsole::CMD_REPLY
@ CMD_REPLY
Definition: rpcconsole.h:64
RPCConsole::showEvent
void showEvent(QShowEvent *event) override
Definition: rpcconsole.cpp:1347
RPCConsole::on_tabWidget_currentChanged
void on_tabWidget_currentChanged(int index)
Definition: rpcconsole.cpp:1143
RPCConsole::disconnectSelectedNode
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
Definition: rpcconsole.cpp:1383
RPCConsole
Local Bitcoin RPC console.
Definition: rpcconsole.h:36
RPCConsole::MessageClass
MessageClass
Definition: rpcconsole.h:64
RPCConsole::ColumnWidths
ColumnWidths
Definition: rpcconsole.h:151
RPCConsole::BANSUBNET_COLUMN_WIDTH
@ BANSUBNET_COLUMN_WIDTH
Definition: rpcconsole.h:155
guiutil.h
RPCConsole::MC_ERROR
@ MC_ERROR
Definition: rpcconsole.h:64
RPCConsole::PING_COLUMN_WIDTH
@ PING_COLUMN_WIDTH
Definition: rpcconsole.h:154
RPCConsole::showBanTableContextMenu
void showBanTableContextMenu(const QPoint &point)
Show custom context menu on Bans tab.
Definition: rpcconsole.cpp:1376
RPCConsole::SUBVERSION_COLUMN_WIDTH
@ SUBVERSION_COLUMN_WIDTH
Definition: rpcconsole.h:153
CNodeCombinedStats
Definition: peertablemodel.h:26
RPCConsole::BANTIME_COLUMN_WIDTH
@ BANTIME_COLUMN_WIDTH
Definition: rpcconsole.h:156
RPCConsole::hideEvent
void hideEvent(QHideEvent *event) override
Definition: rpcconsole.cpp:1358
RPCConsole::m_node
interfaces::Node & m_node
Definition: rpcconsole.h:160
RPCConsole::thread
QThread thread
Definition: rpcconsole.h:173
RPCConsole::TabTypes::GRAPH
@ GRAPH
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:55
RPCConsole::tabTitle
QString tabTitle(TabTypes tab_type) const
Definition: rpcconsole.cpp:1469
RPCConsole::~RPCConsole
~RPCConsole()
Definition: rpcconsole.cpp:584
RPCConsole::updateNodeDetail
void updateNodeDetail(const CNodeCombinedStats *stats)
show detailed information on ui about selected node
Definition: rpcconsole.cpp:1262
RPCConsole::history
QStringList history
Definition: rpcconsole.h:163
RPCConsole::TabTypes
TabTypes
Definition: rpcconsole.h:66
RPCConsole::cmdBeforeBrowsing
QString cmdBeforeBrowsing
Definition: rpcconsole.h:165
ClientModel
Model for Bitcoin network client.
Definition: clientmodel.h:36
RPCConsole::eventFilter
virtual bool eventFilter(QObject *obj, QEvent *event) override
Definition: rpcconsole.cpp:592
Ui
Definition: addressbookpage.h:14
RPCConsole::setTabFocus
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
Definition: rpcconsole.cpp:1465
RPCConsole::on_lineEdit_returnPressed
void on_lineEdit_returnPressed()
Definition: rpcconsole.cpp:1038
RPCConsole::peersTableContextMenu
QMenu * peersTableContextMenu
Definition: rpcconsole.h:169
RPCConsole::RPCExecuteCommandLine
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
RPCConsole::message
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:107
RPCConsole::on_openDebugLogfileButton_clicked
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
Definition: rpcconsole.cpp:1149
RPCConsole::browseHistory
void browseHistory(int offset)
Go forward or back in history.
Definition: rpcconsole.cpp:1099
RPCConsole::historyPtr
int historyPtr
Definition: rpcconsole.h:164
RPCConsole::on_sldGraphRange_valueChanged
void on_sldGraphRange_valueChanged(int value)
change the time range of the network traffic graph
Definition: rpcconsole.cpp:1158
RPCConsole::setNumBlocks
void setNumBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, bool headers)
Set number of blocks and last block date shown in the UI.
Definition: rpcconsole.cpp:1018
RPCConsole::fontBigger
void fontBigger()
Definition: rpcconsole.cpp:866
peertablemodel.h
net.h
PlatformStyle
Definition: platformstyle.h:13
RPCConsole::unbanSelectedNode
void unbanSelectedNode()
Unban a selected node on the Bans tab.
Definition: rpcconsole.cpp:1428
RPCConsole::clear
void clear(bool clearHistory=true)
Definition: rpcconsole.cpp:904
RPCConsole::tabs
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:68
RPCConsole::rpcTimerInterface
RPCTimerInterface * rpcTimerInterface
Definition: rpcconsole.h:168
RPCConsole::peerSelected
void peerSelected(const QItemSelection &selected, const QItemSelection &deselected)
Handle selection of peer in peers list.
Definition: rpcconsole.cpp:1175
RPCConsole::banSelectedNode
void banSelectedNode(int bantime)
Ban a selected node on the Peers tab.
Definition: rpcconsole.cpp:1397
RPCConsole::peerLayoutAboutToChange
void peerLayoutAboutToChange()
Handle selection caching before update.
Definition: rpcconsole.cpp:1192
RPCConsole::clientModel
ClientModel * clientModel
Definition: rpcconsole.h:162
RPCConsole::banTableContextMenu
QMenu * banTableContextMenu
Definition: rpcconsole.h:170
RPCConsole::TabTypes::INFO
@ INFO
RPCConsole::TabTypes::PEERS
@ PEERS