@@ -25,7 +25,12 @@ import lm, {
25
25
TChannelUpdate ,
26
26
} from '@synonymdev/react-native-ldk' ;
27
27
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' ;
29
34
import RNFS from 'react-native-fs' ;
30
35
31
36
let logSubscription : EmitterSubscription | undefined ;
@@ -41,6 +46,7 @@ const Dev = (): ReactElement => {
41
46
const [ nodeStarted , setNodeStarted ] = useState ( false ) ;
42
47
const [ showLogs , setShowLogs ] = useState ( false ) ;
43
48
const [ logContent , setLogContent ] = useState ( '' ) ;
49
+ const [ temporaryChannelId , setTemporaryChannelId ] = useState ( '' ) ; //For funding channels locally
44
50
45
51
useEffect ( ( ) => {
46
52
//Restarting LDK on each code update causes constant errors.
@@ -231,7 +237,6 @@ const Dev = (): ReactElement => {
231
237
}
232
238
} }
233
239
/>
234
-
235
240
< Button
236
241
title = { 'Get Node ID' }
237
242
onPress = { async ( ) : Promise < void > => {
@@ -246,7 +251,6 @@ const Dev = (): ReactElement => {
246
251
setMessage ( `Node ID: ${ nodeIdRes . value } ` ) ;
247
252
} }
248
253
/>
249
-
250
254
< Button
251
255
title = { 'Sync LDK' }
252
256
onPress = { async ( ) : Promise < void > => {
@@ -258,7 +262,6 @@ const Dev = (): ReactElement => {
258
262
setMessage ( syncRes . value ) ;
259
263
} }
260
264
/>
261
-
262
265
< View style = { styles . buttonRow } >
263
266
< Button
264
267
title = { 'Add Peers' }
@@ -299,7 +302,6 @@ const Dev = (): ReactElement => {
299
302
} }
300
303
/>
301
304
</ View >
302
-
303
305
< View style = { styles . buttonRow } >
304
306
< Button
305
307
title = { 'List channels' }
@@ -393,7 +395,6 @@ const Dev = (): ReactElement => {
393
395
} }
394
396
/>
395
397
</ View >
396
-
397
398
< View style = { styles . buttonRow } >
398
399
< Button
399
400
title = { 'List watch transactions' }
@@ -409,7 +410,6 @@ const Dev = (): ReactElement => {
409
410
} }
410
411
/>
411
412
</ View >
412
-
413
413
< Button
414
414
title = { '🤑Get Address Balance' }
415
415
onPress = { async ( ) : Promise < void > => {
@@ -421,7 +421,6 @@ const Dev = (): ReactElement => {
421
421
) ;
422
422
} }
423
423
/>
424
-
425
424
< Button
426
425
title = { 'Recover all outputs attempt' }
427
426
onPress = { async ( ) : Promise < void > => {
@@ -435,7 +434,6 @@ const Dev = (): ReactElement => {
435
434
setMessage ( res . value ) ;
436
435
} }
437
436
/>
438
-
439
437
< View style = { styles . buttonRow } >
440
438
< Button
441
439
title = { 'Get claimed payments' }
@@ -454,7 +452,6 @@ const Dev = (): ReactElement => {
454
452
} }
455
453
/>
456
454
</ View >
457
-
458
455
< View style = { styles . buttonRow } >
459
456
< Button
460
457
title = { 'Create invoice' }
@@ -548,7 +545,6 @@ const Dev = (): ReactElement => {
548
545
} }
549
546
/>
550
547
</ View >
551
-
552
548
< Button
553
549
title = { 'Get network graph nodes' }
554
550
onPress = { async ( ) : Promise < void > => {
@@ -574,7 +570,6 @@ const Dev = (): ReactElement => {
574
570
setMessage ( `${ msg } ` ) ;
575
571
} }
576
572
/>
577
-
578
573
< Button
579
574
title = { 'Show claimable balances for closed/closing channels' }
580
575
onPress = { async ( ) : Promise < void > => {
@@ -586,7 +581,6 @@ const Dev = (): ReactElement => {
586
581
setMessage ( JSON . stringify ( balances . value ) ) ;
587
582
} }
588
583
/>
589
-
590
584
< Button
591
585
title = { 'List channel monitors' }
592
586
onPress = { async ( ) : Promise < void > => {
@@ -604,6 +598,79 @@ const Dev = (): ReactElement => {
604
598
} }
605
599
/>
606
600
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
+
607
674
< Button
608
675
title = { 'Show version' }
609
676
onPress = { async ( ) : Promise < void > => {
@@ -615,7 +682,6 @@ const Dev = (): ReactElement => {
615
682
setMessage ( ldkVersion . value . ldk ) ;
616
683
} }
617
684
/>
618
-
619
685
< Button
620
686
title = { 'Show LDK logs' }
621
687
onPress = { async ( ) : Promise < void > => {
@@ -631,7 +697,6 @@ const Dev = (): ReactElement => {
631
697
}
632
698
} }
633
699
/>
634
-
635
700
< Button
636
701
title = { 'Restore backup from server' }
637
702
onPress = { async ( ) : Promise < void > => {
@@ -658,7 +723,6 @@ const Dev = (): ReactElement => {
658
723
setMessage ( 'Successfully restored wallet' ) ;
659
724
} }
660
725
/>
661
-
662
726
< Button
663
727
title = { 'Backup self check' }
664
728
onPress = { async ( ) : Promise < void > => {
@@ -671,7 +735,6 @@ const Dev = (): ReactElement => {
671
735
setMessage ( 'Backup server check passed ✅' ) ;
672
736
} }
673
737
/>
674
-
675
738
< Button
676
739
title = { 'Restart node' }
677
740
onPress = { async ( ) : Promise < void > => {
@@ -699,7 +762,6 @@ const Dev = (): ReactElement => {
699
762
setMessage ( res . value ) ;
700
763
} }
701
764
/>
702
-
703
765
< Button
704
766
title = { 'Node state' }
705
767
onPress = { async ( ) : Promise < void > => {
@@ -712,7 +774,6 @@ const Dev = (): ReactElement => {
712
774
setMessage ( res . value ) ;
713
775
} }
714
776
/>
715
-
716
777
< Button
717
778
title = { 'List backed up files' }
718
779
onPress = { async ( ) : Promise < void > => {
@@ -726,7 +787,6 @@ const Dev = (): ReactElement => {
726
787
setMessage ( JSON . stringify ( res . value ) ) ;
727
788
} }
728
789
/>
729
-
730
790
< Button
731
791
title = { 'Test file backup' }
732
792
onPress = { async ( ) : Promise < void > => {
0 commit comments