Bitcoin Core  27.99.0
P2P Digital Currency
clientmodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2022 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 
16 class BanTableModel;
17 class CBlockIndex;
18 class OptionsModel;
19 class PeerTableModel;
20 class PeerTableSortProxy;
21 enum class SynchronizationState;
22 
23 namespace interfaces {
24 class Handler;
25 class Node;
26 struct BlockTip;
27 }
28 
29 QT_BEGIN_NAMESPACE
30 class QTimer;
31 QT_END_NAMESPACE
32 
33 enum class BlockSource {
34  NONE,
35  DISK,
36  NETWORK,
37 };
38 
39 enum class SyncType {
43 };
44 
47  CONNECTIONS_IN = (1U << 0),
48  CONNECTIONS_OUT = (1U << 1),
50 };
51 
53 class ClientModel : public QObject
54 {
55  Q_OBJECT
56 
57 public:
58  explicit ClientModel(interfaces::Node& node, OptionsModel *optionsModel, QObject *parent = nullptr);
59  ~ClientModel();
60 
61  void stop();
62 
63  interfaces::Node& node() const { return m_node; }
68 
70  int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
71  int getNumBlocks() const;
73  int getHeaderTipHeight() const;
74  int64_t getHeaderTipTime() const;
75 
79  QString getStatusBarWarnings() const;
80 
81  QString formatFullVersion() const;
82  QString formatSubVersion() const;
83  bool isReleaseVersion() const;
84  QString formatClientStartupTime() const;
85  QString dataDir() const;
86  QString blocksDir() const;
87 
88  bool getProxyInfo(std::string& ip_port) const;
89 
90  // caches for the best header: hash, number of blocks and block time
91  mutable std::atomic<int> cachedBestHeaderHeight;
92  mutable std::atomic<int64_t> cachedBestHeaderTime;
93  mutable std::atomic<int> m_cached_num_blocks{-1};
94 
96  uint256 m_cached_tip_blocks GUARDED_BY(m_cached_tip_mutex){};
97 
98 private:
100  std::vector<std::unique_ptr<interfaces::Handler>> m_event_handlers;
105 
107  QThread* const m_thread;
108 
109  void TipChanged(SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress, SyncType synctype) EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex);
110  void subscribeToCoreSignals();
112 
113 Q_SIGNALS:
115  void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, SyncType header, SynchronizationState sync_state);
116  void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
117  void networkActiveChanged(bool networkActive);
118  void alertsChanged(const QString &warnings);
119  void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
120 
122  void message(const QString &title, const QString &message, unsigned int style);
123 
124  // Show progress dialog e.g. for verifychain
125  void showProgress(const QString &title, int nProgress);
126 };
127 
128 #endif // BITCOIN_QT_CLIENTMODEL_H
int flags
Definition: bitcoin-tx.cpp:530
Qt model providing information about banned 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:141
Model for Bitcoin network client.
Definition: clientmodel.h:54
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut)
void showProgress(const QString &title, int nProgress)
QString blocksDir() const
QString getStatusBarWarnings() const
Return warnings to be displayed in status bar.
std::vector< std::unique_ptr< interfaces::Handler > > m_event_handlers
Definition: clientmodel.h:100
int getHeaderTipHeight() const
std::atomic< int64_t > cachedBestHeaderTime
Definition: clientmodel.h:92
interfaces::Node & m_node
Definition: clientmodel.h:96
interfaces::Node & node() const
Definition: clientmodel.h:63
Mutex m_cached_tip_mutex
Definition: clientmodel.h:95
PeerTableModel * getPeerTableModel()
PeerTableSortProxy * peerTableSortProxy()
std::atomic< int > cachedBestHeaderHeight
Definition: clientmodel.h:91
uint256 getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex)
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)
BlockSource getBlockSource() const
Returns the block source of the current importing/syncing state.
int getNumBlocks() const
int64_t getHeaderTipTime() const
uint256 m_cached_tip_blocks GUARDED_BY(m_cached_tip_mutex)
Definition: clientmodel.h:96
QString formatClientStartupTime() const
int getNumConnections(unsigned int flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
Definition: clientmodel.cpp:86
ClientModel(interfaces::Node &node, OptionsModel *optionsModel, QObject *parent=nullptr)
Definition: clientmodel.cpp:38
OptionsModel * optionsModel
Definition: clientmodel.h:101
BanTableModel * banTableModel
Definition: clientmodel.h:104
QThread *const m_thread
A thread to interact with m_node asynchronously.
Definition: clientmodel.h:107
BanTableModel * getBanTableModel()
void unsubscribeFromCoreSignals()
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType header, SynchronizationState sync_state)
void TipChanged(SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress, SyncType synctype) EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex)
void alertsChanged(const QString &warnings)
QString dataDir() const
std::atomic< int > m_cached_num_blocks
Definition: clientmodel.h:93
OptionsModel * getOptionsModel()
QString formatFullVersion() const
PeerTableModel * peerTableModel
Definition: clientmodel.h:102
PeerTableSortProxy * m_peer_table_sort_proxy
Definition: clientmodel.h:103
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)
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:43
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:70
256-bit opaque blob.
Definition: uint256.h:106
SyncType
Definition: clientmodel.h:39
@ HEADER_PRESYNC
NumConnections
Definition: clientmodel.h:45
@ CONNECTIONS_IN
Definition: clientmodel.h:47
@ CONNECTIONS_NONE
Definition: clientmodel.h:46
@ CONNECTIONS_OUT
Definition: clientmodel.h:48
@ CONNECTIONS_ALL
Definition: clientmodel.h:49
BlockSource
Definition: clientmodel.h:33
Definition: init.h:25
Block tip (could be a header or not, depends on the subscribed signal).
Definition: node.h:276
static int count
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:80