From: Matt Corallo Date: Sat, 30 Sep 2023 00:53:06 +0000 (+0000) Subject: Rename `persister` in `handle_ldk_events` to differentiate store X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=f5d699d8640f7fbc0fad5c415d0831f265d5c1e4;p=ldk-sample Rename `persister` in `handle_ldk_events` to differentiate store Since we now have a `Persist`er which is separate from our `FilesystemStore`, its useful to use different names to differentiate the two. --- diff --git a/src/cli.rs b/src/cli.rs index 9cb0f17..66af9ee 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -65,7 +65,7 @@ pub(crate) fn poll_for_user_input( keys_manager: Arc, network_graph: Arc, onion_messenger: Arc, inbound_payments: Arc>, outbound_payments: Arc>, ldk_data_dir: String, network: Network, - logger: Arc, persister: Arc, + logger: Arc, fs_store: Arc, ) { println!( "LDK startup successful. Enter \"help\" to view available commands. Press Ctrl-D to quit." @@ -172,7 +172,7 @@ pub(crate) fn poll_for_user_input( &channel_manager, &invoice, &mut outbound_payments.lock().unwrap(), - persister.clone(), + Arc::clone(&fs_store), ); } "keysend" => { @@ -209,7 +209,7 @@ pub(crate) fn poll_for_user_input( amt_msat, &*keys_manager, &mut outbound_payments.lock().unwrap(), - persister.clone(), + Arc::clone(&fs_store), ); } "getinvoice" => { @@ -247,7 +247,7 @@ pub(crate) fn poll_for_user_input( expiry_secs.unwrap(), Arc::clone(&logger), ); - persister + fs_store .write("", "", INBOUND_PAYMENTS_FNAME, &inbound_payments.encode()) .unwrap(); } @@ -684,7 +684,7 @@ fn open_channel( fn send_payment( channel_manager: &ChannelManager, invoice: &Bolt11Invoice, - outbound_payments: &mut PaymentInfoStorage, persister: Arc, + outbound_payments: &mut PaymentInfoStorage, fs_store: Arc, ) { let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner()); let payment_secret = Some(*invoice.payment_secret()); @@ -697,7 +697,7 @@ fn send_payment( amt_msat: MillisatAmount(invoice.amount_milli_satoshis()), }, ); - persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap(); + fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap(); match pay_invoice(invoice, Retry::Timeout(Duration::from_secs(10)), channel_manager) { Ok(_payment_id) => { let payee_pubkey = invoice.recover_payee_pub_key(); @@ -709,14 +709,14 @@ fn send_payment( println!("ERROR: failed to send payment: {:?}", e); print!("> "); outbound_payments.payments.get_mut(&payment_hash).unwrap().status = HTLCStatus::Failed; - persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap(); + fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap(); } }; } fn keysend( channel_manager: &ChannelManager, payee_pubkey: PublicKey, amt_msat: u64, entropy_source: &E, - outbound_payments: &mut PaymentInfoStorage, persister: Arc, + outbound_payments: &mut PaymentInfoStorage, fs_store: Arc, ) { let payment_preimage = PaymentPreimage(entropy_source.get_secure_random_bytes()); let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()); @@ -734,7 +734,7 @@ fn keysend( amt_msat: MillisatAmount(Some(amt_msat)), }, ); - persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap(); + fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap(); match channel_manager.send_spontaneous_payment_with_retry( Some(payment_preimage), RecipientOnionFields::spontaneous_empty(), @@ -750,7 +750,7 @@ fn keysend( println!("ERROR: failed to send payment: {:?}", e); print!("> "); outbound_payments.payments.get_mut(&payment_hash).unwrap().status = HTLCStatus::Failed; - persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap(); + fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap(); } }; } diff --git a/src/main.rs b/src/main.rs index 0e0dd34..97524e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -160,7 +160,7 @@ async fn handle_ldk_events( channel_manager: &Arc, bitcoind_client: &BitcoindClient, network_graph: &NetworkGraph, keys_manager: &KeysManager, bump_tx_event_handler: &BumpTxEventHandler, inbound_payments: Arc>, - outbound_payments: Arc>, persister: &Arc, + outbound_payments: Arc>, fs_store: &Arc, network: Network, event: Event, ) { match event { @@ -272,7 +272,7 @@ async fn handle_ldk_events( }); } } - persister.write("", "", INBOUND_PAYMENTS_FNAME, &inbound.encode()).unwrap(); + fs_store.write("", "", INBOUND_PAYMENTS_FNAME, &inbound.encode()).unwrap(); } Event::PaymentSent { payment_preimage, payment_hash, fee_paid_msat, .. } => { let mut outbound = outbound_payments.lock().unwrap(); @@ -296,7 +296,7 @@ async fn handle_ldk_events( io::stdout().flush().unwrap(); } } - persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap(); + fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap(); } Event::OpenChannelRequest { ref temporary_channel_id, ref counterparty_node_id, .. @@ -345,7 +345,7 @@ async fn handle_ldk_events( let payment = outbound.payments.get_mut(&payment_hash).unwrap(); payment.status = HTLCStatus::Failed; } - persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap(); + fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap(); } Event::PaymentForwarded { prev_channel_id, @@ -433,7 +433,7 @@ async fn handle_ldk_events( let key = hex_utils::hex_str(&keys_manager.get_secure_random_bytes()); // Note that if the type here changes our read code needs to change as well. let output: SpendableOutputDescriptor = output; - persister.write(PENDING_SPENDABLE_OUTPUT_DIR, "", &key, &output.encode()).unwrap(); + fs_store.write(PENDING_SPENDABLE_OUTPUT_DIR, "", &key, &output.encode()).unwrap(); } } Event::ChannelPending { channel_id, counterparty_node_id, .. } => {