]> git.bitcoin.ninja Git - ldk-sample/commitdiff
working before async refactor
authorValentine Wallace <vwallace@protonmail.com>
Fri, 19 Mar 2021 22:37:28 +0000 (18:37 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Mon, 3 May 2021 22:30:30 +0000 (18:30 -0400)
src/cli.rs
src/main.rs

index 21c40236e18e9ec6f0793102e4888eae452cf319..ca1b84fed66fbe6f64f3cf4d63ddc141c0978ace 100644 (file)
@@ -160,10 +160,10 @@ pub(crate) fn poll_for_user_input(
 
                                        // let private_channel = match words.next().as_ref().map(String::as_str) {
                                        let announce_channel = match words.next() {
-                                               Some("--public") | Some("--public=true") | Some("--public true") => true,
-                                               Some("--public=false") | Some("--public false") => false,
+                                               Some("--public") | Some("--public=true") => true,
+                                               Some("--public=false") => false,
                                                Some(_) => {
-                                                       println!("ERROR: invalid `--public` command format");
+                                                       println!("ERROR: invalid `--public` command format. Valid formats: `--public`, `--public=true` `--public=false`");
                                                        print!("> ");
                                                        io::stdout().flush().unwrap();
                                                        continue;
index 0b45f0e6b71fa481c0d6fb4687a1d3c883380d89..529e170599d60cc2ac32d003d23a2011b7fac4ed 100644 (file)
@@ -484,7 +484,7 @@ fn main() {
                        SpvClient::new(chain_tip.unwrap(), chain_poller, &mut cache, &chain_listener);
                loop {
                        spv_client.poll_best_tip().await.unwrap();
-                       thread::sleep(Duration::new(1, 0));
+                       tokio::time::sleep(Duration::from_secs(1)).await;
                }
        });
 
@@ -501,11 +501,9 @@ fn main() {
        );
 
        let peer_manager_processor = peer_manager.clone();
-       runtime_handle.spawn(async move {
-               loop {
-                       peer_manager_processor.timer_tick_occurred();
-                       thread::sleep(Duration::new(60, 0));
-               }
+       thread::spawn(move || loop {
+               peer_manager_processor.timer_tick_occurred();
+               thread::sleep(Duration::new(60, 0));
        });
 
        // Step 15: Initialize LDK Event Handling
@@ -515,7 +513,6 @@ fn main() {
        let keys_manager_listener = keys_manager.clone();
        let payment_info: PaymentInfoStorage = Arc::new(Mutex::new(HashMap::new()));
        let payment_info_for_events = payment_info.clone();
-       let handle = runtime_handle.clone();
        let network = args.network;
        thread::spawn(move || {
                handle_ldk_events(
@@ -530,17 +527,22 @@ fn main() {
        });
 
        // Reconnect to channel peers if possible.
+       let handle = runtime_handle.clone();
        let peer_data_path = format!("{}/channel_peer_data", ldk_data_dir.clone());
        match disk::read_channel_peer_data(Path::new(&peer_data_path)) {
                Ok(mut info) => {
                        for (pubkey, peer_addr) in info.drain() {
-                               let _ = cli::connect_peer_if_necessary(
-                                       pubkey,
-                                       peer_addr,
-                                       peer_manager.clone(),
-                                       event_ntfn_sender.clone(),
-                                       handle.clone(),
-                               );
+                               for chan_info in channel_manager.list_channels() {
+                                       if pubkey == chan_info.remote_network_id {
+                                               let _ = cli::connect_peer_if_necessary(
+                                                       pubkey,
+                                                       peer_addr,
+                                                       peer_manager.clone(),
+                                                       event_ntfn_sender.clone(),
+                                                       handle.clone(),
+                                               );
+                                       }
+                               }
                        }
                }
                Err(e) => println!("ERROR: errored reading channel peer info from disk: {:?}", e),