@@ -25,7 +25,12 @@ import lm, {
2525 TChannelUpdate ,
2626} from '@synonymdev/react-native-ldk' ;
2727import { 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' ;
2934import RNFS from 'react-native-fs' ;
3035
3136let 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 > => {
0 commit comments