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 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
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:305
CONNECTIONS_IN
@ CONNECTIONS_IN
Definition: clientmodel.h:41
ClientModel::m_handler_notify_alert_changed
std::unique_ptr< interfaces::Handler > m_handler_notify_alert_changed
Definition: clientmodel.h:95
count
static int count
Definition: tests.c:41
ClientModel::numConnectionsChanged
void numConnectionsChanged(int count)
CONNECTIONS_OUT
@ CONNECTIONS_OUT
Definition: clientmodel.h:42
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:77
flags
int flags
Definition: bitcoin-tx.cpp:512
sync.h
ClientModel::isReleaseVersion
bool isReleaseVersion() const
Definition: clientmodel.cpp:212
uint256.h
ClientModel::node
interfaces::Node & node() const
Definition: clientmodel.h:55
ClientModel::getBlockSource
enum BlockSource getBlockSource() const
Returns enum BlockSource of the current importing/syncing state.
Definition: clientmodel.cpp:165
ClientModel::peerTableSortProxy
PeerTableSortProxy * peerTableSortProxy()
Definition: clientmodel.cpp:192
ClientModel::blocksDir
QString blocksDir() const
Definition: clientmodel.cpp:227
ClientModel::m_handler_notify_num_connections_changed
std::unique_ptr< interfaces::Handler > m_handler_notify_num_connections_changed
Definition: clientmodel.h:93
BlockSource::DISK
@ DISK
AnnotatedMixin< std::mutex >
CONNECTIONS_ALL
@ CONNECTIONS_ALL
Definition: clientmodel.h:43
CONNECTIONS_NONE
@ CONNECTIONS_NONE
Definition: clientmodel.h:40
ClientModel::getStatusBarWarnings
QString getStatusBarWarnings() const
Return warnings to be displayed in status bar.
Definition: clientmodel.cpp:177
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:102
ClientModel::updateNetworkActive
void updateNetworkActive(bool networkActive)
Definition: clientmodel.cpp:155
ClientModel::m_handler_notify_block_tip
std::unique_ptr< interfaces::Handler > m_handler_notify_block_tip
Definition: clientmodel.h:97
OptionsModel
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:39
ClientModel::getOptionsModel
OptionsModel * getOptionsModel()
Definition: clientmodel.cpp:182
ClientModel::unsubscribeFromCoreSignals
void unsubscribeFromCoreSignals()
Definition: clientmodel.cpp:317
ClientModel::m_handler_notify_network_active_changed
std::unique_ptr< interfaces::Handler > m_handler_notify_network_active_changed
Definition: clientmodel.h:94
ClientModel::getPeerTableModel
PeerTableModel * getPeerTableModel()
Definition: clientmodel.cpp:187
BlockSource::REINDEX
@ REINDEX
ClientModel::GUARDED_BY
uint256 m_cached_tip_blocks GUARDED_BY(m_cached_tip_mutex)
Definition: clientmodel.h:88
ClientModel::getHeaderTipHeight
int getHeaderTipHeight() const
Definition: clientmodel.cpp:91
ClientModel::getProxyInfo
bool getProxyInfo(std::string &ip_port) const
Definition: clientmodel.cpp:329
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:32
ClientModel::getNumBlocks
int getNumBlocks() const
Definition: clientmodel.cpp:119
ClientModel::formatFullVersion
QString formatFullVersion() const
Definition: clientmodel.cpp:202
ClientModel::cachedBestHeaderTime
std::atomic< int64_t > cachedBestHeaderTime
Definition: clientmodel.h:84
uint256
256-bit opaque blob.
Definition: uint256.h:124
ClientModel::peerTableModel
PeerTableModel * peerTableModel
Definition: clientmodel.h:100
ClientModel::optionsModel
OptionsModel * optionsModel
Definition: clientmodel.h:99
BlockSource::NONE
@ NONE
ClientModel::m_node
interfaces::Node & m_node
Definition: clientmodel.h:88
PeerTableModel
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call.
Definition: peertablemodel.h:38
ClientModel::updateNumConnections
void updateNumConnections(int numConnections)
Definition: clientmodel.cpp:150
ClientModel::showProgress
void showProgress(const QString &title, int nProgress)
interfaces::Node
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:54
ClientModel::updateBanlist
void updateBanlist()
Definition: clientmodel.cpp:232
ClientModel
Model for Bitcoin network client.
Definition: clientmodel.h:47
ClientModel::formatSubVersion
QString formatSubVersion() const
Definition: clientmodel.cpp:207
ClientModel::m_handler_show_progress
std::unique_ptr< interfaces::Handler > m_handler_show_progress
Definition: clientmodel.h:92
ClientModel::m_peer_table_sort_proxy
PeerTableSortProxy * m_peer_table_sort_proxy
Definition: clientmodel.h:101
ClientModel::m_handler_notify_header_tip
std::unique_ptr< interfaces::Handler > m_handler_notify_header_tip
Definition: clientmodel.h:98
NumConnections
NumConnections
Definition: clientmodel.h:39
ClientModel::cachedBestHeaderHeight
std::atomic< int > cachedBestHeaderHeight
Definition: clientmodel.h:83
ClientModel::formatClientStartupTime
QString formatClientStartupTime() const
Definition: clientmodel.cpp:217
PeerTableSortProxy
Definition: peertablesortproxy.h:14
ClientModel::~ClientModel
~ClientModel()
Definition: clientmodel.cpp:69
ClientModel::m_cached_num_blocks
std::atomic< int > m_cached_num_blocks
Definition: clientmodel.h:85
ClientModel::dataDir
QString dataDir() const
Definition: clientmodel.cpp:222
node
Definition: interfaces.cpp:67
SynchronizationState
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:103
BlockSource
BlockSource
Definition: clientmodel.h:32
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:105
ClientModel::getBestBlockHash
uint256 getBestBlockHash()
Definition: clientmodel.cpp:127
ClientModel::m_cached_tip_mutex
Mutex m_cached_tip_mutex
Definition: clientmodel.h:87
ClientModel::m_handler_banned_list_changed
std::unique_ptr< interfaces::Handler > m_handler_banned_list_changed
Definition: clientmodel.h:96
ClientModel::networkActiveChanged
void networkActiveChanged(bool networkActive)
ClientModel::updateAlert
void updateAlert()
Definition: clientmodel.cpp:160
ClientModel::getHeaderTipTime
int64_t getHeaderTipTime() const
Definition: clientmodel.cpp:106
ClientModel::getBanTableModel
BanTableModel * getBanTableModel()
Definition: clientmodel.cpp:197