Bitcoin
clientmodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2018 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 
14 class BanTableModel;
15 class OptionsModel;
16 class PeerTableModel;
17 
18 class CBlockIndex;
19 
20 namespace interfaces {
21 class Handler;
22 class Node;
23 }
24 
25 QT_BEGIN_NAMESPACE
26 class QTimer;
27 QT_END_NAMESPACE
28 
29 enum class BlockSource {
30  NONE,
31  REINDEX,
32  DISK,
33  NETWORK
34 };
35 
38  CONNECTIONS_IN = (1U << 0),
39  CONNECTIONS_OUT = (1U << 1),
41 };
42 
44 class ClientModel : public QObject
45 {
46  Q_OBJECT
47 
48 public:
49  explicit ClientModel(interfaces::Node& node, OptionsModel *optionsModel, QObject *parent = nullptr);
50  ~ClientModel();
51 
52  interfaces::Node& node() const { return m_node; }
56 
58  int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
59  int getHeaderTipHeight() const;
60  int64_t getHeaderTipTime() const;
61 
63  enum BlockSource getBlockSource() const;
65  QString getStatusBarWarnings() const;
66 
67  QString formatFullVersion() const;
68  QString formatSubVersion() const;
69  bool isReleaseVersion() const;
70  QString formatClientStartupTime() const;
71  QString dataDir() const;
72  QString blocksDir() const;
73 
74  bool getProxyInfo(std::string& ip_port) const;
75 
76  // caches for the best header
77  mutable std::atomic<int> cachedBestHeaderHeight;
78  mutable std::atomic<int64_t> cachedBestHeaderTime;
79 
80 private:
82  std::unique_ptr<interfaces::Handler> m_handler_show_progress;
83  std::unique_ptr<interfaces::Handler> m_handler_notify_num_connections_changed;
84  std::unique_ptr<interfaces::Handler> m_handler_notify_network_active_changed;
85  std::unique_ptr<interfaces::Handler> m_handler_notify_alert_changed;
86  std::unique_ptr<interfaces::Handler> m_handler_banned_list_changed;
87  std::unique_ptr<interfaces::Handler> m_handler_notify_block_tip;
88  std::unique_ptr<interfaces::Handler> m_handler_notify_header_tip;
92 
93  QTimer *pollTimer;
94 
97 
98 Q_SIGNALS:
99  void numConnectionsChanged(int count);
100  void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header);
101  void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
102  void networkActiveChanged(bool networkActive);
103  void alertsChanged(const QString &warnings);
104  void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
105 
107  void message(const QString &title, const QString &message, unsigned int style);
108 
109  // Show progress dialog e.g. for verifychain
110  void showProgress(const QString &title, int nProgress);
111 
112 public Q_SLOTS:
113  void updateTimer();
114  void updateNumConnections(int numConnections);
115  void updateNetworkActive(bool networkActive);
116  void updateAlert();
117  void updateBanlist();
118 };
119 
120 #endif // BITCOIN_QT_CLIENTMODEL_H
void subscribeToCoreSignals()
Definition: clientmodel.cpp:251
std::unique_ptr< interfaces::Handler > m_handler_notify_block_tip
Definition: clientmodel.h:87
QString getStatusBarWarnings() const
Return warnings to be displayed in status bar.
Definition: clientmodel.cpp:128
Definition: optionsmodel.h:29
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes)
Definition: moc_clientmodel.cpp:266
enum BlockSource getBlockSource() const
Returns enum BlockSource of the current importing/syncing state.
Definition: clientmodel.cpp:116
void message(const QString &title, const QString &message, unsigned int style)
Fired when a message should be reported to the user.
Definition: moc_clientmodel.cpp:294
int64_t getHeaderTipTime() const
Definition: clientmodel.cpp:80
std::unique_ptr< interfaces::Handler > m_handler_banned_list_changed
Definition: clientmodel.h:86
std::unique_ptr< interfaces::Handler > m_handler_notify_num_connections_changed
Definition: clientmodel.h:83
bool getProxyInfo(std::string &ip_port) const
Definition: clientmodel.cpp:275
void updateNumConnections(int numConnections)
Definition: clientmodel.cpp:101
void updateAlert()
Definition: clientmodel.cpp:111
Definition: clientmodel.h:37
std::atomic< int64_t > cachedBestHeaderTime
Definition: clientmodel.h:78
bool isReleaseVersion() const
Definition: clientmodel.cpp:158
Definition: clientmodel.h:39
Definition: peertablemodel.h:49
Definition: clientmodel.h:38
std::unique_ptr< interfaces::Handler > m_handler_notify_header_tip
Definition: clientmodel.h:88
void showProgress(const QString &title, int nProgress)
Definition: moc_clientmodel.cpp:301
BanTableModel * banTableModel
Definition: clientmodel.h:91
std::unique_ptr< interfaces::Handler > m_handler_notify_alert_changed
Definition: clientmodel.h:85
NumConnections
Definition: clientmodel.h:36
Definition: dummywallet.cpp:11
std::unique_ptr< interfaces::Handler > m_handler_notify_network_active_changed
Definition: clientmodel.h:84
void updateNetworkActive(bool networkActive)
Definition: clientmodel.cpp:106
BlockSource
Definition: clientmodel.h:29
PeerTableModel * peerTableModel
Definition: clientmodel.h:90
QString formatSubVersion() const
Definition: clientmodel.cpp:153
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:36
QString dataDir() const
Definition: clientmodel.cpp:168
OptionsModel * optionsModel
Definition: clientmodel.h:89
int getHeaderTipHeight() const
Definition: clientmodel.cpp:65
Definition: clientmodel.h:40
QString formatFullVersion() const
Definition: clientmodel.cpp:148
int flags
Definition: bitcoin-tx.cpp:507
interfaces::Node & m_node
Definition: clientmodel.h:81
QString blocksDir() const
Definition: clientmodel.cpp:173
ClientModel(interfaces::Node &node, OptionsModel *optionsModel, QObject *parent=nullptr)
Definition: clientmodel.cpp:27
QString formatClientStartupTime() const
Definition: clientmodel.cpp:163
Definition: clientmodel.h:44
not actually invalid
std::unique_ptr< interfaces::Handler > m_handler_show_progress
Definition: clientmodel.h:82
interfaces::Node & node() const
Definition: clientmodel.h:52
void updateBanlist()
Definition: clientmodel.cpp:178
static int count
Definition: tests.c:45
Definition: chain.h:139
signed long long int64_t
Definition: stdint.h:18
void alertsChanged(const QString &warnings)
Definition: moc_clientmodel.cpp:280
std::atomic< int > cachedBestHeaderHeight
Definition: clientmodel.h:77
void unsubscribeFromCoreSignals()
Definition: clientmodel.cpp:263
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut)
Definition: moc_clientmodel.cpp:287
QTimer * pollTimer
Definition: clientmodel.h:93
void numConnectionsChanged(int count)
Definition: moc_clientmodel.cpp:252
~ClientModel()
Definition: clientmodel.cpp:46
OptionsModel * getOptionsModel()
Definition: clientmodel.cpp:133
void updateTimer()
Definition: clientmodel.cpp:93
Definition: bantablemodel.h:43
void numBlocksChanged(int count, const QDateTime &blockDate, double nVerificationProgress, bool header)
Definition: moc_clientmodel.cpp:259
BanTableModel * getBanTableModel()
Definition: clientmodel.cpp:143
int getNumConnections(unsigned int flags=CONNECTIONS_ALL) const
Return number of connections, default is in- and outbound (total)
Definition: clientmodel.cpp:51
void networkActiveChanged(bool networkActive)
Definition: moc_clientmodel.cpp:273
PeerTableModel * getPeerTableModel()
Definition: clientmodel.cpp:138