Bitcoin Core 28.99.0
P2P Digital Currency
rpcconsole.h
Go to the documentation of this file.
1// Copyright (c) 2011-2022 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 <QThread>
19#include <QWidget>
20
21class PlatformStyle;
22class RPCExecutor;
24class WalletModel;
25
26namespace interfaces {
27 class Node;
28}
29
30namespace Ui {
31 class RPCConsole;
32}
33
34QT_BEGIN_NAMESPACE
35class QDateTime;
36class QMenu;
37class QItemSelection;
38QT_END_NAMESPACE
39
41class RPCConsole: public QWidget
42{
43 Q_OBJECT
44
45public:
46 explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
48
49 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);
50 static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const WalletModel* wallet_model = nullptr) {
51 return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_model);
52 }
53
54 void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);
55
56#ifdef ENABLE_WALLET
57 void addWallet(WalletModel* const walletModel);
58 void removeWallet(WalletModel* const walletModel);
59#endif // ENABLE_WALLET
60
67 };
68
69 enum class TabTypes {
70 INFO,
71 CONSOLE,
72 GRAPH,
73 PEERS
74 };
75
76 std::vector<TabTypes> tabs() const { return {TabTypes::INFO, TabTypes::CONSOLE, TabTypes::GRAPH, TabTypes::PEERS}; }
77
78 QString tabTitle(TabTypes tab_type) const;
79 QKeySequence tabShortcut(TabTypes tab_type) const;
80
81protected:
82 virtual bool eventFilter(QObject* obj, QEvent *event) override;
83 void keyPressEvent(QKeyEvent *) override;
84 void changeEvent(QEvent* e) override;
85
86private Q_SLOTS:
88 void on_tabWidget_currentChanged(int index);
92 void on_sldGraphRange_valueChanged(int value);
94 void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
95 void resizeEvent(QResizeEvent *event) override;
96 void showEvent(QShowEvent *event) override;
97 void hideEvent(QHideEvent *event) override;
99 void showPeersTableContextMenu(const QPoint& point);
101 void showBanTableContextMenu(const QPoint& point);
105 void clearSelectedNode();
107 void updateDetailWidget();
108
109public Q_SLOTS:
110 void clear(bool keep_prompt = false);
111 void fontBigger();
112 void fontSmaller();
113 void setFontSize(int newSize);
115 void message(int category, const QString &msg) { message(category, msg, false); }
116 void message(int category, const QString &message, bool html);
118 void setNumConnections(int count);
120 void setNetworkActive(bool networkActive);
122 void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype);
124 void setMempoolSize(long numberOfTxs, size_t dynUsage, size_t maxUsage);
126 void browseHistory(int offset);
128 void scrollToEnd();
132 void banSelectedNode(int bantime);
134 void unbanSelectedNode();
136 void setTabFocus(enum TabTypes tabType);
137#ifdef ENABLE_WALLET
139 void setCurrentWallet(WalletModel* const wallet_model);
140#endif // ENABLE_WALLET
141
142private:
144 const QString yes{tr("Yes")}, no{tr("No")}, to{tr("To")}, from{tr("From")},
145 ban_for{tr("Ban for")}, na{tr("N/A")}, unknown{tr("Unknown")};
146 } const ts;
147
148 void startExecutor();
149 void setTrafficGraphRange(int mins);
150
152 {
158
159 };
160
162 Ui::RPCConsole* const ui;
164 QStringList history;
165 int historyPtr = 0;
167 QList<NodeId> cachedNodeids;
170 QMenu *peersTableContextMenu = nullptr;
171 QMenu *banTableContextMenu = nullptr;
173 QCompleter *autoCompleter = nullptr;
174 QThread thread;
177 bool m_is_executing{false};
180
182 void updateNetworkState();
183
185 QString TimeDurationField(std::chrono::seconds time_now, std::chrono::seconds time_at_event) const
186 {
187 return time_at_event.count() ? GUIUtil::formatDurationStr(time_now - time_at_event) : tr("Never");
188 }
189
190 void updateWindowTitle();
191
192private Q_SLOTS:
193 void updateAlerts(const QString& warnings);
194};
195
196#endif // BITCOIN_QT_RPCCONSOLE_H
Model for Bitcoin network client.
Definition: clientmodel.h:57
Local Bitcoin RPC console.
Definition: rpcconsole.h:42
QMenu * peersTableContextMenu
Definition: rpcconsole.h:170
RPCConsole(interfaces::Node &node, const PlatformStyle *platformStyle, QWidget *parent)
Definition: rpcconsole.cpp:470
struct RPCConsole::TranslatedStrings ts
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:76
void browseHistory(int offset)
Go forward or back in history.
QByteArray m_banlist_widget_header_state
Definition: rpcconsole.h:179
void fontSmaller()
Definition: rpcconsole.cpp:840
RPCTimerInterface * rpcTimerInterface
Definition: rpcconsole.h:169
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:185
void on_lineEdit_returnPressed()
QStringList history
Definition: rpcconsole.h:164
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:115
void setFontSize(int newSize)
Definition: rpcconsole.cpp:845
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:172
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:168
void setMempoolSize(long numberOfTxs, size_t dynUsage, size_t maxUsage)
Set size (number of transactions and memory usage) of the mempool in the UI.
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:971
void clear(bool keep_prompt=false)
Definition: rpcconsole.cpp:870
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
@ BANTIME_COLUMN_WIDTH
Definition: rpcconsole.h:157
@ ADDRESS_COLUMN_WIDTH
Definition: rpcconsole.h:153
@ SUBVERSION_COLUMN_WIDTH
Definition: rpcconsole.h:154
@ PING_COLUMN_WIDTH
Definition: rpcconsole.h:155
@ BANSUBNET_COLUMN_WIDTH
Definition: rpcconsole.h:156
QCompleter * autoCompleter
Definition: rpcconsole.h:173
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:167
bool m_is_executing
Definition: rpcconsole.h:177
interfaces::Node & m_node
Definition: rpcconsole.h:161
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:172
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: rpcconsole.cpp:997
void setNumBlocks(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType synctype)
Set number of blocks and last block date shown in the UI.
ClientModel * clientModel
Definition: rpcconsole.h:163
void banSelectedNode(int bantime)
Ban a selected node on the Peers tab.
int historyPtr
Definition: rpcconsole.h:165
void scrollToEnd()
Scroll console view to end.
void keyPressEvent(QKeyEvent *) override
Definition: rpcconsole.cpp:929
void on_tabWidget_currentChanged(int index)
Ui::RPCConsole *const ui
Definition: rpcconsole.h:162
void startExecutor()
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
void updateWindowTitle()
void fontBigger()
Definition: rpcconsole.cpp:835
QString cmdBeforeBrowsing
Definition: rpcconsole.h:166
virtual bool eventFilter(QObject *obj, QEvent *event) override
Definition: rpcconsole.cpp:615
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
void showBanTableContextMenu(const QPoint &point)
Show custom context menu on Bans tab.
void setClientModel(ClientModel *model=nullptr, int bestblock_height=0, int64_t bestblock_date=0, double verification_progress=0.0)
Definition: rpcconsole.cpp:659
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
QByteArray m_peer_widget_header_state
Definition: rpcconsole.h:178
void changeEvent(QEvent *e) override
Definition: rpcconsole.cpp:936
WalletModel * m_last_wallet_model
Definition: rpcconsole.h:176
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
RPCExecutor * m_executor
Definition: rpcconsole.h:175
QMenu * banTableContextMenu
Definition: rpcconsole.h:171
QThread thread
Definition: rpcconsole.h:174
RPC timer "driver".
Definition: server.h:52
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:48
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:71
SyncType
Definition: clientmodel.h:42
QString formatDurationStr(std::chrono::seconds dur)
Convert seconds into a QString with days, hours, mins, secs.
Definition: guiutil.cpp:736
Definition: messages.h:20
static int count