@@ -56,6 +56,7 @@ namespace {
5656class NodeImpl : public Node
5757{
5858public:
59+ NodeImpl (NodeContext* context) { setContext (context); }
5960 void initError (const bilingual_str& message) override { InitError (message); }
6061 bool parseParameters (int argc, const char * const argv[], std::string& error) override
6162 {
@@ -81,13 +82,13 @@ class NodeImpl : public Node
8182 }
8283 bool appInitMain () override
8384 {
84- m_context. chain = MakeChain (m_context);
85- return AppInitMain (m_context_ref, m_context);
85+ m_context-> chain = MakeChain (* m_context);
86+ return AppInitMain (m_context_ref, * m_context);
8687 }
8788 void appShutdown () override
8889 {
89- Interrupt (m_context);
90- Shutdown (m_context);
90+ Interrupt (* m_context);
91+ Shutdown (* m_context);
9192 }
9293 void startShutdown () override
9394 {
@@ -108,19 +109,19 @@ class NodeImpl : public Node
108109 StopMapPort ();
109110 }
110111 }
111- void setupServerArgs () override { return SetupServerArgs (m_context); }
112+ void setupServerArgs () override { return SetupServerArgs (* m_context); }
112113 bool getProxy (Network net, proxyType& proxy_info) override { return GetProxy (net, proxy_info); }
113114 size_t getNodeCount (CConnman::NumConnections flags) override
114115 {
115- return m_context. connman ? m_context. connman ->GetNodeCount (flags) : 0 ;
116+ return m_context-> connman ? m_context-> connman ->GetNodeCount (flags) : 0 ;
116117 }
117118 bool getNodesStats (NodesStats& stats) override
118119 {
119120 stats.clear ();
120121
121- if (m_context. connman ) {
122+ if (m_context-> connman ) {
122123 std::vector<CNodeStats> stats_temp;
123- m_context. connman ->GetNodeStats (stats_temp);
124+ m_context-> connman ->GetNodeStats (stats_temp);
124125
125126 stats.reserve (stats_temp.size ());
126127 for (auto & node_stats_temp : stats_temp) {
@@ -141,46 +142,46 @@ class NodeImpl : public Node
141142 }
142143 bool getBanned (banmap_t & banmap) override
143144 {
144- if (m_context. banman ) {
145- m_context. banman ->GetBanned (banmap);
145+ if (m_context-> banman ) {
146+ m_context-> banman ->GetBanned (banmap);
146147 return true ;
147148 }
148149 return false ;
149150 }
150151 bool ban (const CNetAddr& net_addr, int64_t ban_time_offset) override
151152 {
152- if (m_context. banman ) {
153- m_context. banman ->Ban (net_addr, ban_time_offset);
153+ if (m_context-> banman ) {
154+ m_context-> banman ->Ban (net_addr, ban_time_offset);
154155 return true ;
155156 }
156157 return false ;
157158 }
158159 bool unban (const CSubNet& ip) override
159160 {
160- if (m_context. banman ) {
161- m_context. banman ->Unban (ip);
161+ if (m_context-> banman ) {
162+ m_context-> banman ->Unban (ip);
162163 return true ;
163164 }
164165 return false ;
165166 }
166167 bool disconnectByAddress (const CNetAddr& net_addr) override
167168 {
168- if (m_context. connman ) {
169- return m_context. connman ->DisconnectNode (net_addr);
169+ if (m_context-> connman ) {
170+ return m_context-> connman ->DisconnectNode (net_addr);
170171 }
171172 return false ;
172173 }
173174 bool disconnectById (NodeId id) override
174175 {
175- if (m_context. connman ) {
176- return m_context. connman ->DisconnectNode (id);
176+ if (m_context-> connman ) {
177+ return m_context-> connman ->DisconnectNode (id);
177178 }
178179 return false ;
179180 }
180- int64_t getTotalBytesRecv () override { return m_context. connman ? m_context. connman ->GetTotalBytesRecv () : 0 ; }
181- int64_t getTotalBytesSent () override { return m_context. connman ? m_context. connman ->GetTotalBytesSent () : 0 ; }
182- size_t getMempoolSize () override { return m_context. mempool ? m_context. mempool ->size () : 0 ; }
183- size_t getMempoolDynamicUsage () override { return m_context. mempool ? m_context. mempool ->DynamicMemoryUsage () : 0 ; }
181+ int64_t getTotalBytesRecv () override { return m_context-> connman ? m_context-> connman ->GetTotalBytesRecv () : 0 ; }
182+ int64_t getTotalBytesSent () override { return m_context-> connman ? m_context-> connman ->GetTotalBytesSent () : 0 ; }
183+ size_t getMempoolSize () override { return m_context-> mempool ? m_context-> mempool ->size () : 0 ; }
184+ size_t getMempoolDynamicUsage () override { return m_context-> mempool ? m_context-> mempool ->DynamicMemoryUsage () : 0 ; }
184185 bool getHeaderTip (int & height, int64_t & block_time) override
185186 {
186187 LOCK (::cs_main);
@@ -223,11 +224,11 @@ class NodeImpl : public Node
223224 bool getImporting () override { return ::fImporting ; }
224225 void setNetworkActive (bool active) override
225226 {
226- if (m_context. connman ) {
227- m_context. connman ->SetNetworkActive (active);
227+ if (m_context-> connman ) {
228+ m_context-> connman ->SetNetworkActive (active);
228229 }
229230 }
230- bool getNetworkActive () override { return m_context. connman && m_context. connman ->GetNetworkActive (); }
231+ bool getNetworkActive () override { return m_context-> connman && m_context-> connman ->GetNetworkActive (); }
231232 CFeeRate estimateSmartFee (int num_blocks, bool conservative, int * returned_target = nullptr ) override
232233 {
233234 FeeCalculation fee_calc;
@@ -269,20 +270,20 @@ class NodeImpl : public Node
269270 std::vector<std::unique_ptr<Wallet>> getWallets () override
270271 {
271272 std::vector<std::unique_ptr<Wallet>> wallets;
272- for (auto & client : m_context. chain_clients ) {
273+ for (auto & client : m_context-> chain_clients ) {
273274 auto client_wallets = client->getWallets ();
274275 std::move (client_wallets.begin (), client_wallets.end (), std::back_inserter (wallets));
275276 }
276277 return wallets;
277278 }
278279 std::unique_ptr<Wallet> loadWallet (const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
279280 {
280- return MakeWallet (LoadWallet (*m_context. chain , name, error, warnings));
281+ return MakeWallet (LoadWallet (*m_context-> chain , name, error, warnings));
281282 }
282283 std::unique_ptr<Wallet> createWallet (const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, WalletCreationStatus& status) override
283284 {
284285 std::shared_ptr<CWallet> wallet;
285- status = CreateWallet (*m_context. chain , passphrase, wallet_creation_flags, name, error, warnings, wallet);
286+ status = CreateWallet (*m_context-> chain , passphrase, wallet_creation_flags, name, error, warnings, wallet);
286287 return MakeWallet (wallet);
287288 }
288289 std::unique_ptr<Handler> handleInitMessage (InitMessageFn fn) override
@@ -336,13 +337,22 @@ class NodeImpl : public Node
336337 /* verification progress is unused when a header was received */ 0 );
337338 }));
338339 }
339- NodeContext* context () override { return &m_context; }
340- NodeContext m_context;
341- util::Ref m_context_ref{m_context};
340+ NodeContext* context () override { return m_context; }
341+ void setContext (NodeContext* context) override
342+ {
343+ m_context = context;
344+ if (context) {
345+ m_context_ref.Set (*context);
346+ } else {
347+ m_context_ref.Clear ();
348+ }
349+ }
350+ NodeContext* m_context{nullptr };
351+ util::Ref m_context_ref;
342352};
343353
344354} // namespace
345355
346- std::unique_ptr<Node> MakeNode () { return MakeUnique<NodeImpl>(); }
356+ std::unique_ptr<Node> MakeNode (NodeContext* context ) { return MakeUnique<NodeImpl>(context ); }
347357
348358} // namespace interfaces
0 commit comments