@@ -56,6 +56,7 @@ namespace {
56
56
class NodeImpl : public Node
57
57
{
58
58
public:
59
+ NodeImpl (NodeContext* context) { setContext (context); }
59
60
void initError (const bilingual_str& message) override { InitError (message); }
60
61
bool parseParameters (int argc, const char * const argv[], std::string& error) override
61
62
{
@@ -80,13 +81,13 @@ class NodeImpl : public Node
80
81
}
81
82
bool appInitMain () override
82
83
{
83
- m_context. chain = MakeChain (m_context);
84
- return AppInitMain (m_context_ref, m_context);
84
+ m_context-> chain = MakeChain (* m_context);
85
+ return AppInitMain (m_context_ref, * m_context);
85
86
}
86
87
void appShutdown () override
87
88
{
88
- Interrupt (m_context);
89
- Shutdown (m_context);
89
+ Interrupt (* m_context);
90
+ Shutdown (* m_context);
90
91
}
91
92
void startShutdown () override
92
93
{
@@ -107,19 +108,19 @@ class NodeImpl : public Node
107
108
StopMapPort ();
108
109
}
109
110
}
110
- void setupServerArgs () override { return SetupServerArgs (m_context); }
111
+ void setupServerArgs () override { return SetupServerArgs (* m_context); }
111
112
bool getProxy (Network net, proxyType& proxy_info) override { return GetProxy (net, proxy_info); }
112
113
size_t getNodeCount (CConnman::NumConnections flags) override
113
114
{
114
- return m_context. connman ? m_context. connman ->GetNodeCount (flags) : 0 ;
115
+ return m_context-> connman ? m_context-> connman ->GetNodeCount (flags) : 0 ;
115
116
}
116
117
bool getNodesStats (NodesStats& stats) override
117
118
{
118
119
stats.clear ();
119
120
120
- if (m_context. connman ) {
121
+ if (m_context-> connman ) {
121
122
std::vector<CNodeStats> stats_temp;
122
- m_context. connman ->GetNodeStats (stats_temp);
123
+ m_context-> connman ->GetNodeStats (stats_temp);
123
124
124
125
stats.reserve (stats_temp.size ());
125
126
for (auto & node_stats_temp : stats_temp) {
@@ -140,46 +141,46 @@ class NodeImpl : public Node
140
141
}
141
142
bool getBanned (banmap_t & banmap) override
142
143
{
143
- if (m_context. banman ) {
144
- m_context. banman ->GetBanned (banmap);
144
+ if (m_context-> banman ) {
145
+ m_context-> banman ->GetBanned (banmap);
145
146
return true ;
146
147
}
147
148
return false ;
148
149
}
149
150
bool ban (const CNetAddr& net_addr, int64_t ban_time_offset) override
150
151
{
151
- if (m_context. banman ) {
152
- m_context. banman ->Ban (net_addr, ban_time_offset);
152
+ if (m_context-> banman ) {
153
+ m_context-> banman ->Ban (net_addr, ban_time_offset);
153
154
return true ;
154
155
}
155
156
return false ;
156
157
}
157
158
bool unban (const CSubNet& ip) override
158
159
{
159
- if (m_context. banman ) {
160
- m_context. banman ->Unban (ip);
160
+ if (m_context-> banman ) {
161
+ m_context-> banman ->Unban (ip);
161
162
return true ;
162
163
}
163
164
return false ;
164
165
}
165
166
bool disconnectByAddress (const CNetAddr& net_addr) override
166
167
{
167
- if (m_context. connman ) {
168
- return m_context. connman ->DisconnectNode (net_addr);
168
+ if (m_context-> connman ) {
169
+ return m_context-> connman ->DisconnectNode (net_addr);
169
170
}
170
171
return false ;
171
172
}
172
173
bool disconnectById (NodeId id) override
173
174
{
174
- if (m_context. connman ) {
175
- return m_context. connman ->DisconnectNode (id);
175
+ if (m_context-> connman ) {
176
+ return m_context-> connman ->DisconnectNode (id);
176
177
}
177
178
return false ;
178
179
}
179
- int64_t getTotalBytesRecv () override { return m_context. connman ? m_context. connman ->GetTotalBytesRecv () : 0 ; }
180
- int64_t getTotalBytesSent () override { return m_context. connman ? m_context. connman ->GetTotalBytesSent () : 0 ; }
181
- size_t getMempoolSize () override { return m_context. mempool ? m_context. mempool ->size () : 0 ; }
182
- size_t getMempoolDynamicUsage () override { return m_context. mempool ? m_context. mempool ->DynamicMemoryUsage () : 0 ; }
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 ; }
183
184
bool getHeaderTip (int & height, int64_t & block_time) override
184
185
{
185
186
LOCK (::cs_main);
@@ -222,11 +223,11 @@ class NodeImpl : public Node
222
223
bool getImporting () override { return ::fImporting ; }
223
224
void setNetworkActive (bool active) override
224
225
{
225
- if (m_context. connman ) {
226
- m_context. connman ->SetNetworkActive (active);
226
+ if (m_context-> connman ) {
227
+ m_context-> connman ->SetNetworkActive (active);
227
228
}
228
229
}
229
- bool getNetworkActive () override { return m_context. connman && m_context. connman ->GetNetworkActive (); }
230
+ bool getNetworkActive () override { return m_context-> connman && m_context-> connman ->GetNetworkActive (); }
230
231
CFeeRate estimateSmartFee (int num_blocks, bool conservative, int * returned_target = nullptr ) override
231
232
{
232
233
FeeCalculation fee_calc;
@@ -268,20 +269,20 @@ class NodeImpl : public Node
268
269
std::vector<std::unique_ptr<Wallet>> getWallets () override
269
270
{
270
271
std::vector<std::unique_ptr<Wallet>> wallets;
271
- for (auto & client : m_context. chain_clients ) {
272
+ for (auto & client : m_context-> chain_clients ) {
272
273
auto client_wallets = client->getWallets ();
273
274
std::move (client_wallets.begin (), client_wallets.end (), std::back_inserter (wallets));
274
275
}
275
276
return wallets;
276
277
}
277
278
std::unique_ptr<Wallet> loadWallet (const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
278
279
{
279
- return MakeWallet (LoadWallet (*m_context. chain , name, error, warnings));
280
+ return MakeWallet (LoadWallet (*m_context-> chain , name, error, warnings));
280
281
}
281
282
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
282
283
{
283
284
std::shared_ptr<CWallet> wallet;
284
- status = CreateWallet (*m_context. chain , passphrase, wallet_creation_flags, name, error, warnings, wallet);
285
+ status = CreateWallet (*m_context-> chain , passphrase, wallet_creation_flags, name, error, warnings, wallet);
285
286
return MakeWallet (wallet);
286
287
}
287
288
std::unique_ptr<Handler> handleInitMessage (InitMessageFn fn) override
@@ -335,13 +336,22 @@ class NodeImpl : public Node
335
336
/* verification progress is unused when a header was received */ 0 );
336
337
}));
337
338
}
338
- NodeContext* context () override { return &m_context; }
339
- NodeContext m_context;
340
- util::Ref m_context_ref{m_context};
339
+ NodeContext* context () override { return m_context; }
340
+ void setContext (NodeContext* context) override
341
+ {
342
+ m_context = context;
343
+ if (context) {
344
+ m_context_ref.Set (*context);
345
+ } else {
346
+ m_context_ref.Clear ();
347
+ }
348
+ }
349
+ NodeContext* m_context{nullptr };
350
+ util::Ref m_context_ref;
341
351
};
342
352
343
353
} // namespace
344
354
345
- std::unique_ptr<Node> MakeNode () { return MakeUnique<NodeImpl>(); }
355
+ std::unique_ptr<Node> MakeNode (NodeContext* context ) { return MakeUnique<NodeImpl>(context ); }
346
356
347
357
} // namespace interfaces
0 commit comments