4
4
5
5
#include < interface/node.h>
6
6
7
+ #include < chain.h>
7
8
#include < chainparams.h>
8
9
#include < init.h>
9
10
#include < interface/handler.h>
10
11
#include < interface/wallet.h>
11
12
#include < net.h>
12
13
#include < netaddress.h>
13
14
#include < netbase.h>
15
+ #include < primitives/block.h>
14
16
#include < scheduler.h>
17
+ #include < sync.h>
18
+ #include < txmempool.h>
15
19
#include < ui_interface.h>
16
20
#include < util.h>
21
+ #include < validation.h>
17
22
#include < warnings.h>
18
23
19
24
#if defined(HAVE_CONFIG_H)
25
30
#define CHECK_WALLET (x ) throw std::logic_error (" Wallet function called in non-wallet build." )
26
31
#endif
27
32
33
+ #include < atomic>
28
34
#include < boost/thread/thread.hpp>
29
35
30
36
class CWallet ;
@@ -69,6 +75,56 @@ class NodeImpl : public Node
69
75
}
70
76
std::string helpMessage (HelpMessageMode mode) override { return HelpMessage (mode); }
71
77
bool getProxy (Network net, proxyType& proxy_info) override { return GetProxy (net, proxy_info); }
78
+ size_t getNodeCount (CConnman::NumConnections flags) override
79
+ {
80
+ return g_connman ? g_connman->GetNodeCount (flags) : 0 ;
81
+ }
82
+ int64_t getTotalBytesRecv () override { return g_connman ? g_connman->GetTotalBytesRecv () : 0 ; }
83
+ int64_t getTotalBytesSent () override { return g_connman ? g_connman->GetTotalBytesSent () : 0 ; }
84
+ size_t getMempoolSize () override { return ::mempool.size (); }
85
+ size_t getMempoolDynamicUsage () override { return ::mempool.DynamicMemoryUsage (); }
86
+ bool getHeaderTip (int & height, int64_t & block_time) override
87
+ {
88
+ LOCK (::cs_main);
89
+ if (::pindexBestHeader) {
90
+ height = ::pindexBestHeader->nHeight ;
91
+ block_time = ::pindexBestHeader->GetBlockTime ();
92
+ return true ;
93
+ }
94
+ return false ;
95
+ }
96
+ int getNumBlocks () override
97
+ {
98
+ LOCK (::cs_main);
99
+ return ::chainActive.Height ();
100
+ }
101
+ int64_t getLastBlockTime () override
102
+ {
103
+ LOCK (::cs_main);
104
+ if (::chainActive.Tip ()) {
105
+ return ::chainActive.Tip ()->GetBlockTime ();
106
+ }
107
+ return Params ().GenesisBlock ().GetBlockTime (); // Genesis block's time of current network
108
+ }
109
+ double getVerificationProgress () override
110
+ {
111
+ const CBlockIndex* tip;
112
+ {
113
+ LOCK (::cs_main);
114
+ tip = ::chainActive.Tip ();
115
+ }
116
+ return GuessVerificationProgress (::Params ().TxData (), tip);
117
+ }
118
+ bool isInitialBlockDownload () override { return IsInitialBlockDownload (); }
119
+ bool getReindex () override { return ::fReindex ; }
120
+ bool getImporting () override { return ::fImporting ; }
121
+ void setNetworkActive (bool active) override
122
+ {
123
+ if (g_connman) {
124
+ g_connman->SetNetworkActive (active);
125
+ }
126
+ }
127
+ bool getNetworkActive () override { return g_connman && g_connman->GetNetworkActive (); }
72
128
std::unique_ptr<Handler> handleInitMessage (InitMessageFn fn) override
73
129
{
74
130
return MakeHandler (::uiInterface.InitMessage .connect (fn));
@@ -90,6 +146,37 @@ class NodeImpl : public Node
90
146
CHECK_WALLET (
91
147
return MakeHandler (::uiInterface.LoadWallet .connect ([fn](CWallet* wallet) { fn (MakeWallet (*wallet)); })));
92
148
}
149
+ std::unique_ptr<Handler> handleNotifyNumConnectionsChanged (NotifyNumConnectionsChangedFn fn) override
150
+ {
151
+ return MakeHandler (::uiInterface.NotifyNumConnectionsChanged .connect (fn));
152
+ }
153
+ std::unique_ptr<Handler> handleNotifyNetworkActiveChanged (NotifyNetworkActiveChangedFn fn) override
154
+ {
155
+ return MakeHandler (::uiInterface.NotifyNetworkActiveChanged .connect (fn));
156
+ }
157
+ std::unique_ptr<Handler> handleNotifyAlertChanged (NotifyAlertChangedFn fn) override
158
+ {
159
+ return MakeHandler (::uiInterface.NotifyAlertChanged .connect (fn));
160
+ }
161
+ std::unique_ptr<Handler> handleBannedListChanged (BannedListChangedFn fn) override
162
+ {
163
+ return MakeHandler (::uiInterface.BannedListChanged .connect (fn));
164
+ }
165
+ std::unique_ptr<Handler> handleNotifyBlockTip (NotifyBlockTipFn fn) override
166
+ {
167
+ return MakeHandler (::uiInterface.NotifyBlockTip .connect ([fn](bool initial_download, const CBlockIndex* block) {
168
+ fn (initial_download, block->nHeight , block->GetBlockTime (),
169
+ GuessVerificationProgress (::Params ().TxData (), block));
170
+ }));
171
+ }
172
+ std::unique_ptr<Handler> handleNotifyHeaderTip (NotifyHeaderTipFn fn) override
173
+ {
174
+ return MakeHandler (
175
+ ::uiInterface.NotifyHeaderTip .connect ([fn](bool initial_download, const CBlockIndex* block) {
176
+ fn (initial_download, block->nHeight , block->GetBlockTime (),
177
+ GuessVerificationProgress (::Params ().TxData (), block));
178
+ }));
179
+ }
93
180
};
94
181
95
182
} // namespace
0 commit comments