Bitcoin Core 22.99.0
P2P Digital Currency
rpcconsole.h
Go to the documentation of this file.
1// Copyright (c) 2011-2020 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 <QByteArray>
14#include <QCompleter>
15#include <QThread>
16#include <QWidget>
17
18class ClientModel;
19class PlatformStyle;
21class WalletModel;
22
23namespace interfaces {
24 class Node;
25}
26
27namespace Ui {
28 class RPCConsole;
29}
30
31QT_BEGIN_NAMESPACE
32class QDateTime;
33class QMenu;
34class QItemSelection;
35QT_END_NAMESPACE
36
38class RPCConsole: public QWidget
39{
40 Q_OBJECT
41
42public:
43 explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
45
46 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);
47 static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const WalletModel* wallet_model = nullptr) {
48 return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_model);
49 }
50
51 void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);
52 void addWallet(WalletModel * const walletModel);
53 void removeWallet(WalletModel* const walletModel);
54
61 };
62
63 enum class TabTypes {
64 INFO,
65 CONSOLE,
66 GRAPH,
67 PEERS
68 };
69
70 std::vector<TabTypes> tabs() const { return {TabTypes::INFO, TabTypes::CONSOLE, TabTypes::GRAPH, TabTypes::PEERS}; }
71
72 QString tabTitle(TabTypes tab_type) const;
73 QKeySequence tabShortcut(TabTypes tab_type) const;
74
75protected:
76 virtual bool eventFilter(QObject* obj, QEvent *event) override;
77 void keyPressEvent(QKeyEvent *) override;
78 void changeEvent(QEvent* e) override;
79
80private 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();
101 void updateDetailWidget();
102
103public Q_SLOTS:
104 void clear(bool keep_prompt = false);
105 void fontBigger();
106 void fontSmaller();
107 void setFontSize(int newSize);
109 void message(int category, const QString &msg) { message(category, msg, false); }
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, double nVerificationProgress, bool headers);
118 void setMempoolSize(long numberOfTxs, size_t dynUsage);
120 void browseHistory(int offset);
122 void scrollToEnd();
126 void banSelectedNode(int bantime);
128 void unbanSelectedNode();
130 void setTabFocus(enum TabTypes tabType);
131
132Q_SIGNALS:
133 // For RPC command executor
134 void cmdRequest(const QString &command, const WalletModel* wallet_model);
135
136private:
138 const QString yes{tr("Yes")}, no{tr("No")}, to{tr("To")}, from{tr("From")},
139 ban_for{tr("Ban for")}, na{tr("N/A")}, unknown{tr("Unknown")};
140 } const ts;
141
142 void startExecutor();
143 void setTrafficGraphRange(int mins);
144
146 {
152
153 };
154
158 QStringList history;
159 int historyPtr = 0;
161 QList<NodeId> cachedNodeids;
164 QMenu *peersTableContextMenu = nullptr;
165 QMenu *banTableContextMenu = nullptr;
167 QCompleter *autoCompleter = nullptr;
168 QThread thread;
170 bool m_is_executing{false};
173
175 void updateNetworkState();
176
178 QString TimeDurationField(uint64_t time_now, uint64_t time_at_event) const {
179 return time_at_event ? GUIUtil::formatDurationStr(time_now - time_at_event) : tr("Never");
180 }
181
182private Q_SLOTS:
183 void updateAlerts(const QString& warnings);
184};
185
186#endif // BITCOIN_QT_RPCCONSOLE_H
Model for Bitcoin network client.
Definition: clientmodel.h:48
Local Bitcoin RPC console.
Definition: rpcconsole.h:39
QMenu * peersTableContextMenu
Definition: rpcconsole.h:164
RPCConsole(interfaces::Node &node, const PlatformStyle *platformStyle, QWidget *parent)
Definition: rpcconsole.cpp:471
struct RPCConsole::TranslatedStrings ts
void cmdRequest(const QString &command, const WalletModel *wallet_model)
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:70
void browseHistory(int offset)
Go forward or back in history.
QByteArray m_banlist_widget_header_state
Definition: rpcconsole.h:172
void fontSmaller()
Definition: rpcconsole.cpp:822
RPCTimerInterface * rpcTimerInterface
Definition: rpcconsole.h:163
void on_lineEdit_returnPressed()
Definition: rpcconsole.cpp:994
QStringList history
Definition: rpcconsole.h:158
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:109
void setFontSize(int newSize)
Definition: rpcconsole.cpp:827
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:173
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:162
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:47
QString tabTitle(TabTypes tab_type) const
void updateNetworkState()
Update UI with latest network info from model.
Definition: rpcconsole.cpp:950
void clear(bool keep_prompt=false)
Definition: rpcconsole.cpp:852
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
@ BANTIME_COLUMN_WIDTH
Definition: rpcconsole.h:151
@ ADDRESS_COLUMN_WIDTH
Definition: rpcconsole.h:147
@ SUBVERSION_COLUMN_WIDTH
Definition: rpcconsole.h:148
@ PING_COLUMN_WIDTH
Definition: rpcconsole.h:149
@ BANSUBNET_COLUMN_WIDTH
Definition: rpcconsole.h:150
QCompleter * autoCompleter
Definition: rpcconsole.h:167
void setMempoolSize(long numberOfTxs, size_t dynUsage)
Set size (number of transactions and memory usage) of the mempool in the UI.
Definition: rpcconsole.cpp:984
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:976
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:161
bool m_is_executing
Definition: rpcconsole.h:170
interfaces::Node & m_node
Definition: rpcconsole.h:155
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:166
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: rpcconsole.cpp:963
ClientModel * clientModel
Definition: rpcconsole.h:157
void banSelectedNode(int bantime)
Ban a selected node on the Peers tab.
int historyPtr
Definition: rpcconsole.h:159
void scrollToEnd()
Scroll console view to end.
void keyPressEvent(QKeyEvent *) override
Definition: rpcconsole.cpp:907
void on_tabWidget_currentChanged(int index)
Ui::RPCConsole *const ui
Definition: rpcconsole.h:156
void startExecutor()
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Definition: rpcconsole.cpp:971
void fontBigger()
Definition: rpcconsole.cpp:817
QString cmdBeforeBrowsing
Definition: rpcconsole.h:160
void addWallet(WalletModel *const walletModel)
virtual bool eventFilter(QObject *obj, QEvent *event) override
Definition: rpcconsole.cpp:604
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
void removeWallet(WalletModel *const walletModel)
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:649
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
QByteArray m_peer_widget_header_state
Definition: rpcconsole.h:171
void changeEvent(QEvent *e) override
Definition: rpcconsole.cpp:915
WalletModel * m_last_wallet_model
Definition: rpcconsole.h:169
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
QString TimeDurationField(uint64_t time_now, uint64_t time_at_event) const
Helper for the output of a time duration field.
Definition: rpcconsole.h:178
QMenu * banTableContextMenu
Definition: rpcconsole.h:165
QThread thread
Definition: rpcconsole.h:168
RPC timer "driver".
Definition: server.h:60
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:52
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:55
QString formatDurationStr(int secs)
Convert seconds into a QString with days, hours, mins, secs.
Definition: guiutil.cpp:708
static int count
Definition: tests.c:41