Skip to content

Commit 1dad8d6

Browse files
authored
Merge pull request #2 from lightninglabs/init-project
Add JS project scaffolding, web -> RN changes, Android bindings
2 parents 373e721 + 0d32a5b commit 1dad8d6

File tree

152 files changed

+64874
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+64874
-17
lines changed

.gitignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
dist/
2+
3+
# OSX
4+
#
5+
.DS_Store
6+
7+
# XDE
8+
.expo/
9+
10+
# VSCode
11+
.vscode/
12+
jsconfig.json
13+
14+
# Xcode
15+
#
16+
build/
17+
*.pbxuser
18+
!default.pbxuser
19+
*.mode1v3
20+
!default.mode1v3
21+
*.mode2v3
22+
!default.mode2v3
23+
*.perspectivev3
24+
!default.perspectivev3
25+
xcuserdata
26+
*.xccheckout
27+
*.moved-aside
28+
DerivedData
29+
*.hmap
30+
*.ipa
31+
*.xcuserstate
32+
project.xcworkspace
33+
34+
# Android/IJ
35+
#
36+
.idea
37+
.gradle
38+
local.properties
39+
android.iml
40+
41+
# Cocoapods
42+
#
43+
example/ios/Pods
44+
45+
# node.js
46+
#
47+
node_modules/
48+
npm-debug.log
49+
yarn-debug.log
50+
yarn-error.log
51+
52+
# BUCK
53+
buck-out/
54+
\.buckd/
55+
android/app/libs
56+
android/keystores/debug.keystore
57+
58+
# Expo
59+
.expo/*
60+
61+
# generated by bob
62+
**/**/*.swp

.prettierignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.github/**
2+
demos/**
3+
dist/**
4+
lib/types/**
5+
package-lock.json
6+
package.json
7+
README.md
8+
test/**
9+
tsconfig.json
10+
tslint.json

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"singleQuote": true,
3+
"tabWidth": 4,
4+
"semi": true,
5+
"trailingComma": "none",
6+
"bracketSpacing": true
7+
}

README.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,17 @@ The constructor for the LNC object takes a parameters object with the three foll
1414

1515
- `pairingPhrase` (string): Your LNC pairing phrase
1616
- `serverHost` (string): Specify a custom Lightning Node Connect proxy server. If not specified we'll default to `mailbox.terminal.lightning.today:443`.
17-
- `password` (string): By default, this module will handle storage of your local and remote keys for you in local storage. We highly recommend encrypting that data with a password you set here.
1817

1918
```
2019
import LNC from ‘@lightninglabs/lnc-rn’;
2120
2221
const pairingPhrase = ‘artefact morning piano photo consider light’;
23-
const password = 'u*E0F?gU\d($N&Ckh8u)tLm';
2422
2523
// default connection using WASM from CDN
2624
// WASM loaded on object creation
2725
// default host: mailbox.terminal.lightning.today:443
28-
// password used for encrypting credentials
2926
const lnc = new LNC({
30-
pairingPhrase,
31-
password
27+
pairingPhrase
3228
});
3329
3430
// using custom Lightning Node Connect proxy server
@@ -73,20 +69,18 @@ const insights = await faraday.channelInsights();
7369
#### Subscriptions
7470

7571
```
72+
import { NativeEventEmitter } from 'react-native';
7673
const { lnd } = lnc;
7774
78-
// handle subscriptions
79-
lnd.lightning.subscribeTransactions(
80-
params,
81-
transaction => handleNewData(transaction),
82-
error => handleError(error),
83-
);
84-
85-
lnd.lightning.subscribeChannelEvents(
86-
params,
87-
event => handleNewChannelEventData(event),
88-
error => handleError(error),
89-
);
75+
const request = {};
76+
const eventName = lightning.subscribePeerEvents(request);
77+
const eventEmitter = new NativeEventEmitter();
78+
listener = eventEmitter.addListener(eventName, (event: any) => {
79+
console.log('Got response', event.result);
80+
});
81+
82+
// when ready to stop listener
83+
listener.stop();
9084
```
9185

9286
## Updating protos

android/build.gradle

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
buildscript {
2+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
3+
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['Lnc_kotlinVersion']
4+
5+
repositories {
6+
google()
7+
jcenter()
8+
}
9+
10+
dependencies {
11+
classpath 'com.android.tools.build:gradle:3.2.1'
12+
// noinspection DifferentKotlinGradleVersion
13+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14+
}
15+
}
16+
17+
apply plugin: 'com.android.library'
18+
apply plugin: 'kotlin-android'
19+
20+
def getExtOrDefault(name) {
21+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Lnc_' + name]
22+
}
23+
24+
def getExtOrIntegerDefault(name) {
25+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['Lnc_' + name]).toInteger()
26+
}
27+
28+
android {
29+
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
30+
buildToolsVersion getExtOrDefault('buildToolsVersion')
31+
defaultConfig {
32+
minSdkVersion rootProject.ext.has('minSdkVersion') ? rootProject.ext.minSdkVersion : 16
33+
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
34+
versionCode 1
35+
versionName "1.0"
36+
37+
}
38+
39+
buildTypes {
40+
release {
41+
minifyEnabled false
42+
}
43+
}
44+
lintOptions {
45+
disable 'GradleCompatible'
46+
}
47+
compileOptions {
48+
sourceCompatibility JavaVersion.VERSION_1_8
49+
targetCompatibility JavaVersion.VERSION_1_8
50+
}
51+
}
52+
53+
repositories {
54+
mavenCentral()
55+
jcenter()
56+
google()
57+
flatDir {
58+
dirs 'libs'
59+
}
60+
61+
def found = false
62+
def defaultDir = null
63+
def androidSourcesName = 'React Native sources'
64+
65+
if (rootProject.ext.has('reactNativeAndroidRoot')) {
66+
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
67+
} else {
68+
defaultDir = new File(
69+
projectDir,
70+
'/../../../node_modules/react-native/android'
71+
)
72+
}
73+
74+
if (defaultDir.exists()) {
75+
maven {
76+
url defaultDir.toString()
77+
name androidSourcesName
78+
}
79+
80+
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
81+
found = true
82+
} else {
83+
def parentDir = rootProject.projectDir
84+
85+
1.upto(5, {
86+
if (found) return true
87+
parentDir = parentDir.parentFile
88+
89+
def androidSourcesDir = new File(
90+
parentDir,
91+
'node_modules/react-native'
92+
)
93+
94+
def androidPrebuiltBinaryDir = new File(
95+
parentDir,
96+
'node_modules/react-native/android'
97+
)
98+
99+
if (androidPrebuiltBinaryDir.exists()) {
100+
maven {
101+
url androidPrebuiltBinaryDir.toString()
102+
name androidSourcesName
103+
}
104+
105+
logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
106+
found = true
107+
} else if (androidSourcesDir.exists()) {
108+
maven {
109+
url androidSourcesDir.toString()
110+
name androidSourcesName
111+
}
112+
113+
logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
114+
found = true
115+
}
116+
})
117+
}
118+
119+
if (!found) {
120+
throw new GradleException(
121+
"${project.name}: unable to locate React Native android sources. " +
122+
"Ensure you have you installed React Native as a dependency in your project and try again."
123+
)
124+
}
125+
}
126+
127+
def kotlin_version = getExtOrDefault('kotlinVersion')
128+
129+
dependencies {
130+
// noinspection GradleDynamicVersion
131+
api 'com.facebook.react:react-native:+'
132+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
133+
compileOnly files('libs/lnc-mobile.aar')
134+
}

android/gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Lnc_kotlinVersion=1.3.50
2+
Lnc_compileSdkVersion=30
3+
Lnc_buildToolsVersion=30.0.1
4+
Lnc_targetSdkVersion=30
57.3 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)