Merge pull request #131 from tnull/2024-02-align-rustfmt
[ldk-sample] / src / cli.rs
index b9fbf77bb7314b7e19e2d6b6c0177f31c868b944..fe1b286d7b4d7abaf424495a98dccd522bb56daf 100644 (file)
@@ -106,7 +106,7 @@ pub(crate) fn poll_for_user_input(
                                                        Err(e) => {
                                                                println!("{:?}", e.into_inner().unwrap());
                                                                continue;
-                                                       }
+                                                       },
                                                };
 
                                        let chan_amt_sat: Result<u64, _> = channel_value_sat.unwrap().parse();
@@ -136,7 +136,7 @@ pub(crate) fn poll_for_user_input(
                                                        _ => {
                                                                println!("ERROR: invalid boolean flag format. Valid formats: `--option`, `--option=true` `--option=false`");
                                                                continue;
-                                                       }
+                                                       },
                                                }
                                        }
 
@@ -155,7 +155,7 @@ pub(crate) fn poll_for_user_input(
                                                        peer_pubkey_and_ip_addr,
                                                );
                                        }
-                               }
+                               },
                                "sendpayment" => {
                                        let invoice_str = words.next();
                                        if invoice_str.is_none() {
@@ -170,7 +170,7 @@ pub(crate) fn poll_for_user_input(
                                                        Err(e) => {
                                                                println!("ERROR: couldn't parse amount_msat: {}", e);
                                                                continue;
-                                                       }
+                                                       },
                                                };
                                        }
 
@@ -184,7 +184,7 @@ pub(crate) fn poll_for_user_input(
                                                        (amt, _) => {
                                                                println!("ERROR: Cannot process non-Bitcoin-denominated offer value {:?}", amt);
                                                                continue;
-                                                       }
+                                                       },
                                                };
                                                if user_provided_amt.is_some() && user_provided_amt != Some(amt_msat) {
                                                        println!("Amount didn't match offer of {}msat", amt_msat);
@@ -244,10 +244,10 @@ pub(crate) fn poll_for_user_input(
                                                        ),
                                                        Err(e) => {
                                                                println!("ERROR: invalid invoice: {:?}", e);
-                                                       }
+                                                       },
                                                }
                                        }
