Bitcoin ABC  0.28.12
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 struct BlockTip;
28 } // namespace interfaces
29 
30 QT_BEGIN_NAMESPACE
31 class QTimer;
32 QT_END_NAMESPACE
33 
34 enum class BlockSource { NONE, REINDEX, DISK, NETWORK };
35 
37 
39 class ClientModel : public QObject {
40  Q_OBJECT
41 
42 public:
45  CONNECTIONS_IN = (1U << 0),
46  CONNECTIONS_OUT = (1U << 1),
48  };
49 
51  QObject *parent = nullptr);
52  ~ClientModel();
53 
54  interfaces::Node &node() const { return m_node; }
58 
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  BlockHash 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>
93  std::unique_ptr<interfaces::Handler>
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;
102 
104  QThread *const m_thread;
105 
107  double verification_progress, SyncType synctype);
108  void subscribeToCoreSignals();
110 
111 Q_SIGNALS:
113  void numBlocksChanged(int count, const QDateTime &blockDate,
114  double nVerificationProgress, SyncType header,
115  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,
123  unsigned int style);
124 
125  // Show progress dialog e.g. for verifychain
126  void showProgress(const QString &title, int nProgress);
127 };
128 
129 #endif // BITCOIN_QT_CLIENTMODEL_H
int flags
Definition: bitcoin-tx.cpp:533
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call.
Definition: bantablemodel.h:42
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:26
Model for Bitcoin network client.
Definition: clientmodel.h:39
std::unique_ptr< interfaces::Handler > m_handler_banned_list_changed
Definition: clientmodel.h:96
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.
int getHeaderTipHeight() const
Definition: clientmodel.cpp:82
std::unique_ptr< interfaces::Handler > m_handler_show_progress
Definition: clientmodel.h:90
std::atomic< int64_t > cachedBestHeaderTime
Definition: clientmodel.h:82
std::unique_ptr< interfaces::Handler > m_handler_notify_alert_changed
Definition: clientmodel.h:95
interfaces::Node & m_node
Definition: clientmodel.h:89
interfaces::Node & node() const
Definition: clientmodel.h:54
Mutex m_cached_tip_mutex
Definition: clientmodel.h:85
PeerTableModel * getPeerTableModel()
BlockHash m_cached_tip_blocks GUARDED_BY(m_cached_tip_mutex)
std::atomic< int > cachedBestHeaderHeight
Definition: clientmodel.h:81
BlockHash getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex)
int getNumConnections(NumConnections flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
Definition: clientmodel.cpp:68
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)
@ CONNECTIONS_NONE
Definition: clientmodel.h:44
int getNumBlocks() const
int64_t getHeaderTipTime() const
Definition: clientmodel.cpp:96
std::unique_ptr< interfaces::Handler > m_handler_notify_block_tip
Definition: clientmodel.h:97
QString formatClientStartupTime() const
enum BlockSource getBlockSource() const
Returns enum BlockSource of the current importing/syncing state.
ClientModel(interfaces::Node &node, OptionsModel *optionsModel, QObject *parent=nullptr)
Definition: clientmodel.cpp:31
void TipChanged(SynchronizationState sync_state, interfaces::BlockTip tip, double verification_progress, SyncType synctype)
std::unique_ptr< interfaces::Handler > m_handler_notify_num_connections_changed
Definition: clientmodel.h:92
std::unique_ptr< interfaces::Handler > m_handler_notify_network_active_changed
Definition: clientmodel.h:94
OptionsModel * optionsModel
Definition: clientmodel.h:99
BanTableModel * banTableModel
Definition: clientmodel.h:101
QThread *const m_thread
A thread to interact with m_node asynchronously.
Definition: clientmodel.h:104
std::unique_ptr< interfaces::Handler > m_handler_notify_header_tip
Definition: clientmodel.h:98
BanTableModel * getBanTableModel()
void unsubscribeFromCoreSignals()
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, SyncType header, SynchronizationState sync_state)
void alertsChanged(const QString &warnings)
QString dataDir() const
std::atomic< int > m_cached_num_blocks
Definition: clientmodel.h:83
OptionsModel * getOptionsModel()
QString formatFullVersion() const
PeerTableModel * peerTableModel
Definition: clientmodel.h:100
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:48
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:58
SyncType
Definition: clientmodel.h:36
@ HEADER_PRESYNC
BlockSource
Definition: clientmodel.h:34
Definition: init.h:28
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:257
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
Block tip (could be a header or not, depends on the subscribed signal).
Definition: node.h:272
static int count
Definition: tests.c:31
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:117