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_CLIENTMODEL_H6#define BITCOIN_QT_CLIENTMODEL_H8#include <QObject>9#include <QDateTime>11#include <atomic>12#include <memory>13#include <sync.h>14#include <uint256.h>16#include <netaddress.h>18class BanTableModel;19class CBlockIndex;20class OptionsModel;21class PeerTableModel;22class PeerTableSortProxy;23enum class SynchronizationState;24struct LocalServiceInfo;26namespace interfaces {27class Handler;28class Node;29struct BlockTip;30}32QT_BEGIN_NAMESPACE33class QTimer;34QT_END_NAMESPACE36enum class BlockSource {37NONE,38DISK,39NETWORK,40};42enum class SyncType {43HEADER_PRESYNC,44HEADER_SYNC,45BLOCK_SYNC46};48enum NumConnections {49CONNECTIONS_NONE = 0,50CONNECTIONS_IN = (1U << 0),51CONNECTIONS_OUT = (1U << 1),52CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT),53};55/** Model for Bitcoin network client. */56class ClientModel : public QObject57{58Q_OBJECT60public:61explicit ClientModel(interfaces::Node& node, OptionsModel *optionsModel, QObject *parent = nullptr);62~ClientModel();64void stop();66interfaces::Node& node() const { return m_node; }67OptionsModel *getOptionsModel();68PeerTableModel *getPeerTableModel();69PeerTableSortProxy* peerTableSortProxy();70BanTableModel *getBanTableModel();72//! Return number of connections, default is in- and outbound (total)73int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;74std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;75int getNumBlocks() const;76uint256 getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex);77int getHeaderTipHeight() const;78int64_t getHeaderTipTime() const;80//! Returns the block source of the current importing/syncing state81BlockSource getBlockSource() const;82//! Return warnings to be displayed in status bar83QString getStatusBarWarnings() const;85QString formatFullVersion() const;86QString formatSubVersion() const;87bool isReleaseVersion() const;88QString formatClientStartupTime() const;89QString dataDir() const;90QString blocksDir() const;92bool getProxyInfo(std::string& ip_port) const;94// caches for the best header: hash, number of blocks and block time95mutable std::atomic<int> cachedBestHeaderHeight;96mutable std::atomic<int64_t> cachedBestHeaderTime;97mutable std::atomic<int> m_cached_num_blocks{-1};99Mutex m_cached_tip_mutex;100uint256 m_cached_tip_blocks GUARDED_BY(m_cached_tip_mutex){};102private:103interfaces::Node& m_node;104std::vector<std::unique_ptr<interfaces::Handler>> m_event_handlers;105OptionsModel *optionsModel;106PeerTableModel* peerTableModel{nullptr};107PeerTableSortProxy* m_peer_table_sort_proxy{nullptr};108BanTableModel* banTableModel{nullptr};110//! A thread to interact with m_node asynchronously111QThread* const m_thread;113void TipChanged(SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress, SyncType synctype) EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex);114void subscribeToCoreSignals();115void unsubscribeFromCoreSignals();117Q_SIGNALS:118void numConnectionsChanged(int count);119void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType header, SynchronizationState sync_state);120void mempoolSizeChanged(long count, size_t mempoolSizeInBytes, size_t mempoolMaxSizeInBytes);121void networkActiveChanged(bool networkActive);122void alertsChanged(const QString &warnings);123void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);125//! Fired when a message should be reported to the user126void message(const QString &title, const QString &message, unsigned int style);128// Show progress dialog e.g. for verifychain129void showProgress(const QString &title, int nProgress);130};132#endif // BITCOIN_QT_CLIENTMODEL_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.