Skip to content

Commit 3767cc7

Browse files
authored
Merge pull request #268 from synonymdev/local-funded-channels
Locally funded channels
2 parents 885ed8a + a90b556 commit 3767cc7

File tree

17 files changed

+1064
-302
lines changed

17 files changed

+1064
-302
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.vscode/
12
.idea/
23
**/.DS_Store
34
example/.watchman*

README.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ This library hopes to simplify the process of adding Lightning via LDK to any Re
1212
yarn add @synonymdev/react-native-ldk
1313
#or
1414
npm i -S @synonymdev/react-native-ldk
15-
````
15+
```
1616

1717
### iOS installation
1818
```bash
1919
cd ios && pod install && cd ../
20-
````
20+
```
2121

2222
### Android installation
2323
1. Add the following line to `dependencies` in `/android/app/build.gradle`
24-
```
25-
dependencies {
26-
...
27-
implementation files("../../node_modules/@synonymdev/react-native-ldk/android/libs/LDK-release.aar")
28-
}
29-
```
24+
```groovy
25+
dependencies {
26+
//...
27+
implementation files("../../node_modules/@synonymdev/react-native-ldk/android/libs/LDK-release.aar") // <- this
28+
}
29+
```
3030
2. Ensure `minSdkVersion` is set to at least `24` in `/android/build.gradle`
3131
3232
## Development
@@ -40,19 +40,32 @@ dependencies {
4040
5. In the popup that appears select `JavaDocs` and tap `OK` then `OK` again
4141
4242
## Running example app
43+
See also [`./example/README.md`](./example/README.md)
4344
```bash
44-
45-
#Build dist files
45+
# Build dist files
4646
git clone https://github.com/synonymdev/react-native-ldk.git
4747
cd react-native-ldk/lib/ && yarn install && yarn build && cd ../
4848
4949
cd example/ && yarn install && yarn rn-setup
5050
5151
yarn ios
52-
#or
52+
# or
5353
yarn android
5454
```
5555

56+
### Update config to match your local setup
57+
In `constants.ts` update `peers.lnd` if you're using Polar locally.
58+
### Example for Android
59+
```ts
60+
// export const peers = {
61+
// lnd: {
62+
pubKey:
63+
'_033f4d3032ce7f54224f4bd9747b50b7cd72074a859758e40e1ca46ffa79a34324_',
64+
address: '10.0.2.2',
65+
port: 9737,
66+
// },
67+
```
68+
5669
## Notes
5770
- It is important to not mix and match account names and seeds when starting LDK. Doing so can result in a corrupt save.
5871

example/Dev.tsx

Lines changed: 80 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ import lm, {
2525
TChannelUpdate,
2626
} from '@synonymdev/react-native-ldk';
2727
import { backupServerDetails, peers } from './utils/constants';
28-
import { createNewAccount, getAccount, getAddress } from './utils/helpers';
28+
import {
29+
createNewAccount,
30+
getAccount,
31+
getAddress,
32+
getAddressFromScriptPubKey,
33+
} from './utils/helpers';
2934
import RNFS from 'react-native-fs';
3035

3136
let logSubscription: EmitterSubscription | undefined;
@@ -41,6 +46,7 @@ const Dev = (): ReactElement => {
4146
const [nodeStarted, setNodeStarted] = useState(false);
4247
const [showLogs, setShowLogs] = useState(false);
4348
const [logContent, setLogContent] = useState('');
49+
const [temporaryChannelId, setTemporaryChannelId] = useState(''); //For funding channels locally
4450

4551
useEffect(() => {
4652
//Restarting LDK on each code update causes constant errors.
@@ -231,7 +237,6 @@ const Dev = (): ReactElement => {
231237
}
232238
}}
233239
/>
234-
235240
<Button
236241
title={'Get Node ID'}
237242
onPress={async (): Promise<void> => {
@@ -246,7 +251,6 @@ const Dev = (): ReactElement => {
246251
setMessage(`Node ID: ${nodeIdRes.value}`);
247252
}}
248253
/>
249-
250254
<Button
251255
title={'Sync LDK'}
252256
onPress={async (): Promise<void> => {
@@ -258,7 +262,6 @@ const Dev = (): ReactElement => {
258262
setMessage(syncRes.value);
259263
}}
260264
/>
261-
262265
<View style={styles.buttonRow}>
263266
<Button
264267
title={'Add Peers'}
@@ -299,7 +302,6 @@ const Dev = (): ReactElement => {
299302
}}
300303
/>
301304
</View>
302-
303305
<View style={styles.buttonRow}>
304306
<Button
305307
title={'List channels'}
@@ -393,7 +395,6 @@ const Dev = (): ReactElement => {
393395
}}
394396
/>
395397
</View>
396-
397398
<View style={styles.buttonRow}>
398399
<Button
399400
title={'List watch transactions'}
@@ -409,7 +410,6 @@ const Dev = (): ReactElement => {
409410
}}
410411
/>
411412
</View>
412-
413413
<Button
414414
title={'🤑Get Address Balance'}
415415
onPress={async (): Promise<void> => {
@@ -421,7 +421,6 @@ const Dev = (): ReactElement => {
421421
);
422422
}}
423423
/>
424-
425424
<Button
426425
title={'Recover all outputs attempt'}
427426
onPress={async (): Promise<void> => {
@@ -435,7 +434,6 @@ const Dev = (): ReactElement => {
435434
setMessage(res.value);
436435
}}
437436
/>
438-
439437
<View style={styles.buttonRow}>
440438
<Button
441439
title={'Get claimed payments'}
@@ -454,7 +452,6 @@ const Dev = (): ReactElement => {
454452
}}
455453
/>
456454
</View>
457-
458455
<View style={styles.buttonRow}>
459456
<Button
460457
title={'Create invoice'}
@@ -548,7 +545,6 @@ const Dev = (): ReactElement => {
548545
}}
549546
/>
550547
</View>
551-
552548
<Button
553549
title={'Get network graph nodes'}
554550
onPress={async (): Promise<void> => {
@@ -574,7 +570,6 @@ const Dev = (): ReactElement => {
574570
setMessage(`${msg}`);
575571
}}
576572
/>
577-
578573
<Button
579574
title={'Show claimable balances for closed/closing channels'}
580575
onPress={async (): Promise<void> => {
@@ -586,7 +581,6 @@ const Dev = (): ReactElement => {
586581
setMessage(JSON.stringify(balances.value));
587582
}}
588583
/>
589-
590584
<Button
591585
title={'List channel monitors'}
592586
onPress={async (): Promise<void> => {
@@ -604,6 +598,79 @@ const Dev = (): ReactElement => {
604598
}}
605599
/>
606600

601+
<Button
602+
title={'Start manual channel open ⛓️'}
603+
onPress={async (): Promise<void> => {
604+
try {
605+
const res = await lm.createChannel({
606+
counterPartyNodeId: peers.lnd.pubKey,
607+
channelValueSats: 20000,
608+
pushSats: 5000,
609+
});
610+
if (res.isErr()) {
611+
setMessage(res.error.message);
612+
return;
613+
}
614+
615+
const { value_satoshis, output_script, temp_channel_id } =
616+
res.value;
617+
618+
setTemporaryChannelId(temp_channel_id);
619+
620+
console.log(res.value);
621+
622+
const address = getAddressFromScriptPubKey(output_script);
623+
const btc = value_satoshis / 100000000;
624+
625+
console.log('***BITCOIND CLI***');
626+
console.log('bitcoin-cli listunspent');
627+
console.log(
628+
`bitcoin-cli createrawtransaction '[{"txid":"<tx-id>","vout":<index>}]' '{"${address}":${btc}}'`,
629+
);
630+
console.log(
631+
'bitcoin-cli signrawtransactionwithwallet "<raw-transaction-hex>"',
632+
);
633+
console.log('********');
634+
635+
setMessage(
636+
`Create tx with ${value_satoshis} for address ${address}. See logs for bitcoin-cli commands needed to create funding tx.`,
637+
);
638+
} catch (e) {
639+
setMessage(JSON.stringify(e));
640+
}
641+
}}
642+
/>
643+
644+
{temporaryChannelId ? (
645+
<Button
646+
title={'Fund channel (paste psbt)'}
647+
onPress={async (): Promise<void> => {
648+
try {
649+
if (!temporaryChannelId) {
650+
return setMessage('Create channel first');
651+
}
652+
653+
const pastedSignedTx = await Clipboard.getString();
654+
655+
const res = await ldk.fundChannel({
656+
temporaryChannelId,
657+
counterPartyNodeId: peers.lnd.pubKey,
658+
fundingTransaction: pastedSignedTx,
659+
});
660+
if (res.isErr()) {
661+
setMessage(res.error.message);
662+
return;
663+
}
664+
665+
setMessage('Channel funded');
666+
setTemporaryChannelId('');
667+
} catch (e) {
668+
setMessage(JSON.stringify(e));
669+
}
670+
}}
671+
/>
672+
) : null}
673+
607674
<Button
608675
title={'Show version'}
609676
onPress={async (): Promise<void> => {
@@ -615,7 +682,6 @@ const Dev = (): ReactElement => {
615682
setMessage(ldkVersion.value.ldk);
616683
}}
617684
/>
618-
619685
<Button
620686
title={'Show LDK logs'}
621687
onPress={async (): Promise<void> => {
@@ -631,7 +697,6 @@ const Dev = (): ReactElement => {
631697
}
632698
}}
633699
/>
634-
635700
<Button
636701
title={'Restore backup from server'}
637702
onPress={async (): Promise<void> => {
@@ -658,7 +723,6 @@ const Dev = (): ReactElement => {
658723
setMessage('Successfully restored wallet');
659724
}}
660725
/>
661-
662726
<Button
663727
title={'Backup self check'}
664728
onPress={async (): Promise<void> => {
@@ -671,7 +735,6 @@ const Dev = (): ReactElement => {
671735
setMessage('Backup server check passed ✅');
672736
}}
673737
/>
674-
675738
<Button
676739
title={'Restart node'}
677740
onPress={async (): Promise<void> => {
@@ -699,7 +762,6 @@ const Dev = (): ReactElement => {
699762
setMessage(res.value);
700763
}}
701764
/>
702-
703765
<Button
704766
title={'Node state'}
705767
onPress={async (): Promise<void> => {
@@ -712,7 +774,6 @@ const Dev = (): ReactElement => {
712774
setMessage(res.value);
713775
}}
714776
/>
715-
716777
<Button
717778
title={'List backed up files'}
718779
onPress={async (): Promise<void> => {
@@ -726,7 +787,6 @@ const Dev = (): ReactElement => {
726787
setMessage(JSON.stringify(res.value));
727788
}}
728789
/>
729-
730790
<Button
731791
title={'Test file backup'}
732792
onPress={async (): Promise<void> => {

example/babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
module.exports = {
22
presets: ['module:metro-react-native-babel-preset'],
3+
plugins: [
4+
['@babel/plugin-transform-class-properties', { loose: false }],
5+
['@babel/plugin-proposal-private-methods', { loose: false }],
6+
['@babel/plugin-transform-private-property-in-object', { loose: false }],
7+
],
38
};

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ PODS:
316316
- React-jsinspector (0.72.4)
317317
- React-logger (0.72.4):
318318
- glog
319-
- react-native-ldk (0.0.148):
319+
- react-native-ldk (0.0.150):
320320
- React
321321
- react-native-randombytes (3.6.1):
322322
- React-Core
@@ -621,7 +621,7 @@ SPEC CHECKSUMS:
621621
React-jsiexecutor: c7f826e40fa9cab5d37cab6130b1af237332b594
622622
React-jsinspector: aaed4cf551c4a1c98092436518c2d267b13a673f
623623
React-logger: da1ebe05ae06eb6db4b162202faeafac4b435e77
624-
react-native-ldk: fda4d4381d40401bdc5c3a9965937d19b232ed08
624+
react-native-ldk: 2b19de9eb94dcfd46f3f2a7191502292b75a5d7a
625625
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
626626
react-native-tcp-socket: c1b7297619616b4c9caae6889bcb0aba78086989
627627
React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f

example/metro.config.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
1+
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
2+
const path = require('path');
23

34
/**
45
* Metro configuration
56
* https://facebook.github.io/metro/docs/configuration
67
*
78
* @type {import('metro-config').MetroConfig}
89
*/
9-
const config = {};
10+
const defaultConfig = getDefaultConfig(__dirname);
1011

11-
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
12+
const config = {
13+
resolver: {
14+
extraNodeModules: {
15+
stream: path.resolve(__dirname, 'node_modules/stream-browserify'),
16+
buffer: path.resolve(__dirname, 'node_modules/buffer/'),
17+
assert: path.resolve(__dirname, 'node_modules/assert/'),
18+
events: path.resolve(__dirname, 'node_modules/events/'),
19+
crypto: path.resolve(__dirname, 'node_modules/crypto-browserify/'),
20+
vm: path.resolve(__dirname, 'node_modules/vm-browserify/'),
21+
process: path.resolve(__dirname, 'node_modules/process/'),
22+
},
23+
},
24+
};
25+
26+
module.exports = mergeConfig(defaultConfig, config);

0 commit comments

Comments
 (0)