X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fcli.rs;h=7e122c39a2b6a402802b95a56fc2eb0a6ea59280;hb=c3ed7ce32015e718f87d2a018eabddfb5fa4599b;hp=f762fe5e5d8f1bc322cd69687b953c7ef3291703;hpb=4901136cfe2e50e66b3e999c1fbcec5e618ba4b5;p=ldk-sample diff --git a/src/cli.rs b/src/cli.rs index f762fe5..7e122c3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -13,7 +13,7 @@ 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::routing::router::RouteHint; use lightning::util::config::UserConfig; use lightning_invoice::{utils, Currency, Invoice}; use std::env; @@ -25,7 +25,6 @@ use std::path::Path; use std::str::FromStr; use std::sync::Arc; use std::time::Duration; -use tokio::sync::mpsc; pub(crate) struct LdkUserInfo { pub(crate) bitcoind_rpc_username: String, @@ -131,8 +130,7 @@ pub(crate) async fn poll_for_user_input( keys_manager: Arc, router: Arc, Arc>>, inbound_payments: PaymentInfoStorage, outbound_payments: PaymentInfoStorage, - event_notifier: mpsc::Sender<()>, ldk_data_dir: String, logger: Arc, - network: Network, + ldk_data_dir: String, logger: Arc, network: Network, ) { println!("LDK startup successful. To view available commands: \"help\"."); println!("LDK logs are available at /.ldk/logs"); @@ -141,7 +139,6 @@ pub(crate) async fn poll_for_user_input( print!("> "); io::stdout().flush().unwrap(); // Without flushing, the `>` doesn't print for line in stdin.lock().lines() { - let _ = event_notifier.try_send(()); let line = line.unwrap(); let mut words = line.split_whitespace(); if let Some(word) = words.next() { @@ -176,14 +173,9 @@ pub(crate) async fn poll_for_user_input( continue; } - if connect_peer_if_necessary( - pubkey, - peer_addr, - peer_manager.clone(), - event_notifier.clone(), - ) - .await - .is_err() + if connect_peer_if_necessary(pubkey, peer_addr, peer_manager.clone()) + .await + .is_err() { print!("> "); io::stdout().flush().unwrap(); @@ -235,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() { @@ -326,14 +314,9 @@ pub(crate) async fn poll_for_user_input( continue; } }; - if connect_peer_if_necessary( - pubkey, - peer_addr, - peer_manager.clone(), - event_notifier.clone(), - ) - .await - .is_ok() + if connect_peer_if_necessary(pubkey, peer_addr, peer_manager.clone()) + .await + .is_ok() { println!("SUCCESS: connected to peer {}", pubkey); } @@ -391,14 +374,16 @@ pub(crate) async fn poll_for_user_input( } fn help() { - println!("openchannel pubkey@host:port "); + println!("openchannel pubkey@host:port "); println!("sendpayment "); - println!("getinvoice "); + println!("getinvoice "); println!("connectpeer pubkey@host:port"); println!("listchannels"); println!("listpayments"); println!("closechannel "); println!("forceclosechannel "); + println!("nodeinfo"); + println!("listpeers"); } fn node_info(channel_manager: Arc, peer_manager: Arc) { @@ -424,20 +409,24 @@ fn list_channels(channel_manager: Arc) { println!(""); println!("\t{{"); println!("\t\tchannel_id: {},", hex_utils::hex_str(&chan_info.channel_id[..])); + if let Some(funding_txo) = chan_info.funding_txo { + println!("\t\tfunding_txid: {},", funding_txo.txid); + } println!( "\t\tpeer_pubkey: {},", hex_utils::hex_str(&chan_info.remote_network_id.serialize()) ); - let mut pending_channel = false; - match chan_info.short_channel_id { - Some(id) => println!("\t\tshort_channel_id: {},", id), - None => { - pending_channel = true; - } + if let Some(id) = chan_info.short_channel_id { + println!("\t\tshort_channel_id: {},", id); } - println!("\t\tpending_open: {},", pending_channel); + println!("\t\tis_confirmed_onchain: {},", chan_info.is_funding_locked); println!("\t\tchannel_value_satoshis: {},", chan_info.channel_value_satoshis); + if chan_info.is_usable { + println!("\t\tavailable_balance_for_send_msat: {},", chan_info.outbound_capacity_msat); + println!("\t\tavailable_balance_for_recv_msat: {},", chan_info.inbound_capacity_msat); + } println!("\t\tchannel_can_send_payments: {},", chan_info.is_usable); + println!("\t\tpublic: {},", chan_info.is_public); println!("\t}},"); } println!("]"); @@ -487,20 +476,13 @@ fn list_payments(inbound_payments: PaymentInfoStorage, outbound_payments: Paymen pub(crate) async fn connect_peer_if_necessary( pubkey: PublicKey, peer_addr: SocketAddr, peer_manager: Arc, - event_notifier: mpsc::Sender<()>, ) -> Result<(), ()> { for node_pubkey in peer_manager.get_peer_node_ids() { if node_pubkey == pubkey { return Ok(()); } } - match lightning_net_tokio::connect_outbound( - Arc::clone(&peer_manager), - event_notifier, - pubkey, - peer_addr, - ) - .await + match lightning_net_tokio::connect_outbound(Arc::clone(&peer_manager), pubkey, peer_addr).await { Some(conn_closed_fut) => { let mut closed_fut_box = Box::pin(conn_closed_fut); @@ -540,7 +522,7 @@ fn open_channel( } // lnd's max to_self_delay is 2016, so we want to be compatible. config.peer_channel_config_limits.their_to_self_delay = 2016; - match channel_manager.create_channel(peer_pubkey, channel_amt_sat, 0, 0, None) { + match channel_manager.create_channel(peer_pubkey, channel_amt_sat, 0, 0, Some(config)) { Ok(_) => { println!("EVENT: initiated channel with peer {}. ", peer_pubkey); return Ok(()); @@ -555,7 +537,7 @@ fn open_channel( fn send_payment( payee: PublicKey, amt_msat: u64, final_cltv: u32, payment_hash: PaymentHash, payment_secret: Option, payee_features: Option, - route_hints: Vec, + route_hints: Vec<&RouteHint>, router: Arc, Arc>>, channel_manager: Arc, payment_storage: PaymentInfoStorage, logger: Arc, @@ -570,7 +552,7 @@ fn send_payment( &payee, payee_features, Some(&first_hops.iter().collect::>()), - &route_hints.iter().collect::>(), + &route_hints, amt_msat, final_cltv, logger, @@ -669,8 +651,7 @@ pub(crate) fn parse_peer_info( if peer_addr_str.is_none() || peer_addr_str.is_none() { return Err(std::io::Error::new( std::io::ErrorKind::Other, - "ERROR: incorrectly formatted peer - info. Should be formatted as: `pubkey@host:port`", + "ERROR: incorrectly formatted peer info. Should be formatted as: `pubkey@host:port`", )); }