Add anchors flag to openchannel CLI command
authorWilmer Paulino <wilmer@wilmerpaulino.com>
Mon, 14 Aug 2023 16:03:00 +0000 (09:03 -0700)
committerWilmer Paulino <wilmer@wilmerpaulino.com>
Mon, 14 Aug 2023 16:07:37 +0000 (09:07 -0700)
src/cli.rs
src/main.rs

index 8e96fd8c26ac95a98ea04bcf07e8075754db7aaa..dab8bac9860b203a4c777637069babda8b44e581 100644 (file)
@@ -93,7 +93,7 @@ pub(crate) async fn poll_for_user_input(
                                        let peer_pubkey_and_ip_addr = words.next();
                                        let channel_value_sat = words.next();
                                        if peer_pubkey_and_ip_addr.is_none() || channel_value_sat.is_none() {
-                                               println!("ERROR: openchannel has 2 required arguments: `openchannel pubkey@host:port channel_amt_satoshis` [--public]");
+                                               println!("ERROR: openchannel has 2 required arguments: `openchannel pubkey@host:port channel_amt_satoshis` [--public] [--with-anchors]");
                                                continue;
                                        }
                                        let peer_pubkey_and_ip_addr = peer_pubkey_and_ip_addr.unwrap();
@@ -119,20 +119,25 @@ pub(crate) async fn poll_for_user_input(
                                                continue;
                                        };
 
-                                       let announce_channel = match words.next() {
-                                               Some("--public") | Some("--public=true") => true,
-                                               Some("--public=false") => false,
-                                               Some(_) => {
-                                                       println!("ERROR: invalid `--public` command format. Valid formats: `--public`, `--public=true` `--public=false`");
-                                                       continue;
+                                       let (mut announce_channel, mut with_anchors) = (false, false);
+                                       while let Some(word) = words.next() {
+                                               match word {
+                                                       "--public" | "--public=true" => announce_channel = true,
+                                                       "--public=false" => announce_channel = false,
+                                                       "--with-anchors" | "--with-anchors=true" => with_anchors = true,
+                                                       "--with-anchors=false" => with_anchors = false,
+                                                       _ => {
+                                                               println!("ERROR: invalid boolean flag format. Valid formats: `--option`, `--option=true` `--option=false`");
+                                                               continue;
+                                                       }
                                                }
-                                               None => false,
-                                       };
+                                       }
 
                                        if open_channel(
                                                pubkey,
                                                chan_amt_sat.unwrap(),
                                                announce_channel,
+                                               with_anchors,
                                                channel_manager.clone(),
                                        )
                                        .is_ok()
@@ -455,7 +460,7 @@ fn help() {
        println!("  help\tShows a list of commands.");
        println!("  quit\tClose the application.");
        println!("\n  Channels:");
-       println!("      openchannel pubkey@host:port <amt_satoshis> [--public]");
+       println!("      openchannel pubkey@host:port <amt_satoshis> [--public] [--with-anchors]");
        println!("      closechannel <channel_id> <peer_pubkey>");
        println!("      forceclosechannel <channel_id> <peer_pubkey>");
        println!("      listchannels");
@@ -638,7 +643,7 @@ fn do_disconnect_peer(
 }
 
 fn open_channel(
-       peer_pubkey: PublicKey, channel_amt_sat: u64, announced_channel: bool,
+       peer_pubkey: PublicKey, channel_amt_sat: u64, announced_channel: bool, with_anchors: bool,
        channel_manager: Arc<ChannelManager>,
 ) -> Result<(), ()> {
        let config = UserConfig {
@@ -649,6 +654,7 @@ fn open_channel(
                },
                channel_handshake_config: ChannelHandshakeConfig {
                        announced_channel,
+                       negotiate_anchors_zero_fee_htlc_tx: with_anchors,
                        ..Default::default()
                },
                ..Default::default()
index f1e1cbfedc300e563dba70e19007839af334d9ea..9fd11904f734d7cb80987d98f9970604dd64e4ee 100644 (file)
@@ -607,6 +607,7 @@ async fn start_ldk() {
        // Step 11: Initialize the ChannelManager
        let mut user_config = UserConfig::default();
        user_config.channel_handshake_limits.force_announced_channel_preference = false;
+       user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
        user_config.manually_accept_inbound_channels = true;
        let mut restarting_node = true;
        let (channel_manager_blockhash, channel_manager) = {