@@ -24,28 +24,17 @@ async function createOrUnlockWallet(node) {
2424 }
2525}
2626
27- async function coinsAndChannels ( node ) {
28- try {
29- const coins_success = await coins ( node ) ;
30- if ( coins_success ) {
31- await channels ( node ) ;
32- }
33- } catch ( e ) {
34- console . log ( "=> err" , e ) ;
35- }
36- }
37-
3827async function coins ( node ) {
3928 try {
4029 const balres = await lightning . getBalance ( node ) ;
4130 const confirmed = parseInt ( balres . confirmed_balance ) ;
42- console . log ( " => ALICE confirmed balance:" , confirmed ) ;
31+ console . log ( ` => ${ node . alias } confirmed balance:` , confirmed ) ;
4332 if ( ! confirmed ) {
4433 const ares = await lightning . newAddress ( node ) ;
4534 const addy = ares . address ;
46- console . log ( " => ALICE address" , addy ) ;
35+ console . log ( ` => ${ node . alias } address` , addy ) ;
4736 await bitcoind . mine ( 101 , addy ) ;
48- console . log ( " => 101 blocks mined to alice!" , addy ) ;
37+ console . log ( ` => 101 blocks mined to ${ node . alias } !` ) ;
4938 await sleep ( 5000 ) ;
5039 }
5140 return true ;
@@ -73,8 +62,10 @@ async function channels(node) {
7362 await bitcoind . mine ( 6 , "bcrt1qsrq4qj4zgwyj8hpsnpgeeh0p0aqfe5vqhv7yrr" ) ;
7463 console . log ( "=> 6 blocked mined to Alice!" ) ;
7564 await sleep ( 20000 )
76- if ( ! channels . length ) {
77- console . log ( "=> alice opening channels..." ) ;
65+ if ( channels . length ) {
66+ console . log ( `=> ${ node . alias } already has open channels` ) ;
67+ } else {
68+ console . log ( `=> ${ node . alias } opening ${ peersToMake . length } channels...` ) ;
7869 // open channels here
7970 await asyncForEach ( peersToMake , async ( p ) => {
8071 await lightning . openChannel ( node , {
@@ -83,25 +74,39 @@ async function channels(node) {
8374 push_amount : 1000000 ,
8475 } ) ;
8576 } ) ;
86- await bitcoind . mine ( 6 , "bcrt1qsrq4qj4zgwyj8hpsnpgeeh0p0aqfe5vqhv7yrr" ) ;
87- console . log ( "=> 6 blocked mined to Alice!" ) ;
8877 }
8978 await sleep ( 4000 ) ;
90- const chans2 = await lightning . listChannels ( node ) ;
91- console . log ( "FINAL CHANS" , chans2 . channels ) ;
79+ } catch ( e ) {
80+ console . log ( "=> err:" , e ) ;
81+ }
82+ }
83+
84+ async function logChannels ( node ) {
85+ try {
86+ const chans = await lightning . listChannels ( node ) ;
87+ console . log ( `${ node . alias } channels:` , chans . channels ) ;
9288 } catch ( e ) {
9389 console . log ( "=> err:" , e ) ;
9490 }
9591}
9692
9793async function unlockAll ( ) {
9894 await sleep ( 3500 ) ;
99- // createOrUnlockWallet(nodes.nodes.alice);
100- await asyncForEach ( Object . values ( nodes . nodes ) , async ( node ) => {
101- await createOrUnlockWallet ( node ) ;
102- } ) ;
95+
96+ await forEachNode ( createOrUnlockWallet ) ;
97+
10398 await sleep ( 5000 ) ;
104- await coinsAndChannels ( nodes . nodes . alice ) ;
99+
100+ await forEachNode ( coins ) ;
101+
102+ await forEachNode ( channels ) ;
103+
104+ await bitcoind . mine ( 6 , "bcrt1qsrq4qj4zgwyj8hpsnpgeeh0p0aqfe5vqhv7yrr" ) ;
105+ console . log ( "=> mined 6 blocks to confirm channels" ) ;
106+
107+ await sleep ( 2500 ) ;
108+
109+ await forEachNode ( logChannels ) ;
105110}
106111
107112unlockAll ( ) ;
@@ -110,6 +115,10 @@ async function sleep(ms) {
110115 return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
111116}
112117
118+ async function forEachNode ( callback ) {
119+ await asyncForEach ( Object . values ( nodes . nodes ) , callback ) ;
120+ }
121+
113122async function asyncForEach ( array , callback ) {
114123 for ( let index = 0 ; index < array . length ; index ++ ) {
115124 await callback ( array [ index ] , index , array ) ;
0 commit comments