Bitcoin Core  22.0.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 
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 }
27 
28 QT_BEGIN_NAMESPACE
29 class QTimer;
30 QT_END_NAMESPACE
31 
32 enum class BlockSource {
33  NONE,
34  REINDEX,
35  DISK,
36  NETWORK
37 };
38 
41  CONNECTIONS_IN = (1U << 0),
42  CONNECTIONS_OUT = (1U << 1),
44 };
45 
47 class ClientModel : public QObject
48 {
49  Q_OBJECT
50 
51 public:
52  explicit ClientModel(interfaces::Node& node, OptionsModel *optionsModel, QObject *parent = nullptr);
53  ~ClientModel();
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 
90 private:
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 
107  void subscribeToCoreSignals();
109 
110 Q_SIGNALS:
111  void numConnectionsChanged(int count);
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 
124 public 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
QString formatClientStartupTime() const
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
PeerTableModel * peerTableModel
Definition: clientmodel.h:100
void updateNetworkActive(bool networkActive)
QString formatSubVersion() const
interfaces::Node & m_node
Definition: clientmodel.h:88
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:102
bool isReleaseVersion() const
std::atomic< int64_t > cachedBestHeaderTime
Definition: clientmodel.h:84
void updateBanlist()
QString blocksDir() const
QThread *const m_thread
A thread to interact with m_node asynchronously.
Definition: clientmodel.h:105
void networkActiveChanged(bool networkActive)
BanTableModel * banTableModel
Definition: clientmodel.h:102
ClientModel(interfaces::Node &node, OptionsModel *optionsModel, QObject *parent=nullptr)
Definition: clientmodel.cpp:32
std::unique_ptr< interfaces::Handler > m_handler_show_progress
Definition: clientmodel.h:92
OptionsModel * getOptionsModel()
Mutex m_cached_tip_mutex
Definition: clientmodel.h:87
std::atomic< int > cachedBestHeaderHeight
Definition: clientmodel.h:83
PeerTableModel * getPeerTableModel()
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, bool header, SynchronizationState sync_state)
void numConnectionsChanged(int count)
QString getStatusBarWarnings() const
Return warnings to be displayed in status bar.
void alertsChanged(const QString &warnings)
std::unique_ptr< interfaces::Handler > m_handler_notify_block_tip
Definition: clientmodel.h:97
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut)
std::atomic< int > m_cached_num_blocks
Definition: clientmodel.h:85
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.
NumConnections
Definition: clientmodel.h:39
PeerTableSortProxy * m_peer_table_sort_proxy
Definition: clientmodel.h:101
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call...
BlockSource
Definition: clientmodel.h:32
void unsubscribeFromCoreSignals()
BanTableModel * getBanTableModel()
interfaces::Node & node() const
Definition: clientmodel.h:55
void subscribeToCoreSignals()
std::unique_ptr< interfaces::Handler > m_handler_banned_list_changed
Definition: clientmodel.h:96
Model for Bitcoin network client.
Definition: clientmodel.h:47
std::unique_ptr< interfaces::Handler > m_handler_notify_header_tip
Definition: clientmodel.h:98
int flags
Definition: bitcoin-tx.cpp:512
256-bit opaque blob.
Definition: uint256.h:124
void updateAlert()
std::unique_ptr< interfaces::Handler > m_handler_notify_num_connections_changed
Definition: clientmodel.h:93
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:39
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:137
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call...
Definition: bantablemodel.h:42
static int count
Definition: tests.c:41
OptionsModel * optionsModel
Definition: clientmodel.h:99
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes)
QString dataDir() const
uint256 getBestBlockHash()
std::unique_ptr< interfaces::Handler > m_handler_notify_network_active_changed
Definition: clientmodel.h:94
int getNumBlocks() const
uint256 m_cached_tip_blocks GUARDED_BY(m_cached_tip_mutex)
Definition: clientmodel.h:88
void updateNumConnections(int numConnections)
PeerTableSortProxy * peerTableSortProxy()
int getHeaderTipHeight() const
Definition: clientmodel.cpp:91
std::unique_ptr< interfaces::Handler > m_handler_notify_alert_changed
Definition: clientmodel.h:95
int64_t getHeaderTipTime() const
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:54
void showProgress(const QString &title, int nProgress)
QString formatFullVersion() const
bool getProxyInfo(std::string &ip_port) const