Skip to content
This repository was archived by the owner on Oct 24, 2022. It is now read-only.

Commit d8adbfb

Browse files
Merge pull request #21 from synonymdev/neutrino-cache
Neutrino cache
2 parents 02a97ae + 8d85223 commit d8adbfb

20 files changed

+664
-210
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
node_modules
22
dist
3-
src/*.d.ts
3+
src/protos

.eslintrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"rules": {
2222
"no-param-reassign": "error",
23-
"no-shadow": "error",
23+
"no-shadow": "off",
2424
"prettier/prettier": "warn",
2525
"indent": [
2626
2,
@@ -35,8 +35,8 @@
3535
"@typescript-eslint/switch-exhaustiveness-check": "error",
3636
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
3737
"@typescript-eslint/explicit-function-return-type": "error",
38-
"@typescript-eslint/space-before-function-paren": ["warn", "never"],
3938
"@typescript-eslint/no-unused-vars": "warn",
40-
"@typescript-eslint/strict-boolean-expressions": "off"
39+
"@typescript-eslint/strict-boolean-expressions": "off",
40+
"@typescript-eslint/restrict-template-expressions": "off"
4141
}
4242
}

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
node_modules/
22
.idea/
3-
src/rpc.*
4-
src/walletunlocker.*
3+
src/protos/*.ts
4+
src/protos/*.js
55
dist/
66
**.DS_Store
77
android/build/

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,31 @@ lnd.subscribeToOnChainTransactions(
101101

102102

103103
```
104+
105+
### Using neutrino headers cache
106+
Initial neutrino sync times can take a while for first time users. This is a trusted setup that allows the app to download a cached pre-synced archive of the neutrino headers. This speeds up the time it takes for LND to become usable as syncing doesn't need to start from scratch.
107+
```bash
108+
#Add these dependencies to your app
109+
yarn add react-native-fs react-native-zip-archive
110+
#or
111+
npm i react-native-fs react-native-zip-archive -S
112+
113+
cd ios && pod install && cd ../
114+
````
115+
116+
Using it:
117+
118+
```javascript
119+
import lndCache from '@synonymdev/react-native-lightning/dist/utils/neutrino-cache';
120+
```
121+
122+
```javascript
123+
lndCache.addStateListener(
124+
(state: ICachedNeutrinoDBDownloadState) => {
125+
setMessage(JSON.stringify(state));
126+
},
127+
);
128+
129+
await lndCache.downloadCache(ENetworks.testnet);
130+
await startLnd();
131+
```

example/App.tsx

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ import lnd, {
2222
ENetworks,
2323
LndConf,
2424
TCurrentLndState,
25+
ICachedNeutrinoDBDownloadState,
2526
} from '@synonymdev/react-native-lightning';
2627

28+
import lndCache from '@synonymdev/react-native-lightning/dist/utils/neutrino-cache';
29+
2730
import {emoji} from './src/helpers';
2831
import PSBT from './src/PSBT';
2932
import Options from './src/Options';
@@ -57,7 +60,7 @@ const App = () => {
5760

5861
lnd.subscribeToCurrentState(setLndState);
5962
})();
60-
}, []);
63+
}, [lndState]);
6164

6265
useEffect(() => {
6366
if (lndState.walletUnlocked) {
@@ -129,24 +132,41 @@ const App = () => {
129132
}}
130133
/>
131134
) : (
132-
<Button
133-
title={'Start LND'}
134-
onPress={async () => {
135-
setMessage('Starting LND...');
136-
137-
const customFields = {};
138-
const lndConf = new LndConf(network, customFields);
139-
const res = await lnd.start(lndConf);
140-
141-
if (res.isErr()) {
142-
setMessage(res.error.message);
143-
console.error(res.error);
144-
return;
145-
}
146-
147-
setMessage(JSON.stringify(res.value));
148-
}}
149-
/>
135+
<>
136+
<Button
137+
title={'Download cached headers then start LND'}
138+
onPress={async () => {
139+
setMessage('Downloading cached headers...');
140+
setMessage(JSON.stringify(lndCache));
141+
lndCache.addStateListener(
142+
(state: ICachedNeutrinoDBDownloadState) => {
143+
setMessage(JSON.stringify(state));
144+
},
145+
);
146+
147+
await lndCache.downloadCache(ENetworks.testnet);
148+
// await startLnd();
149+
}}
150+
/>
151+
<Button
152+
title={'Start LND'}
153+
onPress={async () => {
154+
setMessage('Starting LND...');
155+
156+
const customFields = {};
157+
const lndConf = new LndConf(network, customFields);
158+
const res = await lnd.start(lndConf);
159+
160+
if (res.isErr()) {
161+
setMessage(res.error.message);
162+
console.error(res.error);
163+
return;
164+
}
165+
166+
setMessage(JSON.stringify(res.value));
167+
}}
168+
/>
169+
</>
150170
)}
151171

152172
{showGenerateSeed ? (

example/ios/Podfile.lock

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ PODS:
185185
- React-cxxreact (= 0.63.4)
186186
- React-jsi (= 0.63.4)
187187
- React-jsinspector (0.63.4)
188-
- react-native-lightning (0.0.24):
188+
- react-native-lightning (0.0.28):
189189
- React
190190
- React-RCTActionSheet (0.63.4):
191191
- React-Core/RCTActionSheetHeaders (= 0.63.4)
@@ -249,6 +249,16 @@ PODS:
249249
- React-jsi (= 0.63.4)
250250
- RNCClipboard (1.7.0):
251251
- React-Core
252+
- RNFS (2.18.0):
253+
- React
254+
- RNZipArchive (6.0.3):
255+
- React-Core
256+
- RNZipArchive/Core (= 6.0.3)
257+
- SSZipArchive (= 2.2.3)
258+
- RNZipArchive/Core (6.0.3):
259+
- React-Core
260+
- SSZipArchive (= 2.2.3)
261+
- SSZipArchive (2.2.3)
252262
- Yoga (1.14.0)
253263

254264
DEPENDENCIES:
@@ -281,11 +291,14 @@ DEPENDENCIES:
281291
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
282292
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
283293
- "RNCClipboard (from `../node_modules/@react-native-clipboard/clipboard`)"
294+
- RNFS (from `../node_modules/react-native-fs`)
295+
- RNZipArchive (from `../node_modules/react-native-zip-archive`)
284296
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
285297

286298
SPEC REPOS:
287299
trunk:
288300
- boost-for-react-native
301+
- SSZipArchive
289302

290303
EXTERNAL SOURCES:
291304
DoubleConversion:
@@ -342,6 +355,10 @@ EXTERNAL SOURCES:
342355
:path: "../node_modules/react-native/ReactCommon"
343356
RNCClipboard:
344357
:path: "../node_modules/@react-native-clipboard/clipboard"
358+
RNFS:
359+
:path: "../node_modules/react-native-fs"
360+
RNZipArchive:
361+
:path: "../node_modules/react-native-zip-archive"
345362
Yoga:
346363
:path: "../node_modules/react-native/ReactCommon/yoga"
347364

@@ -362,7 +379,7 @@ SPEC CHECKSUMS:
362379
React-jsi: a0418934cf48f25b485631deb27c64dc40fb4c31
363380
React-jsiexecutor: 93bd528844ad21dc07aab1c67cb10abae6df6949
364381
React-jsinspector: 58aef7155bc9a9683f5b60b35eccea8722a4f53a
365-
react-native-lightning: 609ccfb42e601a7a075fba5fb1366003a9e287cb
382+
react-native-lightning: 6ed013f7c5427d80ab76b63d012cfa5baa95531b
366383
React-RCTActionSheet: 89a0ca9f4a06c1f93c26067af074ccdce0f40336
367384
React-RCTAnimation: 1bde3ecc0c104c55df246eda516e0deb03c4e49b
368385
React-RCTBlob: a97d378b527740cc667e03ebfa183a75231ab0f0
@@ -374,6 +391,9 @@ SPEC CHECKSUMS:
374391
React-RCTVibration: ae4f914cfe8de7d4de95ae1ea6cc8f6315d73d9d
375392
ReactCommon: 73d79c7039f473b76db6ff7c6b159c478acbbb3b
376393
RNCClipboard: 245417a78ab585e0d4d83926c28907e7b2bc24bd
394+
RNFS: 3ab21fa6c56d65566d1fb26c2228e2b6132e5e32
395+
RNZipArchive: 924d63f15f2838837f8379ee6e9955d8ff4736c4
396+
SSZipArchive: 62d4947b08730e4cda640473b0066d209ff033c9
377397
Yoga: 4bd86afe9883422a7c4028c00e34790f560923d6
378398

379399
PODFILE CHECKSUM: 68dc732fcf33a342148a67cab9f313638be7a515

example/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
},
1212
"dependencies": {
1313
"@react-native-clipboard/clipboard": "^1.7.0",
14+
"@synonymdev/react-native-lightning": "link:../",
1415
"react": "16.13.1",
1516
"react-native": "0.63.4",
16-
"@synonymdev/react-native-lightning": "link:../"
17+
"react-native-fs": "^2.18.0",
18+
"react-native-zip-archive": "^6.0.3"
1719
},
1820
"devDependencies": {
1921
"@babel/core": "^7.8.4",

example/yarn.lock

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,13 @@
977977
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
978978
integrity sha1-p3c2C1s5oaLlEG+OhY8v0tBgxXA=
979979

980+
"@react-native-async-storage/async-storage@^1.15.4":
981+
version "1.15.4"
982+
resolved "https://registry.yarnpkg.com/@react-native-async-storage/async-storage/-/async-storage-1.15.4.tgz#cdba464ca3bb9f10ec538342cbf2520c06f453ab"
983+
integrity sha512-pC0MS6UBuv/YiVAxtzi7CgUed8oCQNYMtGt0yb/I9fI/BWTiJK5cj4YtW2XtL95K5IuvPX/6uGWaouZ8KqXwdg==
984+
dependencies:
985+
deep-assign "^3.0.0"
986+
980987
"@react-native-clipboard/clipboard@^1.7.0":
981988
version "1.7.0"
982989
resolved "https://registry.yarnpkg.com/@react-native-clipboard/clipboard/-/clipboard-1.7.0.tgz#43320841870b82b2f311f375dd5f178da46e244e"
@@ -1760,6 +1767,11 @@ balanced-match@^1.0.0:
17601767
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
17611768
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
17621769

1770+
base-64@^0.1.0:
1771+
version "0.1.0"
1772+
resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb"
1773+
integrity sha1-eAqZyE59YAJgNhURxId2E78k9rs=
1774+
17631775
base64-js@^1.1.2, base64-js@^1.2.3, base64-js@^1.5.1:
17641776
version "1.5.1"
17651777
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
@@ -2304,6 +2316,13 @@ decode-uri-component@^0.2.0:
23042316
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
23052317
integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=
23062318

2319+
deep-assign@^3.0.0:
2320+
version "3.0.0"
2321+
resolved "https://registry.yarnpkg.com/deep-assign/-/deep-assign-3.0.0.tgz#c8e4c4d401cba25550a2f0f486a2e75bc5f219a2"
2322+
integrity sha512-YX2i9XjJ7h5q/aQ/IM9PEwEnDqETAIYbggmdDB3HLTlSgo1CxPsj6pvhPG68rq6SVE0+p+6Ywsm5fTYNrYtBWw==
2323+
dependencies:
2324+
is-obj "^1.0.0"
2325+
23072326
deep-is@~0.1.3:
23082327
version "0.1.3"
23092328
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
@@ -3602,6 +3621,11 @@ is-number@^7.0.0:
36023621
resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
36033622
integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==
36043623

3624+
is-obj@^1.0.0:
3625+
version "1.0.1"
3626+
resolved "https://registry.yarnpkg.com/is-obj/-/is-obj-1.0.1.tgz#3e4729ac1f5fde025cd7d83a896dab9f4f67db0f"
3627+
integrity sha1-PkcprB9f3gJc19g6iW2rn09n2w8=
3628+
36053629
is-plain-object@^2.0.3, is-plain-object@^2.0.4:
36063630
version "2.0.4"
36073631
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-2.0.4.tgz#2c163b3fafb1b606d9d17928f05c2a1c38e07677"
@@ -5480,6 +5504,19 @@ react-is@^16.12.0, react-is@^16.8.1, react-is@^16.8.4, react-is@^16.8.6:
54805504
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
54815505
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
54825506

5507+
react-native-fs@^2.18.0:
5508+
version "2.18.0"
5509+
resolved "https://registry.yarnpkg.com/react-native-fs/-/react-native-fs-2.18.0.tgz#987b99cc90518ef26663a8d60e62104694b41c21"
5510+
integrity sha512-9iQhkUNnN2JNED0in06JwZy88YEVyIGKWz4KLlQYxa5Y2U0U2AZh9FUHtA04oWj+xt2LlHh0LFPCzhmNsAsUDg==
5511+
dependencies:
5512+
base-64 "^0.1.0"
5513+
utf8 "^3.0.0"
5514+
5515+
react-native-zip-archive@^6.0.3:
5516+
version "6.0.3"
5517+
resolved "https://registry.yarnpkg.com/react-native-zip-archive/-/react-native-zip-archive-6.0.3.tgz#19dad30565b068b352c55048c8c535a6195f0b46"
5518+
integrity sha512-EBJJV+owqD8ibBwYvEuvtBWlstHQUaN7QOJbc7shWwtJEgxayRbyVv5gGtUGTnMO2wX+dav+3egHX3s7GacRyA==
5519+
54835520
react-native@0.63.4:
54845521
version "0.63.4"
54855522
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.63.4.tgz#2210fdd404c94a5fa6b423c6de86f8e48810ec36"
@@ -6681,6 +6718,11 @@ use@^3.1.0:
66816718
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
66826719
integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==
66836720

6721+
utf8@^3.0.0:
6722+
version "3.0.0"
6723+
resolved "https://registry.yarnpkg.com/utf8/-/utf8-3.0.0.tgz#f052eed1364d696e769ef058b183df88c87f69d1"
6724+
integrity sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ==
6725+
66846726
util-deprecate@~1.0.1:
66856727
version "1.0.2"
66866728
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@synonymdev/react-native-lightning",
33
"title": "React Native Lightning",
4-
"version": "0.0.24",
4+
"version": "0.0.28",
55
"description": "React Native wrapper for Lndmobile",
66
"main": "./dist/index.js",
77
"types": "./dist/index.d.ts",
@@ -25,8 +25,8 @@
2525
"lint": "yarn run lint:ts",
2626
"lint:ts": "eslint . --ext .ts,.tsx --fix",
2727
"protobuf": "yarn run protobuf:rpc && yarn run protobuf:walletunlocker",
28-
"protobuf:rpc": "pbjs -t static-module -w commonjs -o dist/rpc.js src/protos/rpc.proto && pbjs -t static-module src/protos/rpc.proto | pbts -o dist/rpc.d.ts - && cp dist/rpc.* ./src/",
29-
"protobuf:walletunlocker": "pbjs -t static-module -w commonjs -o dist/walletunlocker.js src/protos/walletunlocker.proto && pbjs -t static-module src/protos/walletunlocker.proto | pbts -o dist/walletunlocker.d.ts - && cp dist/walletunlocker.* ./src/",
28+
"protobuf:rpc": "mkdir -p dist/protos && pbjs -t static-module -w commonjs -o dist/protos/rpc.js src/protos/rpc.proto && pbjs -t static-module src/protos/rpc.proto | pbts -o dist/protos/rpc.d.ts - && cp dist/protos/rpc.* ./src/protos/",
29+
"protobuf:walletunlocker": "mkdir -p dist/protos && pbjs -t static-module -w commonjs -o dist/protos/walletunlocker.js src/protos/walletunlocker.proto && pbjs -t static-module src/protos/walletunlocker.proto | pbts -o dist/protos/walletunlocker.d.ts - && cp dist/protos/walletunlocker.* ./src/protos/",
3030
"prepublish": "yarn lint && yarn run build && npm --no-git-tag-version version patch"
3131
},
3232
"repository": {
@@ -44,8 +44,8 @@
4444
"devDependencies": {
4545
"@react-native-community/eslint-config": "^2.0.0",
4646
"@types/react-native": "0.62.13",
47-
"@typescript-eslint/eslint-plugin": "3.3.0",
48-
"@typescript-eslint/parser": "3.3.0",
47+
"@typescript-eslint/eslint-plugin": "^4.25.0",
48+
"@typescript-eslint/parser": "^4.25.0",
4949
"eslint": "^7.20.0",
5050
"eslint-config-prettier": "6.11.0",
5151
"eslint-config-standard-with-typescript": "18.0.2",
@@ -57,11 +57,13 @@
5757
"eslint-plugin-standard": "4.0.1",
5858
"prettier": "^2.2.1",
5959
"react": "^16.9.0",
60-
"typescript": "^4.1.5"
60+
"typescript": "^4.2.4"
6161
},
6262
"dependencies": {
6363
"base64-js": "^1.5.1",
64-
"protobufjs": "^6.10.2"
64+
"protobufjs": "^6.10.2",
65+
"react-native-fs": "^2.18.0",
66+
"react-native-zip-archive": "^6.0.3"
6567
},
6668
"bugs": {
6769
"url": "https://github.com/synonymdev/react-native-lightning/issues"

react-native-lightning.podspec

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ Pod::Spec.new do |s|
2121
s.source_files = "ios/**/*.{h,m,swift}"
2222
s.requires_arc = true
2323

24-
# s.frameworks = 'Lndmobile'
2524
s.vendored_frameworks = 'ios/Lndmobile.framework'
2625
s.dependency "React"
27-
# ...
28-
# s.dependency "..."
2926
end
30-

0 commit comments

Comments
 (0)