From: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com> Date: Mon, 14 Aug 2023 18:47:11 +0000 (+0000) Subject: Merge pull request #116 from wpaulino/anchors X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=0be8a1b35092b7ff8f1ac0a2efb8708e5a18a80c;hp=-c;p=ldk-sample Merge pull request #116 from wpaulino/anchors Add support for opening anchor outputs channels --- 0be8a1b35092b7ff8f1ac0a2efb8708e5a18a80c diff --combined src/cli.rs index a53a020,dab8bac..10dce92 --- a/src/cli.rs +++ b/src/cli.rs @@@ -93,7 -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 +119,25 @@@ 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() @@@ -368,14 -373,14 +373,14 @@@ "listpeers" => list_peers(peer_manager.clone()), "signmessage" => { const MSG_STARTPOS: usize = "signmessage".len() + 1; - if line.as_bytes().len() <= MSG_STARTPOS { + if line.trim().as_bytes().len() <= MSG_STARTPOS { println!("ERROR: signmsg requires a message"); continue; } println!( "{:?}", lightning::util::message_signing::sign( - &line.as_bytes()[MSG_STARTPOS..], + &line.trim().as_bytes()[MSG_STARTPOS..], &keys_manager.get_node_secret_key() ) ); @@@ -455,7 -460,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 [--public]"); + println!(" openchannel pubkey@host:port [--public] [--with-anchors]"); println!(" closechannel "); println!(" forceclosechannel "); println!(" listchannels"); @@@ -638,7 -643,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, ) -> Result<(), ()> { let config = UserConfig { @@@ -649,6 -654,7 +654,7 @@@ }, channel_handshake_config: ChannelHandshakeConfig { announced_channel, + negotiate_anchors_zero_fee_htlc_tx: with_anchors, ..Default::default() }, ..Default::default()