-                               }
+                               },
                                "keysend" => {
                                        let dest_pubkey = match words.next() {
                                                Some(dest) => match hex_utils::to_compressed_pubkey(dest) {
@@ -255,26 +255,26 @@ pub(crate) fn poll_for_user_input(
                                                        None => {
                                                                println!("ERROR: couldn't parse destination pubkey");
                                                                continue;
-                                                       }
+                                                       },
                                                },
                                                None => {
                                                        println!("ERROR: keysend requires a destination pubkey: `keysend <dest_pubkey> <amt_msat>`");
                                                        continue;
-                                               }
+                                               },
                                        };
                                        let amt_msat_str = match words.next() {
                                                Some(amt) => amt,
                                                None => {
                                                        println!("ERROR: keysend requires an amount in millisatoshis: `keysend <dest_pubkey> <amt_msat>`");
                                                        continue;
-                                               }
+                                               },
                                        };
                                        let amt_msat: u64 = match amt_msat_str.parse() {
                                                Ok(amt) => amt,
                                                Err(e) => {
                                                        println!("ERROR: couldn't parse amount_msat: {}", e);
                                                        continue;
-                                               }
+                                               },
                                        };
                                        keysend(
                                                &channel_manager,
@@ -284,7 +284,7 @@ pub(crate) fn poll_for_user_input(
                                                &mut outbound_payments.lock().unwrap(),
                                                Arc::clone(&fs_store),
                                        );
-                               }
+                               },
                                "getoffer" => {
                                        let offer_builder = channel_manager.create_offer_builder(String::new());
                                        if let Err(e) = offer_builder {
@@ -312,7 +312,7 @@ pub(crate) fn poll_for_user_input(
                                                // correspond with individual payments.
                                                println!("{}", offer.unwrap());
                                        }
-                               }
+                               },
                                "getinvoice" => {
                                        let amt_str = words.next();
                                        if amt_str.is_none() {
@@ -351,7 +351,7 @@ pub(crate) fn poll_for_user_input(
                                        fs_store
                                                .write("", "", INBOUND_PAYMENTS_FNAME, &inbound_payments.encode())
                                                .unwrap();
-                               }
+                               },
                                "connectpeer" => {
                                        let peer_pubkey_and_ip_addr = words.next();
                                        if peer_pubkey_and_ip_addr.is_none() {
@@ -364,7 +364,7 @@ pub(crate) fn poll_for_user_input(
                                                        Err(e) => {
                                                                println!("{:?}", e.into_inner().unwrap());
                                                                continue;
-                                                       }
+                                                       },
                                                };
                                        if tokio::runtime::Handle::current()
                                                .block_on(connect_peer_if_necessary(
@@ -376,7 +376,7 @@ pub(crate) fn poll_for_user_input(
                                        {
                                                println!("SUCCESS: connected to peer {}", pubkey);
                                        }
-                               }
+                               },
                                "disconnectpeer" => {
                                        let peer_pubkey = words.next();
                                        if peer_pubkey.is_none() {
@@ -390,7 +390,7 @@ pub(crate) fn poll_for_user_input(
                                                        Err(e) => {
                                                                println!("ERROR: {}", e.to_string());
                                                                continue;
-                                                       }
+                                                       },
                                                };
 
                                        if do_disconnect_peer(
@@ -402,7 +402,7 @@ pub(crate) fn poll_for_user_input(
                                        {
                                                println!("SUCCESS: disconnected from peer {}", peer_pubkey);
                                        }
-                               }
+                               },
                                "listchannels" => list_channels(&channel_manager, &network_graph),
                                "listpayments" => list_payments(
                                        &inbound_payments.lock().unwrap(),
@@ -432,18 +432,18 @@ pub(crate) fn poll_for_user_input(
                                                None => {
                                                        println!("ERROR: couldn't parse peer_pubkey");
                                                        continue;
-                                               }
+                                               },
                                        };
                                        let peer_pubkey = match PublicKey::from_slice(&peer_pubkey_vec) {
                                                Ok(peer_pubkey) => peer_pubkey,
                                                Err(_) => {
                                                        println!("ERROR: couldn't parse peer_pubkey");
                                                        continue;
-                                               }
+                                               },
                                        };
 
                                        close_channel(channel_id, peer_pubkey, channel_manager.clone());
-                               }
+                               },
                                "forceclosechannel" => {
                                        let channel_id_str = words.next();
                                        if channel_id_str.is_none() {
@@ -468,18 +468,18 @@ pub(crate) fn poll_for_user_input(
                                                None => {
                                                        println!("ERROR: couldn't parse peer_pubkey");
                                                        continue;
-                                               }
+                                               },
                                        };
                                        let peer_pubkey = match PublicKey::from_slice(&peer_pubkey_vec) {
                                                Ok(peer_pubkey) => peer_pubkey,
                                                Err(_) => {
                                                        println!("ERROR: couldn't parse peer_pubkey");
                                                        continue;
-                                               }
+                                               },
                                        };
 
                                        force_close_channel(channel_id, peer_pubkey, channel_manager.clone());
-                               }
+                               },
                                "nodeinfo" => node_info(&channel_manager, &peer_manager),
                                "listpeers" => list_peers(peer_manager.clone()),
                                "signmessage" => {
@@ -495,7 +495,7 @@ pub(crate) fn poll_for_user_input(
                                                        &keys_manager.get_node_secret_key()
                                                )
                                        );
