Bitcoin Core  0.20.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 #include <sync.h>
14 #include <uint256.h>
15 
16 class BanTableModel;
17 class CBlockIndex;
18 class OptionsModel;
19 class PeerTableModel;
20 enum class SynchronizationState;
21 
22 namespace interfaces {
23 class Handler;
24 class Node;
25 }
26 
27 QT_BEGIN_NAMESPACE
28 class QTimer;
29 QT_END_NAMESPACE
30 
31 enum class BlockSource {
32  NONE,
33  REINDEX,
34  DISK,
35  NETWORK
36 };
37 
40  CONNECTIONS_IN = (1U << 0),
41  CONNECTIONS_OUT = (1U << 1),
43 };
44 
46 class ClientModel : public QObject
47 {
48  Q_OBJECT
49 
50 public:
51  explicit ClientModel(interfaces::Node& node, OptionsModel *optionsModel, QObject *parent = nullptr);
52  ~ClientModel();
53 
54  interfaces::Node& node() const { return m_node; }
55  OptionsModel *getOptionsModel();
56  PeerTableModel *getPeerTableModel();
57  BanTableModel *getBanTableModel();
58 
60  int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
61  int getNumBlocks() const;
62  uint256 getBestBlockHash();
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  uint256 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> m_handler_notify_num_connections_changed;
92  std::unique_ptr<interfaces::Handler> m_handler_notify_network_active_changed;
93  std::unique_ptr<interfaces::Handler> m_handler_notify_alert_changed;
94  std::unique_ptr<interfaces::Handler> m_handler_banned_list_changed;
95  std::unique_ptr<interfaces::Handler> m_handler_notify_block_tip;
96  std::unique_ptr<interfaces::Handler> m_handler_notify_header_tip;
100 
102  QThread* const m_thread;
103 
104  void subscribeToCoreSignals();
105  void unsubscribeFromCoreSignals();
106 
107 Q_SIGNALS:
108  void numConnectionsChanged(int count);
109  void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress, bool header, SynchronizationState sync_state);
110  void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
111  void networkActiveChanged(bool networkActive);
112  void alertsChanged(const QString &warnings);
113  void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
114 
116  void message(const QString &title, const QString &message, unsigned int style);
117 
118  // Show progress dialog e.g. for verifychain
119  void showProgress(const QString &title, int nProgress);
120 
121 public Q_SLOTS:
122  void updateNumConnections(int numConnections);
123  void updateNetworkActive(bool networkActive);
124  void updateAlert();
125  void updateBanlist();
126 };
127 
128 #endif // BITCOIN_QT_CLIENTMODEL_H
PeerTableModel * peerTableModel
Definition: clientmodel.h:98
interfaces::Node & m_node
Definition: clientmodel.h:86
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:106
std::atomic< int64_t > cachedBestHeaderTime
Definition: clientmodel.h:82
QThread *const m_thread
A thread to interact with m_node asynchronously.
Definition: clientmodel.h:102
NodeContext & m_node
Definition: chain.cpp:411
BanTableModel * banTableModel
Definition: clientmodel.h:99
std::unique_ptr< interfaces::Handler > m_handler_show_progress
Definition: clientmodel.h:90
Mutex m_cached_tip_mutex
Definition: clientmodel.h:85
std::atomic< int > cachedBestHeaderHeight
Definition: clientmodel.h:81
std::unique_ptr< interfaces::Handler > m_handler_notify_block_tip
Definition: clientmodel.h:95
NumConnections
Definition: clientmodel.h:38
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:54
std::unique_ptr< interfaces::Handler > m_handler_banned_list_changed
Definition: clientmodel.h:94
Model for Bitcoin network client.
Definition: clientmodel.h:46
std::unique_ptr< interfaces::Handler > m_handler_notify_header_tip
Definition: clientmodel.h:96
int flags
Definition: bitcoin-tx.cpp:506
256-bit opaque blob.
Definition: uint256.h:124
std::unique_ptr< interfaces::Handler > m_handler_notify_num_connections_changed
Definition: clientmodel.h:91
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:39
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:35
OptionsModel * optionsModel
Definition: clientmodel.h:97
#define GUARDED_BY(x)
Definition: threadsafety.h:38
std::unique_ptr< interfaces::Handler > m_handler_notify_network_active_changed
Definition: clientmodel.h:92
std::unique_ptr< interfaces::Handler > m_handler_notify_alert_changed
Definition: clientmodel.h:93
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:52