44
55#include < interface/node.h>
66
7+ #include < chain.h>
78#include < chainparams.h>
89#include < init.h>
910#include < interface/handler.h>
1011#include < interface/wallet.h>
1112#include < net.h>
1213#include < netaddress.h>
1314#include < netbase.h>
15+ #include < primitives/block.h>
1416#include < scheduler.h>
17+ #include < sync.h>
18+ #include < txmempool.h>
1519#include < ui_interface.h>
1620#include < util.h>
21+ #include < validation.h>
1722#include < warnings.h>
1823
1924#if defined(HAVE_CONFIG_H)
2530#define CHECK_WALLET (x ) throw std::logic_error (" Wallet function called in non-wallet build." )
2631#endif
2732
33+ #include < atomic>
2834#include < boost/thread/thread.hpp>
2935
3036class CWallet ;
@@ -69,6 +75,56 @@ class NodeImpl : public Node
6975 }
7076 std::string helpMessage (HelpMessageMode mode) override { return HelpMessage (mode); }
7177 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 (); }
72128 std::unique_ptr<Handler> handleInitMessage (InitMessageFn fn) override
73129 {
74130 return MakeHandler (::uiInterface.InitMessage .connect (fn));
@@ -90,6 +146,37 @@ class NodeImpl : public Node
90146 CHECK_WALLET (
91147 return MakeHandler (::uiInterface.LoadWallet .connect ([fn](CWallet* wallet) { fn (MakeWallet (*wallet)); })));
92148 }
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+ }
93180};
94181
95182} // namespace
0 commit comments