Bitcoin Core  31.0.0
P2P Digital Currency
rpcconsole.h
Go to the documentation of this file.
1 // Copyright (c) 2011-present 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 <bitcoin-build-config.h> // IWYU pragma: keep
9 
10 #include <qt/clientmodel.h>
11 #include <qt/guiutil.h>
12 #include <qt/peertablemodel.h>
13 
14 #include <net.h>
15 
16 #include <QByteArray>
17 #include <QCompleter>
18 #include <QMimeData>
19 #include <QTextDocumentFragment>
20 #include <QTextEdit>
21 #include <QThread>
22 #include <QWidget>
23 
24 class PlatformStyle;
25 class RPCExecutor;
26 class WalletModel;
27 
28 namespace interfaces {
29  class Node;
30 }
31 
32 namespace Ui {
33  class RPCConsole;
34 }
35 
36 QT_BEGIN_NAMESPACE
37 class QDateTime;
38 class QMenu;
39 class QItemSelection;
40 QT_END_NAMESPACE
41 
43 class RPCConsole: public QWidget
44 {
45  Q_OBJECT
46 
47 public:
48  explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
49  ~RPCConsole();
50 
51  static bool RPCParseCommandLine(interfaces::Node* node, std::string& strResult, const std::string& strCommand, bool fExecute, std::string* pstrFilteredOut = nullptr, const QString& wallet_name = {});
52  static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const QString& wallet_name = {}) {
53  return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_name);
54  }
55 
56  void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);
57 
58 #ifdef ENABLE_WALLET
59  void addWallet(WalletModel* walletModel);
60  void removeWallet(WalletModel* walletModel);
61 #endif // ENABLE_WALLET
62 
63  enum MessageClass {
69  };
70 
71  enum class TabTypes {
72  INFO,
73  CONSOLE,
74  GRAPH,
75  PEERS
76  };
77 
78  std::vector<TabTypes> tabs() const { return {TabTypes::INFO, TabTypes::CONSOLE, TabTypes::GRAPH, TabTypes::PEERS}; }
79 
80  QString tabTitle(TabTypes tab_type) const;
81  QKeySequence tabShortcut(TabTypes tab_type) const;
82 
83 protected:
84  virtual bool eventFilter(QObject* obj, QEvent *event) override;
85  void keyPressEvent(QKeyEvent *) override;
86  void changeEvent(QEvent* e) override;
87 
88 private Q_SLOTS:
90  void on_tabWidget_currentChanged(int index);
94  void on_sldGraphRange_valueChanged(int value);
96  void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
97  void resizeEvent(QResizeEvent *event) override;
98  void showEvent(QShowEvent *event) override;
99  void hideEvent(QHideEvent *event) override;
101  void showPeersTableContextMenu(const QPoint& point);
103  void showBanTableContextMenu(const QPoint& point);
107  void clearSelectedNode();
109  void updateDetailWidget();
110 
111 public Q_SLOTS:
112  void clear(bool keep_prompt = false);
113  void fontBigger();
114  void fontSmaller();
115  void setFontSize(int newSize);
117  void message(int category, const QString &msg) { message(category, msg, false); }
118  void message(int category, const QString &message, bool html);
120  void setNumConnections(int count);
122  void setNetworkActive(bool networkActive);
124  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype);
126  void setMempoolSize(long numberOfTxs, size_t dynUsage, size_t maxUsage);
128  void browseHistory(int offset);
130  void scrollToEnd();
132  void disconnectSelectedNode();
134  void banSelectedNode(int bantime);
136  void unbanSelectedNode();
138  void setTabFocus(enum TabTypes tabType);
139 #ifdef ENABLE_WALLET
140 
141  void setCurrentWallet(WalletModel* wallet_model);
142 #endif // ENABLE_WALLET
143 
144 private:
146  const QString yes{tr("Yes")}, no{tr("No")}, to{tr("To")}, from{tr("From")},
147  ban_for{tr("Ban for")}, na{tr("N/A")}, unknown{tr("Unknown")};
148  } const ts;
149 
150  void startExecutor();
151  void setTrafficGraphRange(int mins);
152 
154  {
160 
161  };
162 
164  Ui::RPCConsole* const ui;
166  QStringList history;
167  int historyPtr = 0;
169  QList<NodeId> cachedNodeids;
171  QMenu *peersTableContextMenu = nullptr;
172  QMenu *banTableContextMenu = nullptr;
174  QCompleter *autoCompleter = nullptr;
175  QThread thread;
178  bool m_is_executing{false};
181 
183  void updateNetworkState();
184 
186  QString TimeDurationField(std::chrono::seconds time_now, std::chrono::seconds time_at_event) const
187  {
188  return time_at_event.count() ? GUIUtil::formatDurationStr(time_now - time_at_event) : tr("Never");
189  }
190 
191  void updateWindowTitle();
192 
193 private Q_SLOTS:
194  void updateAlerts(const QString& warnings);
195 };
196 
201 class PlainCopyTextEdit : public QTextEdit {
202  Q_OBJECT
203 public:
204  using QTextEdit::QTextEdit;
205 protected:
206  QMimeData* createMimeDataFromSelection() const override {
207  auto md = new QMimeData();
208  md->setText(textCursor().selection().toPlainText());
209  return md;
210  }
211 };
212 
213 #endif // BITCOIN_QT_RPCCONSOLE_H
QMimeData * createMimeDataFromSelection() const override
Definition: rpcconsole.h:206
Local Bitcoin RPC console.
Definition: rpcconsole.h:43
QString cmdBeforeBrowsing
Definition: rpcconsole.h:168
void on_lineEdit_returnPressed()
Definition: rpcconsole.cpp:992
void updateWindowTitle()
static bool RPCParseCommandLine(interfaces::Node *node, std::string &strResult, const std::string &strCommand, bool fExecute, std::string *pstrFilteredOut=nullptr, const QString &wallet_name={})
Split shell command line into a list of arguments and optionally execute the command(s).
Definition: rpcconsole.cpp:141
A version of QTextEdit that only populates plaintext mime data from a selection, this avoids some bad...
Definition: rpcconsole.h:201
void showPeersTableContextMenu(const QPoint &point)
Show custom context menu on Peers tab.
WalletModel * m_last_wallet_model
Definition: rpcconsole.h:177
void updateDetailWidget()
show detailed information on ui about selected node
void setClientModel(ClientModel *model=nullptr, int bestblock_height=0, int64_t bestblock_date=0, double verification_progress=0.0)
Definition: rpcconsole.cpp:621
QStringList history
Definition: rpcconsole.h:166
interfaces::Node & m_node
Definition: rpcconsole.h:163
QThread thread
Definition: rpcconsole.h:175
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Definition: rpcconsole.cpp:967
void scrollToEnd()
Scroll console view to end.
void clearSelectedNode()
clear the selected node
RPCConsole(interfaces::Node &node, const PlatformStyle *platformStyle, QWidget *parent)
Definition: rpcconsole.cpp:437
void fontSmaller()
Definition: rpcconsole.cpp:802
void changeEvent(QEvent *e) override
Definition: rpcconsole.cpp:898
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
void on_tabWidget_currentChanged(int index)
QString formatDurationStr(std::chrono::seconds dur)
Convert seconds into a QString with days, hours, mins, secs.
Definition: guiutil.cpp:731
QString tabTitle(TabTypes tab_type) const
void clear(bool keep_prompt=false)
Definition: rpcconsole.cpp:832
RPCExecutor * m_executor
Definition: rpcconsole.h:176
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:170
struct RPCConsole::TranslatedStrings ts
QMenu * peersTableContextMenu
Definition: rpcconsole.h:171
void browseHistory(int offset)
Go forward or back in history.
void resizeEvent(QResizeEvent *event) override
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:117
QByteArray m_banlist_widget_header_state
Definition: rpcconsole.h:180
void setMempoolSize(long numberOfTxs, size_t dynUsage, size_t maxUsage)
Set size (number of transactions and memory usage) of the mempool in the UI.
Definition: rpcconsole.cpp:980
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
bool m_is_executing
Definition: rpcconsole.h:178
int historyPtr
Definition: rpcconsole.h:167
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:78
void updateNetworkState()
Update UI with latest network info from model.
Definition: rpcconsole.cpp:933
QByteArray m_peer_widget_header_state
Definition: rpcconsole.h:179
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
Model for Bitcoin network client.
Definition: clientmodel.h:56
void unbanSelectedNode()
Unban a selected node on the Bans tab.
ClientModel * clientModel
Definition: rpcconsole.h:165
QMenu * banTableContextMenu
Definition: rpcconsole.h:172
void setTrafficGraphRange(int mins)
SyncType
Definition: clientmodel.h:42
QKeySequence tabShortcut(TabTypes tab_type) const
Definition: messages.h:21
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
void fontBigger()
Definition: rpcconsole.cpp:797
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:169
void setFontSize(int newSize)
Definition: rpcconsole.cpp:807
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: rpcconsole.cpp:959
void startExecutor()
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:48
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.
static bool RPCExecuteCommandLine(interfaces::Node &node, std::string &strResult, const std::string &strCommand, std::string *const pstrFilteredOut=nullptr, const QString &wallet_name={})
Definition: rpcconsole.h:52
Ui::RPCConsole *const ui
Definition: rpcconsole.h:164
void setNumBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType synctype)
Set number of blocks and last block date shown in the UI.
Definition: rpcconsole.cpp:972
void updateAlerts(const QString &warnings)
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:186
static int count
int consoleFontSize
Definition: rpcconsole.h:173
void showEvent(QShowEvent *event) override
QCompleter * autoCompleter
Definition: rpcconsole.h:174
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:69
void showBanTableContextMenu(const QPoint &point)
Show custom context menu on Bans tab.
void keyPressEvent(QKeyEvent *) override
Definition: rpcconsole.cpp:891
void hideEvent(QHideEvent *event) override
virtual bool eventFilter(QObject *obj, QEvent *event) override
Definition: rpcconsole.cpp:577