11
11
#include " CryptoNoteCore/CryptoNoteBasicImpl.h"
12
12
#include " CryptoNoteCore/CryptoNoteFormatUtils.h"
13
13
#include " CryptoNoteCore/Currency.h"
14
+ #include " CryptoNoteCore/TransactionExtra.h"
14
15
#include " NodeRpcProxy/NodeRpcProxy.h"
15
16
#include " CryptoNoteCore/CoreConfig.h"
16
17
#include " P2p/NetNodeConfig.h"
17
18
#include " CryptoNoteCore/Core.h"
18
19
#include " CryptoNoteProtocol/CryptoNoteProtocolHandler.h"
19
20
#include " InProcessNode/InProcessNode.h"
21
+ #include " InProcessNode/InProcessNodeErrors.h"
20
22
#include " P2p/NetNode.h"
21
- #include " WalletLegacy/WalletLegacy .h"
23
+ #include " Wallet/WalletGreen .h"
22
24
#include " Logging/LoggerManager.h"
23
25
#include " System/Dispatcher.h"
24
26
#include " Settings.h"
25
27
28
+ #include < QTimer>
29
+ #include < QThread>
30
+
26
31
namespace WalletGui {
27
32
28
33
namespace {
@@ -88,28 +93,30 @@ std::string extractPaymentId(const std::string& extra) {
88
93
89
94
}
90
95
91
- Node::~Node () {
92
- }
93
96
94
- class RpcNode : cn::INodeObserver, public Node {
97
+ class RpcNode : public cn ::INodeObserver, public Node {
95
98
public:
96
- RpcNode (const cn::Currency& currency, logging::LoggerManager& logManager, INodeCallback& callback, const std::string& nodeHost, unsigned short nodePort) :
97
- m_callback (callback),
98
- m_currency (currency),
99
- m_logger (logManager),
100
- m_node (nodeHost, nodePort) {
99
+ RpcNode (const cn::Currency& currency, logging::LoggerManager& logManager, INodeCallback& callback,
100
+ const std::string& nodeHost, unsigned short nodePort)
101
+ : m_callback(callback),
102
+ m_currency (currency),
103
+ m_stopEvent(m_dispatcher),
104
+ m_node(nodeHost, nodePort),
105
+ m_logger(logManager) {
101
106
m_node.addObserver (this );
102
107
}
103
108
104
- ~RpcNode () override {
105
- }
109
+ ~RpcNode () override = default ;
106
110
107
111
void init (const std::function<void (std::error_code)>& callback) override {
108
112
m_node.init (callback);
113
+ m_stopEvent.wait ();
109
114
}
110
115
111
116
void deinit () override {
112
- /* nothing to be done here */
117
+ m_dispatcher.remoteSpawn ([this ] {
118
+ m_stopEvent.set ();
119
+ });
113
120
}
114
121
115
122
std::string convertPaymentId (const std::string& paymentIdString) override {
@@ -136,37 +143,40 @@ class RpcNode : cn::INodeObserver, public Node {
136
143
return m_node.getPeerCount ();
137
144
}
138
145
139
- cn::IWalletLegacy* createWallet () override {
140
- return new cn::WalletLegacy (m_currency, m_node, m_logger, Settings::instance ().isTestnet ());
146
+ std::unique_ptr<cn::IWallet> createWallet () override {
147
+ return std::unique_ptr<cn::IWallet>(
148
+ new cn::WalletGreen (m_dispatcher, m_currency, m_node, m_logger));
141
149
}
142
150
143
151
private:
144
152
INodeCallback& m_callback;
145
153
const cn::Currency& m_currency;
154
+ platform_system::Dispatcher m_dispatcher;
155
+ platform_system::Event m_stopEvent;
146
156
cn::NodeRpcProxy m_node;
147
157
logging::LoggerManager& m_logger;
148
158
149
- void peerCountUpdated (size_t count) {
159
+ void peerCountUpdated (size_t count) override {
150
160
m_callback.peerCountUpdated (*this , count);
151
161
}
152
162
153
- void localBlockchainUpdated (uint64_t height) {
163
+ void localBlockchainUpdated (uint32_t height) override {
154
164
m_callback.localBlockchainUpdated (*this , height);
155
165
}
156
166
157
- void lastKnownBlockHeightUpdated (uint64_t height) {
167
+ void lastKnownBlockHeightUpdated (uint32_t height) override {
158
168
m_callback.lastKnownBlockHeightUpdated (*this , height);
159
169
}
160
170
};
161
171
162
- class InprocessNode : cn::INodeObserver, public Node {
172
+ class InprocessNode : public cn ::INodeObserver, public Node {
163
173
public:
164
174
InprocessNode (const cn::Currency& currency, logging::LoggerManager& logManager, const cn::CoreConfig& coreConfig,
165
175
const cn::NetNodeConfig& netNodeConfig, INodeCallback& callback) :
166
- m_currency (currency),
167
- m_dispatcher (),
168
- m_loggerManager (logManager),
169
176
m_callback (callback),
177
+ m_currency (currency),
178
+ m_stopEvent (m_dispatcher),
179
+ m_loggerManager (logManager),
170
180
m_coreConfig (coreConfig),
171
181
m_netNodeConfig (netNodeConfig),
172
182
m_protocolHandler (currency, m_dispatcher, m_core, nullptr , logManager),
@@ -183,9 +193,7 @@ class InprocessNode : cn::INodeObserver, public Node {
183
193
m_protocolHandler.set_p2p_endpoint (&m_nodeServer);
184
194
}
185
195
186
- ~InprocessNode () override {
187
-
188
- }
196
+ ~InprocessNode () override = default ;
189
197
190
198
void init (const std::function<void (std::error_code)>& callback) override {
191
199
try {
@@ -242,33 +250,34 @@ class InprocessNode : cn::INodeObserver, public Node {
242
250
return m_node.getPeerCount ();
243
251
}
244
252
245
- cn::IWalletLegacy* createWallet () override {
246
- return new cn::WalletLegacy (m_currency, m_node, m_loggerManager, Settings::instance ().isTestnet ());
253
+ std::unique_ptr<cn::IWallet> createWallet () override {
254
+ return std::unique_ptr<cn::IWallet>(
255
+ new cn::WalletGreen (m_dispatcher, m_currency, m_node, m_loggerManager));
247
256
}
248
257
249
258
private:
250
259
INodeCallback& m_callback;
251
260
const cn::Currency& m_currency;
252
261
platform_system::Dispatcher m_dispatcher;
262
+ platform_system::Event m_stopEvent;
253
263
logging::LoggerManager& m_loggerManager;
254
264
cn::CoreConfig m_coreConfig;
255
265
cn::NetNodeConfig m_netNodeConfig;
256
- cn::core m_core;
257
266
cn::CryptoNoteProtocolHandler m_protocolHandler;
267
+ cn::core m_core;
258
268
cn::NodeServer m_nodeServer;
259
269
cn::InProcessNode m_node;
260
270
std::future<bool > m_nodeServerFuture;
261
271
262
-
263
- void peerCountUpdated (size_t count) {
272
+ void peerCountUpdated (size_t count) override {
264
273
m_callback.peerCountUpdated (*this , count);
265
274
}
266
275
267
- void localBlockchainUpdated (uint64_t height) {
276
+ void localBlockchainUpdated (uint32_t height) override {
268
277
m_callback.localBlockchainUpdated (*this , height);
269
278
}
270
279
271
- void lastKnownBlockHeightUpdated (uint64_t height) {
280
+ void lastKnownBlockHeightUpdated (uint32_t height) override {
272
281
m_callback.lastKnownBlockHeightUpdated (*this , height);
273
282
}
274
283
};
0 commit comments