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