Add --public option to openchannel command help
[ldk-sample] / src / cli.rs
index b392f0f355019a9b42cae0230afdc7b92c76af33..013209f9d070ab8a1a33d78331afd0546880e165 100644 (file)
@@ -12,7 +12,7 @@ use lightning::chain::keysinterface::{KeysInterface, KeysManager, Recipient};
 use lightning::ln::msgs::NetAddress;
 use lightning::ln::{PaymentHash, PaymentPreimage};
 use lightning::routing::gossip::NodeId;
-use lightning::util::config::{ChannelConfig, ChannelHandshakeLimits, UserConfig};
+use lightning::util::config::{ChannelHandshakeConfig, ChannelHandshakeLimits, UserConfig};
 use lightning::util::events::EventHandler;
 use lightning_invoice::payment::PaymentError;
 use lightning_invoice::{utils, Currency, Invoice};
@@ -423,7 +423,7 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
 }
 
 fn help() {
-       println!("openchannel pubkey@host:port <amt_satoshis>");
+       println!("openchannel pubkey@host:port <amt_satoshis> [--public]");
        println!("sendpayment <invoice>");
        println!("keysend <dest_pubkey> <amt_msats>");
        println!("getinvoice <amt_msats> <expiry_secs>");
@@ -457,19 +457,6 @@ fn list_peers(peer_manager: Arc<PeerManager>) {
        println!("\t}},");
 }
 
-/// Takes some untrusted bytes and returns a sanitized string that is safe to print
-fn sanitize_string(bytes: &[u8]) -> String {
-       let mut ret = String::with_capacity(bytes.len());
-       // We should really support some sane subset of UTF-8 here, but limiting to printable ASCII
-       // instead makes this trivial.
-       for b in bytes {
-               if *b >= 0x20 && *b <= 0x7e {
-                       ret.push(*b as char);
-               }
-       }
-       ret
-}
-
 fn list_channels(channel_manager: &Arc<ChannelManager>, network_graph: &Arc<NetworkGraph>) {
        print!("[");
        for chan_info in channel_manager.list_channels() {
@@ -490,7 +477,7 @@ fn list_channels(channel_manager: &Arc<ChannelManager>, network_graph: &Arc<Netw
                        .get(&NodeId::from_pubkey(&chan_info.counterparty.node_id))
                {
                        if let Some(announcement) = &node_info.announcement_info {
-                               println!("\t\tpeer_alias: {}", sanitize_string(&announcement.alias));
+                               println!("\t\tpeer_alias: {}", announcement.alias);
                        }
                }
 
@@ -598,12 +585,15 @@ fn open_channel(
        channel_manager: Arc<ChannelManager>,
 ) -> Result<(), ()> {
        let config = UserConfig {
-               peer_channel_config_limits: ChannelHandshakeLimits {
+               channel_handshake_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() },
+               channel_handshake_config: ChannelHandshakeConfig {
+                       announced_channel,
+                       ..Default::default()
+               },
                ..Default::default()
        };
 
@@ -760,7 +750,7 @@ fn close_channel(
 fn force_close_channel(
        channel_id: [u8; 32], counterparty_node_id: PublicKey, channel_manager: Arc<ChannelManager>,
 ) {
-       match channel_manager.force_close_channel(&channel_id, &counterparty_node_id) {
+       match channel_manager.force_close_broadcasting_latest_txn(&channel_id, &counterparty_node_id) {
                Ok(()) => println!("EVENT: initiating channel force-close"),
                Err(e) => println!("ERROR: failed to force-close channel: {:?}", e),
        }