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