Bitcoin ABC  0.22.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 
14 class BanTableModel;
15 class CBlockIndex;
16 class OptionsModel;
17 class PeerTableModel;
18 
19 class CBlockIndex;
20 enum class SynchronizationState;
21 
22 namespace interfaces {
23 class Handler;
24 class Node;
25 } // namespace interfaces
26 
27 QT_BEGIN_NAMESPACE
28 class QTimer;
29 QT_END_NAMESPACE
30 
31 enum class BlockSource { NONE, REINDEX, DISK, NETWORK };
32 
34 class ClientModel : public QObject {
35  Q_OBJECT
36 
37 public:
39  CONNECTIONS_NONE = 0,
40  CONNECTIONS_IN = (1U << 0),
41  CONNECTIONS_OUT = (1U << 1),
42  CONNECTIONS_ALL = (CONNECTIONS_IN | CONNECTIONS_OUT),
43  };
44 
45  explicit ClientModel(interfaces::Node &node, OptionsModel *optionsModel,
46  QObject *parent = nullptr);
47  ~ClientModel();
48 
49  interfaces::Node &node() const { return m_node; }
50  OptionsModel *getOptionsModel();
51  PeerTableModel *getPeerTableModel();
52  BanTableModel *getBanTableModel();
53 
55  int getNumConnections(NumConnections flags = CONNECTIONS_ALL) const;
56  int getNumBlocks() const;
57  int getHeaderTipHeight() const;
58  int64_t getHeaderTipTime() const;
59 
61  enum BlockSource getBlockSource() const;
63  QString getStatusBarWarnings() const;
64 
65  QString formatFullVersion() const;
66  QString formatSubVersion() const;
67  bool isReleaseVersion() const;
68  QString formatClientStartupTime() const;
69  QString dataDir() const;
70  QString blocksDir() const;
71 
72  bool getProxyInfo(std::string &ip_port) const;
73 
74  // caches for the best header, number of blocks
75  mutable std::atomic<int> cachedBestHeaderHeight;
76  mutable std::atomic<int64_t> cachedBestHeaderTime;
77  mutable std::atomic<int> m_cached_num_blocks{-1};
78 
79 private:
81  std::unique_ptr<interfaces::Handler> m_handler_show_progress;
82  std::unique_ptr<interfaces::Handler>
84  std::unique_ptr<interfaces::Handler>
86  std::unique_ptr<interfaces::Handler> m_handler_notify_alert_changed;
87  std::unique_ptr<interfaces::Handler> m_handler_banned_list_changed;
88  std::unique_ptr<interfaces::Handler> m_handler_notify_block_tip;
89  std::unique_ptr<interfaces::Handler> m_handler_notify_header_tip;
93 
95  QThread *const m_thread;
96 
97  void subscribeToCoreSignals();
98  void unsubscribeFromCoreSignals();
99 
100 Q_SIGNALS:
101  void numConnectionsChanged(int count);
102  void numBlocksChanged(int count, const QDateTime &blockDate,
103  double nVerificationProgress, bool header,
104  SynchronizationState sync_state);
105  void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
106  void networkActiveChanged(bool networkActive);
107  void alertsChanged(const QString &warnings);
108  void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
109 
111  void message(const QString &title, const QString &message,
112  unsigned int style);
113 
114  // Show progress dialog e.g. for verifychain
115  void showProgress(const QString &title, int nProgress);
116 
117 public Q_SLOTS:
118  void updateNumConnections(int numConnections);
119  void updateNetworkActive(bool networkActive);
120  void updateAlert();
121  void updateBanlist();
122 };
123 
124 #endif // BITCOIN_QT_CLIENTMODEL_H
PeerTableModel * peerTableModel
Definition: clientmodel.h:91
interfaces::Node & m_node
Definition: clientmodel.h:80
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:167
std::atomic< int64_t > cachedBestHeaderTime
Definition: clientmodel.h:76
QThread *const m_thread
A thread to interact with m_node asynchronously.
Definition: clientmodel.h:95
NodeContext & m_node
Definition: chain.cpp:442
BanTableModel * banTableModel
Definition: clientmodel.h:92
std::unique_ptr< interfaces::Handler > m_handler_show_progress
Definition: clientmodel.h:81
std::atomic< int > cachedBestHeaderHeight
Definition: clientmodel.h:75
std::unique_ptr< interfaces::Handler > m_handler_notify_block_tip
Definition: clientmodel.h:88
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call...
BlockSource
Definition: clientmodel.h:31
interfaces::Node & node() const
Definition: clientmodel.h:49
std::unique_ptr< interfaces::Handler > m_handler_banned_list_changed
Definition: clientmodel.h:87
Model for Bitcoin network client.
Definition: clientmodel.h:34
std::unique_ptr< interfaces::Handler > m_handler_notify_header_tip
Definition: clientmodel.h:89
int flags
Definition: bitcoin-tx.cpp:529
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:48
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: blockindex.h:23
Qt model providing information about connected peers, similar to the "getpeerinfo" RPC call...
Definition: bantablemodel.h:41
static int count
Definition: tests.c:35
OptionsModel * optionsModel
Definition: clientmodel.h:90
std::unique_ptr< interfaces::Handler > m_handler_notify_network_active_changed
Definition: clientmodel.h:85
std::unique_ptr< interfaces::Handler > m_handler_notify_alert_changed
Definition: clientmodel.h:86
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:45