@@ -361,7 +361,7 @@ async fn lnd_poller(helipad_config: HelipadConfig) {
361
361
//Make the connection to LND
362
362
println ! ( "\n Connecting to LND node address..." ) ;
363
363
let mut lightning;
364
- match lightning:: connect_to_lnd ( helipad_config. node_address , helipad_config. cert_path , helipad_config. macaroon_path ) . await {
364
+ match lightning:: connect_to_lnd ( & helipad_config. node_address , & helipad_config. cert_path , & helipad_config. macaroon_path ) . await {
365
365
Some ( lndconn) => {
366
366
println ! ( " - Success." ) ;
367
367
lightning = lndconn;
@@ -402,21 +402,33 @@ async fn lnd_poller(helipad_config: HelipadConfig) {
402
402
let mut updated = false ;
403
403
404
404
//Get lnd node channel balance
405
- match lnd:: Lnd :: channel_balance ( & mut lightning) . await {
406
- Ok ( balance) => {
407
- let mut current_balance: i64 = 0 ;
408
- if let Some ( bal) = balance. local_balance {
409
- println ! ( "LND node local balance: {:#?}" , bal. sat) ;
410
- current_balance = bal. sat as i64 ;
411
- }
405
+ let balance = lnd:: Lnd :: channel_balance ( & mut lightning) . await ;
406
+
407
+ if let Err ( status) = balance {
408
+ eprintln ! ( "Error getting LND wallet balance: {:#?}" , status) ;
412
409
413
- if dbif:: add_wallet_balance_to_db ( & db_filepath, current_balance) . is_err ( ) {
414
- println ! ( "Error adding wallet balance to the database." ) ;
410
+ if status. message ( ) == "transport error" {
411
+ // Attempt reconnect to LND
412
+ if let Some ( lndconn) = lightning:: connect_to_lnd ( & helipad_config. node_address , & helipad_config. cert_path , & helipad_config. macaroon_path ) . await {
413
+ println ! ( " - Reconnected." ) ;
414
+ lightning = lndconn;
415
415
}
416
416
}
417
- Err ( e) => {
418
- eprintln ! ( "Error getting LND wallet balance: {:#?}" , e) ;
419
- }
417
+
418
+ tokio:: time:: sleep ( tokio:: time:: Duration :: from_millis ( 9000 ) ) . await ;
419
+ continue ;
420
+ }
421
+
422
+ let balance = balance. unwrap ( ) ;
423
+ let mut current_balance: i64 = 0 ;
424
+
425
+ if let Some ( bal) = balance. local_balance {
426
+ println ! ( "LND node local balance: {:#?}" , bal. sat) ;
427
+ current_balance = bal. sat as i64 ;
428
+ }
429
+
430
+ if dbif:: add_wallet_balance_to_db ( & db_filepath, current_balance) . is_err ( ) {
431
+ println ! ( "Error adding wallet balance to the database." ) ;
420
432
}
421
433
422
434
//Get a list of invoices
0 commit comments