Bitcoin Core 22.99.0
P2P Digital Currency
clientmodel.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_CLIENTMODEL_H
6#define BITCOIN_QT_CLIENTMODEL_H
7
8#include <QObject>
9#include <QDateTime>
10
11#include <atomic>
12#include <memory>
13#include <sync.h>
14#include <uint256.h>
15
16class BanTableModel;
17class CBlockIndex;
18class OptionsModel;
19class PeerTableModel;
21enum class SynchronizationState;
22
23namespace interfaces {
24class Handler;
25class Node;
26}
27
28QT_BEGIN_NAMESPACE
29class QTimer;
30QT_END_NAMESPACE
31
32enum class BlockSource {
33 NONE,
34 REINDEX,
35 DISK,
37};
38
41 CONNECTIONS_IN = (1U << 0),
42 CONNECTIONS_OUT = (1U << 1),
44};
45
47class ClientModel : public QObject
48{
49 Q_OBJECT
50
51public:
52 explicit ClientModel(interfaces::Node& node, OptionsModel *optionsModel, QObject *parent = nullptr);
54
55 interfaces::Node& node() const { return m_node; }
60
62 int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
63 int getNumBlocks() const;
65 int getHeaderTipHeight() const;
66 int64_t getHeaderTipTime() const;
67
69 enum BlockSource getBlockSource() const;
71 QString getStatusBarWarnings() const;
72
73 QString formatFullVersion() const;
74 QString formatSubVersion() const;
75 bool isReleaseVersion() const;
76 QString formatClientStartupTime() const;
77 QString dataDir() const;
78 QString blocksDir() const;
79
80 bool getProxyInfo(std::string& ip_port) const;
81
82 // caches for the best header: hash, number of blocks and block time
83 mutable std::atomic<int> cachedBestHeaderHeight;
84 mutable std::atomic<int64_t> cachedBestHeaderTime;
85 mutable std::atomic<int> m_cached_num_blocks{-1};
86
88 uint256 m_cached_tip_blocks GUARDED_BY(m_cached_tip_mutex){};
89
90private:
92 std::unique_ptr<interfaces::Handler> m_handler_show_progress;
93 std::unique_ptr<interfaces::Handler> m_handler_notify_num_connections_changed;
94 std::unique_ptr<interfaces::Handler> m_handler_notify_network_active_changed;
95 std::unique_ptr<interfaces::Handler> m_handler_notify_alert_changed;
96 std::unique_ptr<interfaces::Handler> m_handler_banned_list_changed;
97 std::unique_ptr<interfaces::Handler> m_handler_notify_block_tip;
98 std::unique_ptr<interfaces::Handler> m_handler_notify_header_tip;
103
105 QThread* const m_thread;
106
109
110Q_SIGNALS:
112 void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header, SynchronizationState sync_state);
113 void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
114 void networkActiveChanged(bool networkActive);
115 void alertsChanged(const QString &warnings);
116 void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
117
119 void message(const QString &title, const QString &message, unsigned int style);
120
121 // Show progress dialog e.g. for verifychain
122 void showProgress(const QString &title, int nProgress);
123
124public Q_SLOTS:
125 void updateNumConnections(int numConnections);
126 void updateNetworkActive(bool networkActive);
127 void updateAlert();
128 void updateBanlist();
129};
130
131#endif // BITCOIN_QT_CLIENTMODEL_H
int flags
Definition: bitcoin-tx.cpp:525
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call.
Definition: bantablemodel.h:44
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:146
Model for Bitcoin network client.
Definition: clientmodel.h:48
void updateAlert()
std::unique_ptr< interfaces::Handler > m_handler_banned_list_changed
Definition: clientmodel.h:96
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut)
void updateBanlist()
void showProgress(const QString &title, int nProgress)
QString blocksDir() const
QString getStatusBarWarnings() const
Return warnings to be displayed in status bar.
uint256 getBestBlockHash()
int getHeaderTipHeight() const
Definition: clientmodel.cpp:91
std::unique_ptr< interfaces::Handler > m_handler_show_progress
Definition: clientmodel.h:92
std::atomic< int64_t > cachedBestHeaderTime
Definition: clientmodel.h:84
std::unique_ptr< interfaces::Handler > m_handler_notify_alert_changed
Definition: clientmodel.h:95
interfaces::Node & m_node
Definition: clientmodel.h:88
Mutex m_cached_tip_mutex
Definition: clientmodel.h:87
PeerTableModel * getPeerTableModel()
void updateNetworkActive(bool networkActive)
PeerTableSortProxy * peerTableSortProxy()
std::atomic< int > cachedBestHeaderHeight
Definition: clientmodel.h:83
void updateNumConnections(int numConnections)
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
void numConnectionsChanged(int count)
int getNumBlocks() const
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, bool header, SynchronizationState sync_state)
int64_t getHeaderTipTime() const
std::unique_ptr< interfaces::Handler > m_handler_notify_block_tip
Definition: clientmodel.h:97
uint256 m_cached_tip_blocks GUARDED_BY(m_cached_tip_mutex)
Definition: clientmodel.h:88
QString formatClientStartupTime() const
int getNumConnections(unsigned int flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
Definition: clientmodel.cpp:77
enum BlockSource getBlockSource() const
Returns enum BlockSource of the current importing/syncing state.
ClientModel(interfaces::Node &node, OptionsModel *optionsModel, QObject *parent=nullptr)
Definition: clientmodel.cpp:32
std::unique_ptr< interfaces::Handler > m_handler_notify_num_connections_changed
Definition: clientmodel.h:93
std::unique_ptr< interfaces::Handler > m_handler_notify_network_active_changed
Definition: clientmodel.h:94
OptionsModel * optionsModel
Definition: clientmodel.h:99
BanTableModel * banTableModel
Definition: clientmodel.h:102
QThread *const m_thread
A thread to interact with m_node asynchronously.
Definition: clientmodel.h:105
std::unique_ptr< interfaces::Handler > m_handler_notify_header_tip
Definition: clientmodel.h:98
BanTableModel * getBanTableModel()
void unsubscribeFromCoreSignals()
void alertsChanged(const QString &warnings)
QString dataDir() const
std::atomic< int > m_cached_num_blocks
Definition: clientmodel.h:85
OptionsModel * getOptionsModel()
QString formatFullVersion() const
PeerTableModel * peerTableModel
Definition: clientmodel.h:100
PeerTableSortProxy * m_peer_table_sort_proxy
Definition: clientmodel.h:101
bool getProxyInfo(std::string &ip_port) const
QString formatSubVersion() const
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes)
bool isReleaseVersion() const
void subscribeToCoreSignals()
void networkActiveChanged(bool networkActive)
interfaces::Node & node() const
Definition: clientmodel.h:55
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:39
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call.
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:55
256-bit opaque blob.
Definition: uint256.h:124
NumConnections
Definition: clientmodel.h:39
@ CONNECTIONS_IN
Definition: clientmodel.h:41
@ CONNECTIONS_NONE
Definition: clientmodel.h:40
@ CONNECTIONS_OUT
Definition: clientmodel.h:42
@ CONNECTIONS_ALL
Definition: clientmodel.h:43
BlockSource
Definition: clientmodel.h:32
static int count
Definition: tests.c:41
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:93