Skip to content
This repository was archived by the owner on Oct 24, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
node_modules/
.idea/
src/lightning/router.js
src/lightning/autopilot.js
src/lightning/rpc.js
src/rpc.*
src/walletunlocker.*
dist/
**.DS_Store
android/build/
Expand Down
3 changes: 0 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ android {
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
multiDexEnabled true
}
lintOptions {
abortOnError false
Expand All @@ -75,8 +74,6 @@ dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
compileOnly files('libs/Lndmobile.aar')
implementation 'com.google.protobuf:protobuf-java:3.13.0'
implementation 'com.android.support:multidex:1.0.3'
}

def configureReactNativePom(def pom) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -35,11 +34,6 @@
import lndmobile.Lndmobile;
import lndmobile.RecvStream;
import lndmobile.SendStream;
import lnrpc.Walletunlocker;

import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.ProtocolStringList;

public class ReactNativeLightningModule extends ReactContextBaseJavaModule {

Expand Down Expand Up @@ -222,21 +216,15 @@ public void onResponse(byte[] bytes) {
Log.i(TAG, "Seed generated successfully");
Log.d(TAG, "Seed generated successfully");

try {
ProtocolStringList seed = Walletunlocker.GenSeedResponse.parseFrom(bytes).getCipherSeedMnemonicList();

//Map seed list into a react native string array
WritableArray promiseSeed = Arguments.createArray();
for(int i = 0; i < seed.size(); i++){
promiseSeed.pushString(seed.get(i));
}

promise.resolve(promiseSeed);
} catch (InvalidProtocolBufferException e) {
Log.i(TAG, "Failed to pass genSeed response: " + e.getMessage());
Log.d(TAG, "Failed to pass genSeed response: " + e.getMessage());
promise.reject(e);
String b64 = "";
if (bytes != null && bytes.length > 0) {
b64 = Base64.encodeToString(bytes, Base64.NO_WRAP);
}

WritableMap params = Arguments.createMap();
params.putString(respB64DataKey, b64);

promise.resolve(params);
}
}

Expand All @@ -247,12 +235,13 @@ public void run() {
Lndmobile.genSeed(request, new SeedCallback());
}
}
Thread t = new Thread(new GenSeedTask(Walletunlocker.GenSeedRequest.newBuilder().build().toByteArray()));

Thread t = new Thread(new GenSeedTask(new byte[0]));
t.start();
}

@ReactMethod
public void createWallet(String password, ReadableArray seed, final Promise promise) {
public void createWallet(String msg, final Promise promise) {
Log.i("LndNativeModule", "Initializing wallet...");

class InitializeWalletCallback implements Callback {
Expand All @@ -271,30 +260,19 @@ public void onResponse(byte[] bytes) {
}
}

//Map a react native ReadableArray to java string array
String[] seedArray = new String[seed.size()];
for (int i = 0; i < seed.size(); i++) {
seedArray[i] = seed.getString(i);
}

//Build init request
Walletunlocker.InitWalletRequest.Builder initRequest = Walletunlocker.InitWalletRequest.newBuilder();
initRequest.setWalletPassword(ByteString.copyFrom(password.getBytes()));
initRequest.addAllCipherSeedMnemonic(Arrays.asList(seedArray));

class InitWalletTask implements Runnable {
byte[] request;
InitWalletTask(byte[] r) { request = r;}
public void run() {
Lndmobile.initWallet(request, new InitializeWalletCallback());
}
}
Thread t = new Thread(new InitWalletTask(initRequest.build().toByteArray()));
Thread t = new Thread(new InitWalletTask(Base64.decode(msg, Base64.NO_WRAP)));
t.start();
}

@ReactMethod
public void unlockWallet(String password, final Promise promise) {
public void unlockWallet(String msg, final Promise promise) {
Log.i("LndNativeModule", "Unlocking wallet...");

class UnlockWalletCallback implements Callback {
Expand All @@ -320,18 +298,14 @@ public void onResponse(byte[] bytes) {
}
}

//Build unlock request
Walletunlocker.UnlockWalletRequest.Builder unlockRequest = Walletunlocker.UnlockWalletRequest.newBuilder();
unlockRequest.setWalletPassword(ByteString.copyFrom(password.getBytes()));

class UnlockWalletTask implements Runnable {
byte[] request;
UnlockWalletTask(byte[] r) { request = r;}
public void run() {
Lndmobile.unlockWallet(request, new UnlockWalletCallback());
}
}
Thread t = new Thread(new UnlockWalletTask(unlockRequest.build().toByteArray()));
Thread t = new Thread(new UnlockWalletTask(Base64.decode(msg, Base64.NO_WRAP)));
t.start();
}

Expand Down Expand Up @@ -457,10 +431,8 @@ public void onResponse(byte[] bytes) {
}
}

byte[] b = Base64.decode(msg, Base64.NO_WRAP);

try {
m.invoke(null, b, new NativeCallback(promise));
m.invoke(null, Base64.decode(msg, Base64.NO_WRAP), new NativeCallback(promise));

//If LND was stopped reset state
if (method.equals("StopDaemon")) {
Expand Down
Loading