26
26
import java .lang .reflect .InvocationTargetException ;
27
27
import java .lang .reflect .Method ;
28
28
import java .util .ArrayList ;
29
- import java .util .Arrays ;
30
29
import java .util .HashMap ;
31
30
import java .util .List ;
32
31
import java .util .Map ;
35
34
import lndmobile .Lndmobile ;
36
35
import lndmobile .RecvStream ;
37
36
import lndmobile .SendStream ;
38
- import lnrpc .Walletunlocker ;
39
-
40
- import com .google .protobuf .ByteString ;
41
- import com .google .protobuf .InvalidProtocolBufferException ;
42
- import com .google .protobuf .ProtocolStringList ;
43
37
44
38
public class ReactNativeLightningModule extends ReactContextBaseJavaModule {
45
39
@@ -222,21 +216,15 @@ public void onResponse(byte[] bytes) {
222
216
Log .i (TAG , "Seed generated successfully" );
223
217
Log .d (TAG , "Seed generated successfully" );
224
218
225
- try {
226
- ProtocolStringList seed = Walletunlocker .GenSeedResponse .parseFrom (bytes ).getCipherSeedMnemonicList ();
227
-
228
- //Map seed list into a react native string array
229
- WritableArray promiseSeed = Arguments .createArray ();
230
- for (int i = 0 ; i < seed .size (); i ++){
231
- promiseSeed .pushString (seed .get (i ));
232
- }
233
-
234
- promise .resolve (promiseSeed );
235
- } catch (InvalidProtocolBufferException e ) {
236
- Log .i (TAG , "Failed to pass genSeed response: " + e .getMessage ());
237
- Log .d (TAG , "Failed to pass genSeed response: " + e .getMessage ());
238
- promise .reject (e );
219
+ String b64 = "" ;
220
+ if (bytes != null && bytes .length > 0 ) {
221
+ b64 = Base64 .encodeToString (bytes , Base64 .NO_WRAP );
239
222
}
223
+
224
+ WritableMap params = Arguments .createMap ();
225
+ params .putString (respB64DataKey , b64 );
226
+
227
+ promise .resolve (params );
240
228
}
241
229
}
242
230
@@ -247,12 +235,13 @@ public void run() {
247
235
Lndmobile .genSeed (request , new SeedCallback ());
248
236
}
249
237
}
250
- Thread t = new Thread (new GenSeedTask (Walletunlocker .GenSeedRequest .newBuilder ().build ().toByteArray ()));
238
+
239
+ Thread t = new Thread (new GenSeedTask (new byte [0 ]));
251
240
t .start ();
252
241
}
253
242
254
243
@ ReactMethod
255
- public void createWallet (String password , ReadableArray seed , final Promise promise ) {
244
+ public void createWallet (String msg , final Promise promise ) {
256
245
Log .i ("LndNativeModule" , "Initializing wallet..." );
257
246
258
247
class InitializeWalletCallback implements Callback {
@@ -271,30 +260,19 @@ public void onResponse(byte[] bytes) {
271
260
}
272
261
}
273
262
274
- //Map a react native ReadableArray to java string array
275
- String [] seedArray = new String [seed .size ()];
276
- for (int i = 0 ; i < seed .size (); i ++) {
277
- seedArray [i ] = seed .getString (i );
278
- }
279
-
280
- //Build init request
281
- Walletunlocker .InitWalletRequest .Builder initRequest = Walletunlocker .InitWalletRequest .newBuilder ();
282
- initRequest .setWalletPassword (ByteString .copyFrom (password .getBytes ()));
283
- initRequest .addAllCipherSeedMnemonic (Arrays .asList (seedArray ));
284
-
285
263
class InitWalletTask implements Runnable {
286
264
byte [] request ;
287
265
InitWalletTask (byte [] r ) { request = r ;}
288
266
public void run () {
289
267
Lndmobile .initWallet (request , new InitializeWalletCallback ());
290
268
}
291
269
}
292
- Thread t = new Thread (new InitWalletTask (initRequest . build (). toByteArray ( )));
270
+ Thread t = new Thread (new InitWalletTask (Base64 . decode ( msg , Base64 . NO_WRAP )));
293
271
t .start ();
294
272
}
295
273
296
274
@ ReactMethod
297
- public void unlockWallet (String password , final Promise promise ) {
275
+ public void unlockWallet (String msg , final Promise promise ) {
298
276
Log .i ("LndNativeModule" , "Unlocking wallet..." );
299
277
300
278
class UnlockWalletCallback implements Callback {
@@ -320,18 +298,14 @@ public void onResponse(byte[] bytes) {
320
298
}
321
299
}
322
300
323
- //Build unlock request
324
- Walletunlocker .UnlockWalletRequest .Builder unlockRequest = Walletunlocker .UnlockWalletRequest .newBuilder ();
325
- unlockRequest .setWalletPassword (ByteString .copyFrom (password .getBytes ()));
326
-
327
301
class UnlockWalletTask implements Runnable {
328
302
byte [] request ;
329
303
UnlockWalletTask (byte [] r ) { request = r ;}
330
304
public void run () {
331
305
Lndmobile .unlockWallet (request , new UnlockWalletCallback ());
332
306
}
333
307
}
334
- Thread t = new Thread (new UnlockWalletTask (unlockRequest . build (). toByteArray ( )));
308
+ Thread t = new Thread (new UnlockWalletTask (Base64 . decode ( msg , Base64 . NO_WRAP )));
335
309
t .start ();
336
310
}
337
311
@@ -457,10 +431,8 @@ public void onResponse(byte[] bytes) {
457
431
}
458
432
}
459
433
460
- byte [] b = Base64 .decode (msg , Base64 .NO_WRAP );
461
-
462
434
try {
463
- m .invoke (null , b , new NativeCallback (promise ));
435
+ m .invoke (null , Base64 . decode ( msg , Base64 . NO_WRAP ) , new NativeCallback (promise ));
464
436
465
437
//If LND was stopped reset state
466
438
if (method .equals ("StopDaemon" )) {
0 commit comments