Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_QT_RPCCONSOLE_H6#define BITCOIN_QT_RPCCONSOLE_H8#include <bitcoin-build-config.h> // IWYU pragma: keep10#include <qt/clientmodel.h>11#include <qt/guiutil.h>12#include <qt/peertablemodel.h>14#include <net.h>16#include <QByteArray>17#include <QCompleter>18#include <QMimeData>19#include <QTextDocumentFragment>20#include <QTextEdit>21#include <QThread>22#include <QWidget>24class PlatformStyle;25class RPCExecutor;26class WalletModel;28namespace interfaces {29class Node;30}32namespace Ui {33class RPCConsole;34}36QT_BEGIN_NAMESPACE37class QDateTime;38class QMenu;39class QItemSelection;40QT_END_NAMESPACE42/** Local Bitcoin RPC console. */43class RPCConsole: public QWidget44{45Q_OBJECT47public:48explicit RPCConsole(interfaces::Node& node, const PlatformStyle *platformStyle, QWidget *parent);49~RPCConsole();51static bool RPCParseCommandLine(interfaces::Node* node, std::string& strResult, const std::string& strCommand, bool fExecute, std::string* pstrFilteredOut = nullptr, const QString& wallet_name = {});52static bool RPCExecuteCommandLine(interfaces::Node& node, std::string &strResult, const std::string &strCommand, std::string * const pstrFilteredOut = nullptr, const QString& wallet_name = {}) {53return RPCParseCommandLine(&node, strResult, strCommand, true, pstrFilteredOut, wallet_name);54}56void setClientModel(ClientModel *model = nullptr, int bestblock_height = 0, int64_t bestblock_date = 0, double verification_progress = 0.0);58#ifdef ENABLE_WALLET59void addWallet(WalletModel* walletModel);60void removeWallet(WalletModel* walletModel);61#endif // ENABLE_WALLET63enum MessageClass {64MC_ERROR,65MC_DEBUG,66CMD_REQUEST,67CMD_REPLY,68CMD_ERROR69};71enum class TabTypes {72INFO,73CONSOLE,74GRAPH,75PEERS76};78std::vector<TabTypes> tabs() const { return {TabTypes::INFO, TabTypes::CONSOLE, TabTypes::GRAPH, TabTypes::PEERS}; }80QString tabTitle(TabTypes tab_type) const;81QKeySequence tabShortcut(TabTypes tab_type) const;83protected:84virtual bool eventFilter(QObject* obj, QEvent *event) override;85void keyPressEvent(QKeyEvent *) override;86void changeEvent(QEvent* e) override;88private Q_SLOTS:89void on_lineEdit_returnPressed();90void on_tabWidget_currentChanged(int index);91/** open the debug.log from the current datadir */92void on_openDebugLogfileButton_clicked();93/** change the time range of the network traffic graph */94void on_sldGraphRange_valueChanged(int value);95/** update traffic statistics */96void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);97void resizeEvent(QResizeEvent *event) override;98void showEvent(QShowEvent *event) override;99void hideEvent(QHideEvent *event) override;100/** Show custom context menu on Peers tab */101void showPeersTableContextMenu(const QPoint& point);102/** Show custom context menu on Bans tab */103void showBanTableContextMenu(const QPoint& point);104/** Hides ban table if no bans are present */105void showOrHideBanTableIfRequired();106/** clear the selected node */107void clearSelectedNode();108/** show detailed information on ui about selected node */109void updateDetailWidget();111public Q_SLOTS:112void clear(bool keep_prompt = false);113void fontBigger();114void fontSmaller();115void setFontSize(int newSize);116/** Append the message to the message widget */117void message(int category, const QString &msg) { message(category, msg, false); }118void message(int category, const QString &message, bool html);119/** Set number of connections shown in the UI */120void setNumConnections(int count);121/** Set network state shown in the UI */122void setNetworkActive(bool networkActive);123/** Set number of blocks and last block date shown in the UI */124void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType synctype);125/** Set size (number of transactions and memory usage) of the mempool in the UI */126void setMempoolSize(long numberOfTxs, size_t dynUsage, size_t maxUsage);127/** Go forward or back in history */128void browseHistory(int offset);129/** Scroll console view to end */130void scrollToEnd();131/** Disconnect a selected node on the Peers tab */132void disconnectSelectedNode();133/** Ban a selected node on the Peers tab */134void banSelectedNode(int bantime);135/** Unban a selected node on the Bans tab */136void unbanSelectedNode();137/** set which tab has the focus (is visible) */138void setTabFocus(enum TabTypes tabType);139#ifdef ENABLE_WALLET140/** Set the current (ie - active) wallet */141void setCurrentWallet(WalletModel* wallet_model);142#endif // ENABLE_WALLET144private:145struct TranslatedStrings {146const QString yes{tr("Yes")}, no{tr("No")}, to{tr("To")}, from{tr("From")},147ban_for{tr("Ban for")}, na{tr("N/A")}, unknown{tr("Unknown")};148} const ts;150void startExecutor();151void setTrafficGraphRange(int mins);153enum ColumnWidths154{155ADDRESS_COLUMN_WIDTH = 200,156SUBVERSION_COLUMN_WIDTH = 150,157PING_COLUMN_WIDTH = 80,158BANSUBNET_COLUMN_WIDTH = 200,159BANTIME_COLUMN_WIDTH = 250161};163interfaces::Node& m_node;164Ui::RPCConsole* const ui;165ClientModel *clientModel = nullptr;166QStringList history;167int historyPtr = 0;168QString cmdBeforeBrowsing;169QList<NodeId> cachedNodeids;170const PlatformStyle* const platformStyle;171QMenu *peersTableContextMenu = nullptr;172QMenu *banTableContextMenu = nullptr;173int consoleFontSize = 0;174QCompleter *autoCompleter = nullptr;175QThread thread;176RPCExecutor* m_executor{nullptr};177WalletModel* m_last_wallet_model{nullptr};178bool m_is_executing{false};179QByteArray m_peer_widget_header_state;180QByteArray m_banlist_widget_header_state;182/** Update UI with latest network info from model. */183void updateNetworkState();185/// Format the duration between now and event as a string.186QString TimeDurationField(NodeClock::time_point now, NodeClock::time_point event) const187{188return event > NodeClock::epoch ? GUIUtil::formatDurationStr(now - event) : tr("Never");189}190/// DEPRECATED: Helper for the output of a time duration field. Inputs are UNIX epoch times.191QString TimeDurationField(std::chrono::seconds time_now, std::chrono::seconds time_at_event) const192{193return time_at_event.count() ? GUIUtil::formatDurationStr(time_now - time_at_event) : tr("Never");194}196void updateWindowTitle();198private Q_SLOTS:199void updateAlerts(const QString& warnings);200};202/**203* A version of QTextEdit that only populates plaintext mime data from a204* selection, this avoids some bad behavior in QT's HTML->Markdown conversion.205*/206class PlainCopyTextEdit : public QTextEdit {207Q_OBJECT208public:209using QTextEdit::QTextEdit;210protected:211QMimeData* createMimeDataFromSelection() const override {212auto md = new QMimeData();213md->setText(textCursor().selection().toPlainText());214return md;215}216};218#endif // BITCOIN_QT_RPCCONSOLE_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.