Bitcoin Core 29.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;
23class WalletModel;
24
25namespace interfaces {
26 class Node;
27}
28
29namespace Ui {
30 class RPCConsole;
31}
32
33QT_BEGIN_NAMESPACE
34class QDateTime;
35class QMenu;
36class QItemSelection;
37QT_END_NAMESPACE
38
40class RPCConsole: public QWidget
41{
42 Q_OBJECT
43
44public:
45 explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
47
48 static bool RPCParseCommandLine(interfaces::Node* node, std::string &strResult, const std::string &strCommand, bool fExecute, std::string * const pstrFilteredOut = nullptr, const QString& wallet_name = {});
49 static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const QString& wallet_name = {}) {
50 return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_name);
51 }
52
53 void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);
54
55#ifdef ENABLE_WALLET
56 void addWallet(WalletModel* const walletModel);
57 void removeWallet(WalletModel* const walletModel);
58#endif // ENABLE_WALLET
59
66 };
67
68 enum class TabTypes {
69 INFO,
70 CONSOLE,
71 GRAPH,
72 PEERS
73 };
74
75 std::vector<TabTypes> tabs() const { return {TabTypes::INFO, TabTypes::CONSOLE, TabTypes::GRAPH, TabTypes::PEERS}; }
76
77 QString tabTitle(TabTypes tab_type) const;
78 QKeySequence tabShortcut(TabTypes tab_type) const;
79
80protected:
81 virtual bool eventFilter(QObject* obj, QEvent *event) override;
82 void keyPressEvent(QKeyEvent *) override;
83 void changeEvent(QEvent* e) override;
84
85private Q_SLOTS:
87 void on_tabWidget_currentChanged(int index);
91 void on_sldGraphRange_valueChanged(int value);
93 void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
94 void resizeEvent(QResizeEvent *event) override;
95 void showEvent(QShowEvent *event) override;
96 void hideEvent(QHideEvent *event) override;
98 void showPeersTableContextMenu(const QPoint& point);
100 void showBanTableContextMenu(const QPoint& point);
104 void clearSelectedNode();
106 void updateDetailWidget();
107
108public Q_SLOTS:
109 void clear(bool keep_prompt = false);
110 void fontBigger();
111 void fontSmaller();
112 void setFontSize(int newSize);
114 void message(int category, const QString &msg) { message(category, msg, false); }
115 void message(int category, const QString &message, bool html);
117 void setNumConnections(int count);
119 void setNetworkActive(bool networkActive);
121 void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype);
123 void setMempoolSize(long numberOfTxs, size_t dynUsage, size_t maxUsage);
125 void browseHistory(int offset);
127 void scrollToEnd();
131 void banSelectedNode(int bantime);
133 void unbanSelectedNode();
135 void setTabFocus(enum TabTypes tabType);
136#ifdef ENABLE_WALLET
138 void setCurrentWallet(WalletModel* const wallet_model);
139#endif // ENABLE_WALLET
140
141private:
143 const QString yes{tr("Yes")}, no{tr("No")}, to{tr("To")}, from{tr("From")},
144 ban_for{tr("Ban for")}, na{tr("N/A")}, unknown{tr("Unknown")};
145 } const ts;
146
147 void startExecutor();
148 void setTrafficGraphRange(int mins);
149
151 {
157
158 };
159
161 Ui::RPCConsole* const ui;
163 QStringList history;
164 int historyPtr = 0;
166 QList<NodeId> cachedNodeids;
168 QMenu *peersTableContextMenu = nullptr;
169 QMenu *banTableContextMenu = nullptr;
171 QCompleter *autoCompleter = nullptr;
172 QThread thread;
175 bool m_is_executing{false};
178
180 void updateNetworkState();
181
183 QString TimeDurationField(std::chrono::seconds time_now, std::chrono::seconds time_at_event) const
184 {
185 return time_at_event.count() ? GUIUtil::formatDurationStr(time_now - time_at_event) : tr("Never");
186 }
187
188 void updateWindowTitle();
189
190private Q_SLOTS:
191 void updateAlerts(const QString& warnings);
192};
193
194#endif // BITCOIN_QT_RPCCONSOLE_H
Model for Bitcoin network client.
Definition: clientmodel.h:57
Local Bitcoin RPC console.
Definition: rpcconsole.h:41
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:49
QMenu * peersTableContextMenu
Definition: rpcconsole.h:168
RPCConsole(interfaces::Node &node, const PlatformStyle *platformStyle, QWidget *parent)
Definition: rpcconsole.cpp:434
struct RPCConsole::TranslatedStrings ts
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:75
void browseHistory(int offset)
Go forward or back in history.
static bool RPCParseCommandLine(interfaces::Node *node, std::string &strResult, const std::string &strCommand, bool fExecute, std::string *const pstrFilteredOut=nullptr, const QString &wallet_name={})
Split shell command line into a list of arguments and optionally execute the command(s).
Definition: rpcconsole.cpp:138
QByteArray m_banlist_widget_header_state
Definition: rpcconsole.h:177
void fontSmaller()
Definition: rpcconsole.cpp:796
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:183
void on_lineEdit_returnPressed()
Definition: rpcconsole.cpp:986
QStringList history
Definition: rpcconsole.h:163
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:114
void setFontSize(int newSize)
Definition: rpcconsole.cpp:801
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
void setTrafficGraphRange(int mins)
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:167
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:974
void updateDetailWidget()
show detailed information on ui about selected node
void showEvent(QShowEvent *event) override
void resizeEvent(QResizeEvent *event) override
QString tabTitle(TabTypes tab_type) const
void updateNetworkState()
Update UI with latest network info from model.
Definition: rpcconsole.cpp:927
void clear(bool keep_prompt=false)
Definition: rpcconsole.cpp:826
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
@ BANTIME_COLUMN_WIDTH
Definition: rpcconsole.h:156
@ ADDRESS_COLUMN_WIDTH
Definition: rpcconsole.h:152
@ SUBVERSION_COLUMN_WIDTH
Definition: rpcconsole.h:153
@ PING_COLUMN_WIDTH
Definition: rpcconsole.h:154
@ BANSUBNET_COLUMN_WIDTH
Definition: rpcconsole.h:155
QCompleter * autoCompleter
Definition: rpcconsole.h:171
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:166
bool m_is_executing
Definition: rpcconsole.h:175
interfaces::Node & m_node
Definition: rpcconsole.h:160
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:170
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: rpcconsole.cpp:953
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:966
ClientModel * clientModel
Definition: rpcconsole.h:162
void banSelectedNode(int bantime)
Ban a selected node on the Peers tab.
int historyPtr
Definition: rpcconsole.h:164
void scrollToEnd()
Scroll console view to end.
void keyPressEvent(QKeyEvent *) override
Definition: rpcconsole.cpp:885
void on_tabWidget_currentChanged(int index)
Ui::RPCConsole *const ui
Definition: rpcconsole.h:161
void startExecutor()
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Definition: rpcconsole.cpp:961
void updateWindowTitle()
void fontBigger()
Definition: rpcconsole.cpp:791
QString cmdBeforeBrowsing
Definition: rpcconsole.h:165
virtual bool eventFilter(QObject *obj, QEvent *event) override
Definition: rpcconsole.cpp:571
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:615
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
QByteArray m_peer_widget_header_state
Definition: rpcconsole.h:176
void changeEvent(QEvent *e) override
Definition: rpcconsole.cpp:892
WalletModel * m_last_wallet_model
Definition: rpcconsole.h:174
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
RPCExecutor * m_executor
Definition: rpcconsole.h:173
QMenu * banTableContextMenu
Definition: rpcconsole.h:169
QThread thread
Definition: rpcconsole.h:172
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:49
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:70
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