X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain.rs;h=57f0bb2ea7f9017c42feb5b6ef7b9b8818bbda7d;hb=d3112a612f8f830520ad01e533e3aac3a701c55e;hp=4073be9ea73faa4395955d00b8f1693f3a002405;hpb=90c12f0f24689326ae09637a9ad620f781d97e5c;p=ldk-sample diff --git a/src/main.rs b/src/main.rs index 4073be9..57f0bb2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ use lightning::ln::peer_handler::{MessageHandler, SimpleArcPeerManager}; use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret}; use lightning::routing::network_graph::NetGraphMsgHandler; use lightning::util::config::UserConfig; -use lightning::util::events::Event; +use lightning::util::events::{Event, PaymentPurpose}; use lightning::util::ser::ReadableArgs; use lightning_background_processor::BackgroundProcessor; use lightning_block_sync::init; @@ -148,8 +148,14 @@ async fn handle_ldk_events( io::stdout().flush().unwrap(); } } - Event::PaymentReceived { payment_hash, payment_preimage, payment_secret, amt, .. } => { + Event::PaymentReceived { payment_hash, purpose, amt, .. } => { let mut payments = inbound_payments.lock().unwrap(); + let (payment_preimage, payment_secret) = match purpose { + PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => { + (payment_preimage, Some(payment_secret)) + } + PaymentPurpose::SpontaneousPayment(preimage) => (Some(preimage), None), + }; let status = match channel_manager.claim_funds(payment_preimage.unwrap()) { true => { println!( @@ -167,13 +173,13 @@ async fn handle_ldk_events( Entry::Occupied(mut e) => { let payment = e.get_mut(); payment.status = status; - payment.preimage = Some(payment_preimage.unwrap()); - payment.secret = Some(payment_secret); + payment.preimage = payment_preimage; + payment.secret = payment_secret; } Entry::Vacant(e) => { e.insert(PaymentInfo { - preimage: Some(payment_preimage.unwrap()), - secret: Some(payment_secret), + preimage: payment_preimage, + secret: payment_secret, status, amt_msat: MillisatAmount(Some(amt)), }); @@ -347,7 +353,8 @@ async fn start_ldk() { let mut channelmonitors = persister.read_channelmonitors(keys_manager.clone()).unwrap(); // Step 8: Initialize the ChannelManager - let user_config = UserConfig::default(); + let mut user_config = UserConfig::default(); + user_config.peer_channel_config_limits.force_announced_channel_preference = false; let mut restarting_node = true; let (channel_manager_blockhash, mut channel_manager) = { if let Ok(mut f) = fs::File::open(format!("{}/manager", ldk_data_dir.clone())) { @@ -544,7 +551,7 @@ async fn start_ldk() { let persist_channel_manager_callback = move |node: &ChannelManager| FilesystemPersister::persist_manager(data_dir.clone(), &*node); // Step 17: Background Processing - BackgroundProcessor::start( + let background_processor = BackgroundProcessor::start( persist_channel_manager_callback, event_handler, chain_monitor.clone(), @@ -603,6 +610,9 @@ async fn start_ldk() { network, ) .await; + + // Stop the background processor. + background_processor.stop().unwrap(); } #[tokio::main]