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