Bitcoin Core  0.19.99
P2P Digital Currency
clientmodel.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2019 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; }
53  OptionsModel *getOptionsModel();
54  PeerTableModel *getPeerTableModel();
55  BanTableModel *getBanTableModel();
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 
94  QThread* const m_thread;
95 
96  void subscribeToCoreSignals();
97  void unsubscribeFromCoreSignals();
98 
99 Q_SIGNALS:
100  void numConnectionsChanged(int count);
101  void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header);
102  void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
103  void networkActiveChanged(bool networkActive);
104  void alertsChanged(const QString &warnings);
105  void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
106 
108  void message(const QString &title, const QString &message, unsigned int style);
109 
110  // Show progress dialog e.g. for verifychain
111  void showProgress(const QString &title, int nProgress);
112 
113 public Q_SLOTS:
114  void updateNumConnections(int numConnections);
115  void updateNetworkActive(bool networkActive);
116  void updateAlert();
117  void updateBanlist();
118 };
119 
120 #endif // BITCOIN_QT_CLIENTMODEL_H
PeerTableModel * peerTableModel
Definition: clientmodel.h:90
interfaces::Node & m_node
Definition: clientmodel.h:81
std::atomic< int64_t > cachedBestHeaderTime
Definition: clientmodel.h:78
QThread *const m_thread
A thread to interact with m_node asynchronously.
Definition: clientmodel.h:94
NodeContext & m_node
Definition: chain.cpp:374
BanTableModel * banTableModel
Definition: clientmodel.h:91
std::unique_ptr< interfaces::Handler > m_handler_show_progress
Definition: clientmodel.h:82
std::atomic< int > cachedBestHeaderHeight
Definition: clientmodel.h:77
std::unique_ptr< interfaces::Handler > m_handler_notify_block_tip
Definition: clientmodel.h:87
NumConnections
Definition: clientmodel.h:36
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call...
BlockSource
Definition: clientmodel.h:29
interfaces::Node & node() const
Definition: clientmodel.h:52
std::unique_ptr< interfaces::Handler > m_handler_banned_list_changed
Definition: clientmodel.h:86
Model for Bitcoin network client.
Definition: clientmodel.h:44
std::unique_ptr< interfaces::Handler > m_handler_notify_header_tip
Definition: clientmodel.h:88
int flags
Definition: bitcoin-tx.cpp:508
std::unique_ptr< interfaces::Handler > m_handler_notify_num_connections_changed
Definition: clientmodel.h:83
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:36
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:137
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call...
Definition: bantablemodel.h:42
static int count
Definition: tests.c:45
OptionsModel * optionsModel
Definition: clientmodel.h:89
std::unique_ptr< interfaces::Handler > m_handler_notify_network_active_changed
Definition: clientmodel.h:84
std::unique_ptr< interfaces::Handler > m_handler_notify_alert_changed
Definition: clientmodel.h:85
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:39