Initialize UserConfig in one statement
[ldk-sample] / src / cli.rs
index 5d778e8754975f085d10605c047c37abf4387596..603e6a9ad117e5ec5218143ec58a4a799f300b67 100644 (file)
@@ -13,8 +13,8 @@ use lightning::ln::msgs::NetAddress;
 use lightning::ln::{PaymentHash, PaymentSecret};
 use lightning::routing::network_graph::NetGraphMsgHandler;
 use lightning::routing::router;
-use lightning::routing::router::RouteHintHop;
-use lightning::util::config::UserConfig;
+use lightning::routing::router::RouteHint;
+use lightning::util::config::{ChannelConfig, ChannelHandshakeLimits, UserConfig};
 use lightning_invoice::{utils, Currency, Invoice};
 use std::env;
 use std::io;
@@ -227,11 +227,7 @@ pub(crate) async fn poll_for_user_input(
                                                        continue;
                                                }
                                        };
-                                       let mut route_hints = invoice.routes().clone();
-                                       let mut last_hops = Vec::new();
-                                       for hint in route_hints.drain(..) {
-                                               last_hops.push(hint[hint.len() - 1].clone());
-                                       }
+                                       let last_hops = invoice.route_hints();
 
                                        let amt_pico_btc = invoice.amount_pico_btc();
                                        if amt_pico_btc.is_none() {
@@ -517,15 +513,19 @@ pub(crate) async fn connect_peer_if_necessary(
 }
 
 fn open_channel(
-       peer_pubkey: PublicKey, channel_amt_sat: u64, announce_channel: bool,
+       peer_pubkey: PublicKey, channel_amt_sat: u64, announced_channel: bool,
        channel_manager: Arc<ChannelManager>,
 ) -> Result<(), ()> {
-       let mut config = UserConfig::default();
-       if announce_channel {
-               config.channel_options.announced_channel = true;
-       }
-       // lnd's max to_self_delay is 2016, so we want to be compatible.
-       config.peer_channel_config_limits.their_to_self_delay = 2016;
+       let config = UserConfig {
+               peer_channel_config_limits: ChannelHandshakeLimits {
+                       // lnd's max to_self_delay is 2016, so we want to be compatible.
+                       their_to_self_delay: 2016,
+                       ..Default::default()
+               },
+               channel_options: ChannelConfig { announced_channel, ..Default::default() },
+               ..Default::default()
+       };
+
        match channel_manager.create_channel(peer_pubkey, channel_amt_sat, 0, 0, Some(config)) {
                Ok(_) => {
                        println!("EVENT: initiated channel with peer {}. ", peer_pubkey);
@@ -541,7 +541,7 @@ fn open_channel(
 fn send_payment(
        payee: PublicKey, amt_msat: u64, final_cltv: u32, payment_hash: PaymentHash,
        payment_secret: Option<PaymentSecret>, payee_features: Option<InvoiceFeatures>,
-       route_hints: Vec<RouteHintHop>,
+       route_hints: Vec<&RouteHint>,
        router: Arc<NetGraphMsgHandler<Arc<dyn chain::Access + Send + Sync>, Arc<FilesystemLogger>>>,
        channel_manager: Arc<ChannelManager>, payment_storage: PaymentInfoStorage,
        logger: Arc<FilesystemLogger>,
@@ -556,7 +556,7 @@ fn send_payment(
                &payee,
                payee_features,
                Some(&first_hops.iter().collect::<Vec<_>>()),
-               &route_hints.iter().collect::<Vec<_>>(),
+               &route_hints,
                amt_msat,
                final_cltv,
                logger,