@@ -53,8 +53,6 @@ public class ReactNativeLightningModule extends ReactContextBaseJavaModule {
53
53
54
54
private FileObserver logObserver ;
55
55
56
- private static LndState state = new LndState ();
57
-
58
56
public ReactNativeLightningModule (ReactApplicationContext reactContext ) {
59
57
super (reactContext );
60
58
}
@@ -173,142 +171,19 @@ public void onError(Exception e) {
173
171
public void onResponse (byte [] bytes ) {
174
172
Log .i (TAG , "Wallet ready to be unlocked" );
175
173
Log .d (TAG , "Wallet ready to be unlocked" );
176
- state .setLndRunning (true , getReactApplicationContext ());
177
174
promise .resolve ("LND started" );
178
175
}
179
176
}
180
- class RPCCallback implements Callback {
181
- @ Override
182
- public void onError (Exception e ) {
183
- Log .i (TAG , "RPC start err: " + e .getMessage ());
184
- Log .d (TAG , "RPC start err: " + e .getMessage ());
185
- }
186
- @ Override
187
- public void onResponse (byte [] bytes ) {
188
- Log .i (TAG , "RPC ready for requests" );
189
- Log .d (TAG , "RPC ready for requests" );
190
- state .setGrpcReady (true , getReactApplicationContext ());
191
- }
192
- }
193
177
194
178
Runnable startLnd = new Runnable () {
195
179
@ Override
196
180
public void run () {
197
- Lndmobile .start (args , new StartedCallback (), new RPCCallback () );
181
+ Lndmobile .start (args , new StartedCallback ());
198
182
}
199
183
};
200
184
new Thread (startLnd ).start ();
201
185
}
202
186
203
- @ ReactMethod
204
- public void genSeed (final Promise promise ) {
205
- Log .i ("LndNativeModule" , "Generating seed..." );
206
-
207
- class SeedCallback implements Callback {
208
- @ Override
209
- public void onError (Exception e ) {
210
- Log .i (TAG , "Seed err: " + e .getMessage ());
211
- Log .d (TAG , "Seed err: " + e .getMessage ());
212
- promise .reject (e );
213
- }
214
- @ Override
215
- public void onResponse (byte [] bytes ) {
216
- Log .i (TAG , "Seed generated successfully" );
217
- Log .d (TAG , "Seed generated successfully" );
218
-
219
- String b64 = "" ;
220
- if (bytes != null && bytes .length > 0 ) {
221
- b64 = Base64 .encodeToString (bytes , Base64 .NO_WRAP );
222
- }
223
-
224
- WritableMap params = Arguments .createMap ();
225
- params .putString (respB64DataKey , b64 );
226
-
227
- promise .resolve (params );
228
- }
229
- }
230
-
231
- class GenSeedTask implements Runnable {
232
- byte [] request ;
233
- GenSeedTask (byte [] r ) { request = r ;}
234
- public void run () {
235
- Lndmobile .genSeed (request , new SeedCallback ());
236
- }
237
- }
238
-
239
- Thread t = new Thread (new GenSeedTask (new byte [0 ]));
240
- t .start ();
241
- }
242
-
243
- @ ReactMethod
244
- public void createWallet (String msg , final Promise promise ) {
245
- Log .i ("LndNativeModule" , "Initializing wallet..." );
246
-
247
- class InitializeWalletCallback implements Callback {
248
- @ Override
249
- public void onError (Exception e ) {
250
- Log .i (TAG , "init err: " + e .getMessage ());
251
- Log .d (TAG , "init err: " + e .getMessage ());
252
- promise .reject (e );
253
- }
254
- @ Override
255
- public void onResponse (byte [] bytes ) {
256
- Log .i (TAG , "Wallet successfully initialized" );
257
- Log .d (TAG , "Wallet successfully initialized" );
258
- state .setWalletUnlocked (true , getReactApplicationContext ());
259
- promise .resolve ("initialized" );
260
- }
261
- }
262
-
263
- class InitWalletTask implements Runnable {
264
- byte [] request ;
265
- InitWalletTask (byte [] r ) { request = r ;}
266
- public void run () {
267
- Lndmobile .initWallet (request , new InitializeWalletCallback ());
268
- }
269
- }
270
- Thread t = new Thread (new InitWalletTask (Base64 .decode (msg , Base64 .NO_WRAP )));
271
- t .start ();
272
- }
273
-
274
- @ ReactMethod
275
- public void unlockWallet (String msg , final Promise promise ) {
276
- Log .i ("LndNativeModule" , "Unlocking wallet..." );
277
-
278
- class UnlockWalletCallback implements Callback {
279
- @ Override
280
- public void onError (Exception e ) {
281
- Log .i (TAG , "Unlock err: " + e .getMessage ());
282
- Log .d (TAG , "Unlock err: " + e .getMessage ());
283
- e .printStackTrace ();
284
-
285
- //TODO wallet still unlocked but sometimes returns an error. Error needs some investigation.
286
- if (e .getMessage ().contains ("transport is closing" )) {
287
- promise .resolve ("unlocked" );
288
- } else {
289
- promise .reject (e );
290
- }
291
- }
292
- @ Override
293
- public void onResponse (byte [] bytes ) {
294
- Log .i (TAG , "Wallet successfully unlocked" );
295
- Log .d (TAG , "Wallet successfully unlocked" );
296
- state .setWalletUnlocked (true , getReactApplicationContext ());
297
- promise .resolve ("unlocked" );
298
- }
299
- }
300
-
301
- class UnlockWalletTask implements Runnable {
302
- byte [] request ;
303
- UnlockWalletTask (byte [] r ) { request = r ;}
304
- public void run () {
305
- Lndmobile .unlockWallet (request , new UnlockWalletCallback ());
306
- }
307
- }
308
- Thread t = new Thread (new UnlockWalletTask (Base64 .decode (msg , Base64 .NO_WRAP )));
309
- t .start ();
310
- }
311
-
312
187
@ ReactMethod
313
188
public void walletExists (String network , final Promise promise ) {
314
189
File directory = new File (getReactApplicationContext ().getFilesDir ().toString () + "/lnd/data/chain/bitcoin/" + network + "/wallet.db" );
@@ -317,11 +192,6 @@ public void walletExists(String network, final Promise promise) {
317
192
promise .resolve (exists );
318
193
}
319
194
320
- @ ReactMethod
321
- public void currentState (final Promise promise ) {
322
- promise .resolve (state .formatted ());
323
- }
324
-
325
195
@ ReactMethod
326
196
public void logFileContent (String network , Integer limit , final Promise promise ) {
327
197
File appDir = getReactApplicationContext ().getFilesDir ();
@@ -433,13 +303,6 @@ public void onResponse(byte[] bytes) {
433
303
434
304
try {
435
305
m .invoke (null , Base64 .decode (msg , Base64 .NO_WRAP ), new NativeCallback (promise ));
436
-
437
- //If LND was stopped reset state
438
- if (method .equals ("StopDaemon" )) {
439
- state .setLndRunning (false , getReactApplicationContext ());
440
- state .setGrpcReady (false , getReactApplicationContext ());
441
- state .setWalletUnlocked (false , getReactApplicationContext ());
442
- }
443
306
} catch (IllegalAccessException | InvocationTargetException e ) {
444
307
e .printStackTrace ();
445
308
promise .reject ("LndNativeModule" , e );
@@ -519,36 +382,3 @@ public void sendStreamWrite(String streamId, String msg) {
519
382
}
520
383
}
521
384
}
522
-
523
- class LndState {
524
- private Boolean lndRunning = false ;
525
- private Boolean walletUnlocked = false ;
526
- private Boolean grpcReady = false ;
527
-
528
- public void setLndRunning (Boolean lndRunning , ReactApplicationContext context ) {
529
- this .lndRunning = lndRunning ;
530
- updateStateStream (context );
531
- }
532
-
533
- public void setWalletUnlocked (Boolean walletUnlocked , ReactApplicationContext context ) {
534
- this .walletUnlocked = walletUnlocked ;
535
- updateStateStream (context );
536
- }
537
-
538
- public void setGrpcReady (Boolean grpcReady , ReactApplicationContext context ) {
539
- this .grpcReady = grpcReady ;
540
- updateStateStream (context );
541
- }
542
-
543
- WritableMap formatted () {
544
- WritableMap params = Arguments .createMap ();
545
- params .putBoolean ("lndRunning" , lndRunning );
546
- params .putBoolean ("walletUnlocked" , walletUnlocked );
547
- params .putBoolean ("grpcReady" , grpcReady );
548
- return params ;
549
- }
550
-
551
- private void updateStateStream (ReactApplicationContext context ) {
552
- context .getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class ).emit ("lndStateUpdate" , formatted ());
553
- }
554
- }
0 commit comments