Skip to content

Commit e586047

Browse files
committed
Add anchors flag to openchannel CLI command
1 parent e846d07 commit e586047

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/cli.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub(crate) async fn poll_for_user_input(
9393
let peer_pubkey_and_ip_addr = words.next();
9494
let channel_value_sat = words.next();
9595
if peer_pubkey_and_ip_addr.is_none() || channel_value_sat.is_none() {
96-
println!("ERROR: openchannel has 2 required arguments: `openchannel pubkey@host:port channel_amt_satoshis` [--public]");
96+
println!("ERROR: openchannel has 2 required arguments: `openchannel pubkey@host:port channel_amt_satoshis` [--public] [--with-anchors]");
9797
continue;
9898
}
9999
let peer_pubkey_and_ip_addr = peer_pubkey_and_ip_addr.unwrap();
@@ -119,20 +119,25 @@ pub(crate) async fn poll_for_user_input(
119119
continue;
120120
};
121121

122-
let announce_channel = match words.next() {
123-
Some("--public") | Some("--public=true") => true,
124-
Some("--public=false") => false,
125-
Some(_) => {
126-
println!("ERROR: invalid `--public` command format. Valid formats: `--public`, `--public=true` `--public=false`");
127-
continue;
122+
let (mut announce_channel, mut with_anchors) = (false, false);
123+
while let Some(word) = words.next() {
124+
match word {
125+
"--public" | "--public=true" => announce_channel = true,
126+
"--public=false" => announce_channel = false,
127+
"--with-anchors" | "--with-anchors=true" => with_anchors = true,
128+
"--with-anchors=false" => with_anchors = false,
129+
_ => {
130+
println!("ERROR: invalid boolean flag format. Valid formats: `--option`, `--option=true` `--option=false`");
131+
continue;
132+
}
128133
}
129-
None => false,
130-
};
134+
}
131135

132136
if open_channel(
133137
pubkey,
134138
chan_amt_sat.unwrap(),
135139
announce_channel,
140+
with_anchors,
136141
channel_manager.clone(),
137142
)
138143
.is_ok()
@@ -455,7 +460,7 @@ fn help() {
455460
println!(" help\tShows a list of commands.");
456461
println!(" quit\tClose the application.");
457462
println!("\n Channels:");
458-
println!(" openchannel pubkey@host:port <amt_satoshis> [--public]");
463+
println!(" openchannel pubkey@host:port <amt_satoshis> [--public] [--with-anchors]");
459464
println!(" closechannel <channel_id> <peer_pubkey>");
460465
println!(" forceclosechannel <channel_id> <peer_pubkey>");
461466
println!(" listchannels");
@@ -638,7 +643,7 @@ fn do_disconnect_peer(
638643
}
639644

640645
fn open_channel(
641-
peer_pubkey: PublicKey, channel_amt_sat: u64, announced_channel: bool,
646+
peer_pubkey: PublicKey, channel_amt_sat: u64, announced_channel: bool, with_anchors: bool,
642647
channel_manager: Arc<ChannelManager>,
643648
) -> Result<(), ()> {
644649
let config = UserConfig {
@@ -649,6 +654,7 @@ fn open_channel(
649654
},
650655
channel_handshake_config: ChannelHandshakeConfig {
651656
announced_channel,
657+
negotiate_anchors_zero_fee_htlc_tx: with_anchors,
652658
..Default::default()
653659
},
654660
..Default::default()

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ async fn start_ldk() {
607607
// Step 11: Initialize the ChannelManager
608608
let mut user_config = UserConfig::default();
609609
user_config.channel_handshake_limits.force_announced_channel_preference = false;
610+
user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
610611
user_config.manually_accept_inbound_channels = true;
611612
let mut restarting_node = true;
612613
let (channel_manager_blockhash, channel_manager) = {

0 commit comments

Comments
 (0)