X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fcli.rs;h=9bc2ef1584d80acaea947d42c9223c63cc1f09a7;hb=68a95c0646810ed7afe5022ac211c1f214d950c5;hp=476ea81efd6803e393f237bd5965333767b00bc2;hpb=d10310b213f6c979e96d770963c4f5f8e9eb0212;p=ldk-sample diff --git a/src/cli.rs b/src/cli.rs index 476ea81..9bc2ef1 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -8,13 +8,14 @@ use bitcoin::hashes::Hash; use bitcoin::network::constants::Network; use bitcoin::secp256k1::key::PublicKey; use lightning::chain; -use lightning::chain::keysinterface::KeysManager; +use lightning::chain::keysinterface::{KeysInterface, KeysManager}; use lightning::ln::features::InvoiceFeatures; use lightning::ln::msgs::NetAddress; use lightning::ln::{PaymentHash, PaymentSecret}; use lightning::routing::network_graph::NetGraphMsgHandler; use lightning::routing::router; use lightning::routing::router::RouteHint; +use lightning::routing::scorer::Scorer; use lightning::util::config::{ChannelConfig, ChannelHandshakeLimits, UserConfig}; use lightning_invoice::{utils, Currency, Invoice}; use std::env; @@ -255,7 +256,7 @@ pub(crate) async fn poll_for_user_input( let payee_pubkey = invoice.recover_payee_pub_key(); let final_cltv = invoice.min_final_cltv_expiry() as u32; let payment_hash = PaymentHash(invoice.payment_hash().clone().into_inner()); - let payment_secret = invoice.payment_secret().cloned(); + let payment_secret = Some(invoice.payment_secret().clone()); let invoice_features = invoice.features().cloned(); send_payment( @@ -411,6 +412,24 @@ pub(crate) async fn poll_for_user_input( } "nodeinfo" => node_info(channel_manager.clone(), peer_manager.clone()), "listpeers" => list_peers(peer_manager.clone()), + "signmessage" => { + const MSG_STARTPOS: usize = "signmsg".len() + 1; + if line.as_bytes().len() <= MSG_STARTPOS { + println!("ERROR: signmsg requires a message"); + print!("> "); + io::stdout().flush().unwrap(); + continue; + } + println!( + "{:?}", + lightning::util::message_signing::sign( + &line.as_bytes()[MSG_STARTPOS..], + &keys_manager.get_node_secret() + ) + ); + print!("> "); + io::stdout().flush().unwrap(); + } _ => println!("Unknown command. See `\"help\" for available commands."), } } @@ -430,6 +449,7 @@ fn help() { println!("forceclosechannel "); println!("nodeinfo"); println!("listpeers"); + println!("signmessage "); } fn node_info(channel_manager: Arc, peer_manager: Arc) { @@ -594,7 +614,7 @@ fn send_payment( channel_manager: Arc, payment_storage: PaymentInfoStorage, logger: Arc, ) { - let network_graph = router.network_graph.read().unwrap(); + let network_graph = &router.network_graph; let first_hops = channel_manager.list_usable_channels(); let payer_pubkey = channel_manager.get_our_node_id(); @@ -608,6 +628,7 @@ fn send_payment( amt_msat, final_cltv, logger, + &Scorer::default(), ); if let Err(e) = route { println!("ERROR: failed to find route: {}", e.err); @@ -615,7 +636,7 @@ fn send_payment( } let status = match channel_manager.send_payment(&route.unwrap(), payment_hash, &payment_secret) { - Ok(()) => { + Ok(_payment_id) => { println!("EVENT: initiated sending {} msats to {}", amt_msat, payee); HTLCStatus::Pending } @@ -642,7 +663,7 @@ fn keysend( channel_manager: Arc, payment_storage: PaymentInfoStorage, logger: Arc, ) { - let network_graph = router.network_graph.read().unwrap(); + let network_graph = &router.network_graph; let first_hops = channel_manager.list_usable_channels(); let payer_pubkey = channel_manager.get_our_node_id(); @@ -655,6 +676,7 @@ fn keysend( amt_msat, 40, logger, + &Scorer::default(), ) { Ok(r) => r, Err(e) => { @@ -664,7 +686,7 @@ fn keysend( }; let mut payments = payment_storage.lock().unwrap(); - let payment_hash = channel_manager.send_spontaneous_payment(&route, None).unwrap(); + let payment_hash = channel_manager.send_spontaneous_payment(&route, None).unwrap().0; payments.insert( payment_hash, PaymentInfo { @@ -709,7 +731,7 @@ fn get_invoice( payment_hash, PaymentInfo { preimage: None, - secret: invoice.payment_secret().cloned(), + secret: Some(invoice.payment_secret().clone()), status: HTLCStatus::Pending, amt_msat: MillisatAmount(Some(amt_msat)), },