Bitcoin Core  0.21.1
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules
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 = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);
50  void addWallet(WalletModel * const walletModel);
51  void removeWallet(WalletModel* const walletModel);
52 
53  enum MessageClass {
59  };
60 
61  enum class TabTypes {
62  INFO,
63  CONSOLE,
64  GRAPH,
65  PEERS
66  };
67 
68  std::vector<TabTypes> tabs() const { return {TabTypes::INFO, TabTypes::CONSOLE, TabTypes::GRAPH, TabTypes::PEERS}; }
69 
70  QString tabTitle(TabTypes tab_type) const;
71  QKeySequence tabShortcut(TabTypes tab_type) const;
72 
73 protected:
74  virtual bool eventFilter(QObject* obj, QEvent *event) override;
75  void keyPressEvent(QKeyEvent *) override;
76 
77 private Q_SLOTS:
79  void on_tabWidget_currentChanged(int index);
83  void on_sldGraphRange_valueChanged(int value);
85  void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
86  void resizeEvent(QResizeEvent *event) override;
87  void showEvent(QShowEvent *event) override;
88  void hideEvent(QHideEvent *event) override;
90  void showPeersTableContextMenu(const QPoint& point);
92  void showBanTableContextMenu(const QPoint& point);
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);
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  {
150 
151  };
152 
154  Ui::RPCConsole* const ui;
156  QStringList history;
157  int historyPtr = 0;
159  QList<NodeId> cachedNodeids;
162  QMenu *peersTableContextMenu = nullptr;
163  QMenu *banTableContextMenu = nullptr;
165  QCompleter *autoCompleter = nullptr;
166  QThread thread;
168 
170  void updateNetworkState();
171 
172 private Q_SLOTS:
173  void updateAlerts(const QString& warnings);
174 };
175 
176 #endif // BITCOIN_QT_RPCCONSOLE_H
void addWallet(WalletModel *const walletModel)
Local Bitcoin RPC console.
Definition: rpcconsole.h:36
RPC timer "driver".
Definition: server.h:60
QString cmdBeforeBrowsing
Definition: rpcconsole.h:158
void on_lineEdit_returnPressed()
Definition: rpcconsole.cpp:889
void showPeersTableContextMenu(const QPoint &point)
Show custom context menu on Peers tab.
WalletModel * m_last_wallet_model
Definition: rpcconsole.h:167
void setClientModel(ClientModel *model=nullptr, int bestblock_height=0, int64_t bestblock_date=0, double verification_progress=0.0)
Definition: rpcconsole.cpp:560
QStringList history
Definition: rpcconsole.h:156
interfaces::Node & m_node
Definition: rpcconsole.h:153
QThread thread
Definition: rpcconsole.h:166
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:68
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Definition: rpcconsole.cpp:866
void scrollToEnd()
Scroll console view to end.
Definition: rpcconsole.cpp:999
void clearSelectedNode()
clear the selected node
RPCConsole(interfaces::Node &node, const PlatformStyle *platformStyle, QWidget *parent)
Definition: rpcconsole.cpp:443
void fontSmaller()
Definition: rpcconsole.cpp:740
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
void on_tabWidget_currentChanged(int index)
Definition: rpcconsole.cpp:987
void updateNodeDetail(const CNodeCombinedStats *stats)
show detailed information on ui about selected node
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:160
QMenu * peersTableContextMenu
Definition: rpcconsole.h:162
void browseHistory(int offset)
Go forward or back in history.
Definition: rpcconsole.cpp:944
void resizeEvent(QResizeEvent *event) override
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:104
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
int historyPtr
Definition: rpcconsole.h:157
void peerLayoutChanged()
Handle updated peer information.
RPCTimerInterface * rpcTimerInterface
Definition: rpcconsole.h:161
void updateNetworkState()
Update UI with latest network info from model.
Definition: rpcconsole.cpp:845
QString tabTitle(TabTypes tab_type) const
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
Definition: rpcconsole.cpp:994
Model for Bitcoin network client.
Definition: clientmodel.h:46
void unbanSelectedNode()
Unban a selected node on the Bans tab.
ClientModel * clientModel
Definition: rpcconsole.h:155
QMenu * banTableContextMenu
Definition: rpcconsole.h:163
void setTrafficGraphRange(int mins)
void clear(bool clearHistory=true)
Definition: rpcconsole.cpp:770
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
void fontBigger()
Definition: rpcconsole.cpp:735
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:159
void setMempoolSize(long numberOfTxs, size_t dynUsage)
Set size (number of transactions and memory usage) of the mempool in the UI.
Definition: rpcconsole.cpp:879
void setFontSize(int newSize)
Definition: rpcconsole.cpp:745
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: rpcconsole.cpp:858
void startExecutor()
Definition: rpcconsole.cpp:965
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:148
void peerLayoutAboutToChange()
Handle selection caching before update.
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
void on_sldGraphRange_valueChanged(int value)
change the time range of the network traffic graph
void banSelectedNode(int bantime)
Ban a selected node on the Peers tab.
Ui::RPCConsole *const ui
Definition: rpcconsole.h:154
void updateAlerts(const QString &warnings)
void removeWallet(WalletModel *const walletModel)
static int count
Definition: tests.c:35
int consoleFontSize
Definition: rpcconsole.h:164
void peerSelected(const QItemSelection &selected, const QItemSelection &deselected)
Handle selection of peer in peers list.
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
void cmdRequest(const QString &command, const WalletModel *wallet_model)
void showEvent(QShowEvent *event) override
QCompleter * autoCompleter
Definition: rpcconsole.h:165
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:52
QKeySequence tabShortcut(TabTypes tab_type) const
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:871
void showBanTableContextMenu(const QPoint &point)
Show custom context menu on Bans tab.
void keyPressEvent(QKeyEvent *) override
Definition: rpcconsole.cpp:821
void hideEvent(QHideEvent *event) override
virtual bool eventFilter(QObject *obj, QEvent *event) override
Definition: rpcconsole.cpp:515