-                               }
+                               },
                                "sendonionmessage" => {
                                        let path_pks_str = words.next();
                                        if path_pks_str.is_none() {
@@ -513,7 +513,7 @@ pub(crate) fn poll_for_user_input(
                                                                println!("ERROR: couldn't parse peer_pubkey");
                                                                errored = true;
                                                                break;
-                                                       }
+                                                       },
                                                };
                                                let node_pubkey = match PublicKey::from_slice(&node_pubkey_vec) {
                                                        Ok(peer_pubkey) => peer_pubkey,
@@ -521,7 +521,7 @@ pub(crate) fn poll_for_user_input(
                                                                println!("ERROR: couldn't parse peer_pubkey");
                                                                errored = true;
                                                                break;
-                                                       }
+                                                       },
                                                };
                                                intermediate_nodes.push(node_pubkey);
                                        }
@@ -533,14 +533,14 @@ pub(crate) fn poll_for_user_input(
                                                _ => {
                                                        println!("Need an integral message type above 64");
                                                        continue;
-                                               }
+                                               },
                                        };
                                        let data = match words.next().map(|s| hex_utils::to_vec(s)) {
                                                Some(Some(data)) => data,
                                                _ => {
                                                        println!("Need a hex data string");
                                                        continue;
-                                               }
+                                               },
                                        };
                                        let destination = Destination::Node(intermediate_nodes.pop().unwrap());
                                        match onion_messenger.send_onion_message(
@@ -550,10 +550,10 @@ pub(crate) fn poll_for_user_input(
                                        ) {
                                                Ok(success) => {
                                                        println!("SUCCESS: forwarded onion message to first hop {:?}", success)
-                                               }
+                                               },
                                                Err(e) => println!("ERROR: failed to send onion message: {:?}", e),
                                        }
-                               }
+                               },
                                "quit" | "exit" => break,
                                _ => println!("Unknown command. See `\"help\" for available commands."),
                        }
@@ -729,7 +729,7 @@ pub(crate) async fn do_connect_peer(
                                        return Ok(());
                                }
                        }
-               }
+               },
                None => Err(()),
        }
 }
@@ -779,11 +779,11 @@ fn open_channel(
                Ok(_) => {
                        println!("EVENT: initiated channel with peer {}. ", peer_pubkey);
                        return Ok(());
-               }
+               },
                Err(e) => {
                        println!("ERROR: failed to open channel: {:?}", e);
                        return Err(());
-               }
+               },
        }
 }
 
@@ -818,10 +818,10 @@ fn send_payment(
        let (payment_hash, recipient_onion, route_params) = match pay_params_opt {
                Ok(res) => res,
                Err(e) => {
-                       println!("Failed to parse invoice");
+                       println!("Failed to parse invoice: {:?}", e);
                        print!("> ");
                        return;
-               }
+               },
        };
        outbound_payments.payments.insert(
                payment_id,
@@ -846,13 +846,13 @@ fn send_payment(
                        let amt_msat = invoice.amount_milli_satoshis().unwrap();
                        println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
                        print!("> ");
-               }
+               },
                Err(e) => {
                        println!("ERROR: failed to send payment: {:?}", e);
                        print!("> ");
                        outbound_payments.payments.get_mut(&payment_id).unwrap().status = HTLCStatus::Failed;
                        fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
-               }
+               },
        };
 }
 
@@ -887,13 +887,13 @@ fn keysend<E: EntropySource>(
                Ok(_payment_hash) => {
                        println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
                        print!("> ");
-               }
+               },
                Err(e) => {
                        println!("ERROR: failed to send payment: {:?}", e);
                        print!("> ");
                        outbound_payments.payments.get_mut(&payment_id).unwrap().status = HTLCStatus::Failed;
                        fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
-               }
+               },
        };
 }
 
@@ -921,11 +921,11 @@ fn get_invoice(
                Ok(inv) => {
                        println!("SUCCESS: generated invoice: {}", inv);
                        inv
-               }
+               },
                Err(e) => {
                        println!("ERROR: failed to create invoice: {:?}", e);
                        return;
-               }
+               },
        };
 
        let payment_hash = PaymentHash(invoice.payment_hash().to_byte_array());