Bitcoin Core  21.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 <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 QDateTime;
32 class QMenu;
33 class QItemSelection;
34 QT_END_NAMESPACE
35 
37 class RPCConsole: public QWidget
38 {
39  Q_OBJECT
40 
41 public:
42  explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);
43  ~RPCConsole();
44 
45  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);
46  static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const WalletModel* wallet_model = nullptr) {
47  return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_model);
48  }
49 
50  void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);
51  void addWallet(WalletModel * const walletModel);
52  void removeWallet(WalletModel* const walletModel);
53 
54  enum MessageClass {
60  };
61 
62  enum class TabTypes {
63  INFO,
64  CONSOLE,
65  GRAPH,
66  PEERS
67  };
68 
69  std::vector<TabTypes> tabs() const { return {TabTypes::INFO, TabTypes::CONSOLE, TabTypes::GRAPH, TabTypes::PEERS}; }
70 
71  QString tabTitle(TabTypes tab_type) const;
72  QKeySequence tabShortcut(TabTypes tab_type) const;
73 
74 protected:
75  virtual bool eventFilter(QObject* obj, QEvent *event) override;
76  void keyPressEvent(QKeyEvent *) override;
77 
78 private Q_SLOTS:
80  void on_tabWidget_currentChanged(int index);
84  void on_sldGraphRange_valueChanged(int value);
86  void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
87  void resizeEvent(QResizeEvent *event) override;
88  void showEvent(QShowEvent *event) override;
89  void hideEvent(QHideEvent *event) override;
91  void showPeersTableContextMenu(const QPoint& point);
93  void showBanTableContextMenu(const QPoint& point);
97  void clearSelectedNode();
99  void updateDetailWidget();
100 
101 public Q_SLOTS:
102  void clear(bool clearHistory = true);
103  void fontBigger();
104  void fontSmaller();
105  void setFontSize(int newSize);
107  void message(int category, const QString &msg) { message(category, msg, false); }
108  void message(int category, const QString &message, bool html);
110  void setNumConnections(int count);
112  void setNetworkActive(bool networkActive);
114  void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool headers);
116  void setMempoolSize(long numberOfTxs, size_t dynUsage);
118  void browseHistory(int offset);
120  void scrollToEnd();
124  void peerLayoutChanged();
126  void disconnectSelectedNode();
128  void banSelectedNode(int bantime);
130  void unbanSelectedNode();
132  void setTabFocus(enum TabTypes tabType);
133 
134 Q_SIGNALS:
135  // For RPC command executor
136  void cmdRequest(const QString &command, const WalletModel* wallet_model);
137 
138 private:
140  const QString yes{tr("Yes")}, no{tr("No")}, to{tr("To")}, from{tr("From")},
141  ban_for{tr("Ban for")}, na{tr("N/A")}, unknown{tr("Unknown")};
142  } const ts;
143 
144  void startExecutor();
145  void setTrafficGraphRange(int mins);
146 
148  {
154 
155  };
156 
158  Ui::RPCConsole* const ui;
160  QStringList history;
161  int historyPtr = 0;
163  QList<NodeId> cachedNodeids;
166  QMenu *peersTableContextMenu = nullptr;
167  QMenu *banTableContextMenu = nullptr;
169  QCompleter *autoCompleter = nullptr;
170  QThread thread;
172 
174  void updateNetworkState();
175 
177  QString TimeDurationField(uint64_t time_now, uint64_t time_at_event) const {
178  return time_at_event ? GUIUtil::formatDurationStr(time_now - time_at_event) : tr("Never");
179  }
180 
181 private Q_SLOTS:
182  void updateAlerts(const QString& warnings);
183 };
184 
185 #endif // BITCOIN_QT_RPCCONSOLE_H
RPCConsole::TabTypes::CONSOLE
@ CONSOLE
interfaces
Definition: dummywallet.cpp:10
RPCConsole::TranslatedStrings::yes
const QString yes
Definition: rpcconsole.h:140
RPCConsole::setNumConnections
void setNumConnections(int count)
Set number of connections shown in the UI.
Definition: rpcconsole.cpp:872
count
static int count
Definition: tests.c:35
RPCConsole::ADDRESS_COLUMN_WIDTH
@ ADDRESS_COLUMN_WIDTH
Definition: rpcconsole.h:149
RPCConsole::TranslatedStrings::from
const QString from
Definition: rpcconsole.h:140
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
RPCConsole::TimeDurationField
QString TimeDurationField(uint64_t time_now, uint64_t time_at_event) const
Helper for the output of a time duration field.
Definition: rpcconsole.h:177
RPCConsole::startExecutor
void startExecutor()
Definition: rpcconsole.cpp:979
RPCTimerInterface
RPC timer "driver".
Definition: server.h:60
RPCConsole::resizeEvent
void resizeEvent(QResizeEvent *event) override
Definition: rpcconsole.cpp:1169
RPCConsole::clearSelectedNode
void clearSelectedNode()
clear the selected node
Definition: rpcconsole.cpp:1262
RPCConsole::TranslatedStrings::ban_for
const QString ban_for
Definition: rpcconsole.h:141
RPCConsole::keyPressEvent
void keyPressEvent(QKeyEvent *) override
Definition: rpcconsole.cpp:835
RPCConsole::platformStyle
const PlatformStyle *const platformStyle
Definition: rpcconsole.h:164
RPCConsole::updateNetworkState
void updateNetworkState()
Update UI with latest network info from model.
Definition: rpcconsole.cpp:859
RPCConsole::CMD_REQUEST
@ CMD_REQUEST
Definition: rpcconsole.h:57
RPCConsole::showOrHideBanTableIfRequired
void showOrHideBanTableIfRequired()
Hides ban table if no bans are present.
Definition: rpcconsole.cpp:1269
RPCConsole::autoCompleter
QCompleter * autoCompleter
Definition: rpcconsole.h:169
RPCConsole::CMD_ERROR
@ CMD_ERROR
Definition: rpcconsole.h:59
RPCConsole::setTrafficGraphRange
void setTrafficGraphRange(int mins)
Definition: rpcconsole.cpp:1026
RPCConsole::RPCParseCommandLine
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:153
RPCConsole::ui
Ui::RPCConsole *const ui
Definition: rpcconsole.h:158
RPCConsole::fontSmaller
void fontSmaller()
Definition: rpcconsole.cpp:754
RPCConsole::setMempoolSize
void setMempoolSize(long numberOfTxs, size_t dynUsage)
Set size (number of transactions and memory usage) of the mempool in the UI.
Definition: rpcconsole.cpp:893
RPCConsole::tabShortcut
QKeySequence tabShortcut(TabTypes tab_type) const
Definition: rpcconsole.cpp:1289
RPCConsole::peerLayoutChanged
void peerLayoutChanged()
Handle updated peer information.
Definition: rpcconsole.cpp:1047
RPCConsole::cachedNodeids
QList< NodeId > cachedNodeids
Definition: rpcconsole.h:163
RPCConsole::addWallet
void addWallet(WalletModel *const walletModel)
RPCConsole::updateTrafficStats
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
update traffic statistics
Definition: rpcconsole.cpp:1032
RPCConsole::MC_DEBUG
@ MC_DEBUG
Definition: rpcconsole.h:56
RPCConsole::consoleFontSize
int consoleFontSize
Definition: rpcconsole.h:168
RPCConsole::updateAlerts
void updateAlerts(const QString &warnings)
Definition: rpcconsole.cpp:1301
RPCConsole::setNetworkActive
void setNetworkActive(bool networkActive)
Set network state shown in the UI.
Definition: rpcconsole.cpp:880
RPCConsole::scrollToEnd
void scrollToEnd()
Scroll console view to end.
Definition: rpcconsole.cpp:1013
RPCConsole::removeWallet
void removeWallet(WalletModel *const walletModel)
RPCConsole::showPeersTableContextMenu
void showPeersTableContextMenu(const QPoint &point)
Show custom context menu on Peers tab.
Definition: rpcconsole.cpp:1196
RPCConsole::TranslatedStrings
Definition: rpcconsole.h:139
RPCConsole::setFontSize
void setFontSize(int newSize)
Definition: rpcconsole.cpp:759
RPCConsole::RPCConsole
RPCConsole(interfaces::Node &node, const PlatformStyle *platformStyle, QWidget *parent)
Definition: rpcconsole.cpp:448
RPCConsole::cmdRequest
void cmdRequest(const QString &command, const WalletModel *wallet_model)
RPCConsole::m_last_wallet_model
WalletModel * m_last_wallet_model
Definition: rpcconsole.h:171
RPCConsole::setClientModel
void setClientModel(ClientModel *model=nullptr, int bestblock_height=0, int64_t bestblock_date=0, double verification_progress=0.0)
Definition: rpcconsole.cpp:576
RPCConsole::CMD_REPLY
@ CMD_REPLY
Definition: rpcconsole.h:58
RPCConsole::showEvent
void showEvent(QShowEvent *event) override
Definition: rpcconsole.cpp:1174
RPCConsole::on_tabWidget_currentChanged
void on_tabWidget_currentChanged(int index)
Definition: rpcconsole.cpp:1001
RPCConsole::disconnectSelectedNode
void disconnectSelectedNode()
Disconnect a selected node on the Peers tab.
Definition: rpcconsole.cpp:1210
RPCConsole
Local Bitcoin RPC console.
Definition: rpcconsole.h:37
RPCConsole::MessageClass
MessageClass
Definition: rpcconsole.h:54
RPCConsole::TranslatedStrings::to
const QString to
Definition: rpcconsole.h:140
RPCConsole::ColumnWidths
ColumnWidths
Definition: rpcconsole.h:147
RPCConsole::BANSUBNET_COLUMN_WIDTH
@ BANSUBNET_COLUMN_WIDTH
Definition: rpcconsole.h:152
guiutil.h
RPCConsole::MC_ERROR
@ MC_ERROR
Definition: rpcconsole.h:55
RPCConsole::PING_COLUMN_WIDTH
@ PING_COLUMN_WIDTH
Definition: rpcconsole.h:151
RPCConsole::showBanTableContextMenu
void showBanTableContextMenu(const QPoint &point)
Show custom context menu on Bans tab.
Definition: rpcconsole.cpp:1203
RPCConsole::SUBVERSION_COLUMN_WIDTH
@ SUBVERSION_COLUMN_WIDTH
Definition: rpcconsole.h:150
RPCConsole::BANTIME_COLUMN_WIDTH
@ BANTIME_COLUMN_WIDTH
Definition: rpcconsole.h:153
RPCConsole::hideEvent
void hideEvent(QHideEvent *event) override
Definition: rpcconsole.cpp:1185
RPCConsole::updateDetailWidget
void updateDetailWidget()
show detailed information on ui about selected node
Definition: rpcconsole.cpp:1099
RPCConsole::m_node
interfaces::Node & m_node
Definition: rpcconsole.h:157
RPCConsole::thread
QThread thread
Definition: rpcconsole.h:170
RPCConsole::TabTypes::GRAPH
@ GRAPH
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:53
RPCConsole::tabTitle
QString tabTitle(TabTypes tab_type) const
Definition: rpcconsole.cpp:1284
RPCConsole::TranslatedStrings::na
const QString na
Definition: rpcconsole.h:141
RPCConsole::~RPCConsole
~RPCConsole()
Definition: rpcconsole.cpp:521
RPCConsole::history
QStringList history
Definition: rpcconsole.h:160
RPCConsole::TranslatedStrings::unknown
const QString unknown
Definition: rpcconsole.h:141
RPCConsole::TabTypes
TabTypes
Definition: rpcconsole.h:62
RPCConsole::cmdBeforeBrowsing
QString cmdBeforeBrowsing
Definition: rpcconsole.h:162
ClientModel
Model for Bitcoin network client.
Definition: clientmodel.h:46
RPCConsole::eventFilter
virtual bool eventFilter(QObject *obj, QEvent *event) override
Definition: rpcconsole.cpp:531
Ui
Definition: addressbookpage.h:14
RPCConsole::setTabFocus
void setTabFocus(enum TabTypes tabType)
set which tab has the focus (is visible)
Definition: rpcconsole.cpp:1279
RPCConsole::on_lineEdit_returnPressed
void on_lineEdit_returnPressed()
Definition: rpcconsole.cpp:903
RPCConsole::peersTableContextMenu
QMenu * peersTableContextMenu
Definition: rpcconsole.h:166
RPCConsole::RPCExecuteCommandLine
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:46
RPCConsole::message
void message(int category, const QString &msg)
Append the message to the message widget.
Definition: rpcconsole.h:107
node
Definition: interfaces.cpp:66
RPCConsole::on_openDebugLogfileButton_clicked
void on_openDebugLogfileButton_clicked()
open the debug.log from the current datadir
Definition: rpcconsole.cpp:1008
GUIUtil::formatDurationStr
QString formatDurationStr(int secs)
Convert seconds into a QString with days, hours, mins, secs.
Definition: guiutil.cpp:682
RPCConsole::browseHistory
void browseHistory(int offset)
Go forward or back in history.
Definition: rpcconsole.cpp:958
RPCConsole::historyPtr
int historyPtr
Definition: rpcconsole.h:161
RPCConsole::on_sldGraphRange_valueChanged
void on_sldGraphRange_valueChanged(int value)
change the time range of the network traffic graph
Definition: rpcconsole.cpp:1019
RPCConsole::setNumBlocks
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:885
RPCConsole::fontBigger
void fontBigger()
Definition: rpcconsole.cpp:749
RPCConsole::TranslatedStrings::no
const QString no
Definition: rpcconsole.h:140
peertablemodel.h
net.h
PlatformStyle
Definition: platformstyle.h:13
RPCConsole::unbanSelectedNode
void unbanSelectedNode()
Unban a selected node on the Bans tab.
Definition: rpcconsole.cpp:1241
RPCConsole::ts
struct RPCConsole::TranslatedStrings ts
RPCConsole::clear
void clear(bool clearHistory=true)
Definition: rpcconsole.cpp:784
RPCConsole::tabs
std::vector< TabTypes > tabs() const
Definition: rpcconsole.h:69
RPCConsole::rpcTimerInterface
RPCTimerInterface * rpcTimerInterface
Definition: rpcconsole.h:165
RPCConsole::banSelectedNode
void banSelectedNode(int bantime)
Ban a selected node on the Peers tab.
Definition: rpcconsole.cpp:1224
RPCConsole::peerLayoutAboutToChange
void peerLayoutAboutToChange()
Handle selection caching before update.
Definition: rpcconsole.cpp:1038
RPCConsole::clientModel
ClientModel * clientModel
Definition: rpcconsole.h:159
RPCConsole::banTableContextMenu
QMenu * banTableContextMenu
Definition: rpcconsole.h:167
RPCConsole::TabTypes::INFO
@ INFO
RPCConsole::TabTypes::PEERS
@ PEERS