diff --git a/src/disk.rs b/src/disk.rs index e28c3179..26603770 100644 --- a/src/disk.rs +++ b/src/disk.rs @@ -13,6 +13,9 @@ use std::net::SocketAddr; use std::path::Path; use std::sync::Arc; +pub(crate) const INBOUND_PAYMENTS_FNAME: &str = "inbound_payments"; +pub(crate) const OUTBOUND_PAYMENTS_FNAME: &str = "outbound_payments"; + pub(crate) struct FilesystemLogger { data_dir: String, } @@ -55,14 +58,17 @@ pub(crate) fn persist_channel_peer(path: &Path, peer_info: &str) -> std::io::Res pub(crate) fn persist_inbound_payments( ldk_data_dir: String, inbound_payments: &PaymentInfoStorage, ) -> std::io::Result<()> { - persist_payment_info(Path::new(&format!("{}/inbound_payments", ldk_data_dir)), inbound_payments) + persist_payment_info( + Path::new(&format!("{}/{}", ldk_data_dir, INBOUND_PAYMENTS_FNAME)), + inbound_payments, + ) } pub(crate) fn persist_outbound_payments( ldk_data_dir: String, outbound_payments: &PaymentInfoStorage, ) -> std::io::Result<()> { persist_payment_info( - Path::new(&format!("{}/outbound_payments", ldk_data_dir)), + Path::new(&format!("{}/{}", ldk_data_dir, OUTBOUND_PAYMENTS_FNAME)), outbound_payments, ) } diff --git a/src/main.rs b/src/main.rs index 44720fb9..31498caf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ use bitcoin::consensus::encode; use bitcoin::network::constants::Network; use bitcoin::BlockHash; use bitcoin_bech32::WitnessProgram; +use disk::{INBOUND_PAYMENTS_FNAME, OUTBOUND_PAYMENTS_FNAME}; use lightning::chain::keysinterface::{ EntropySource, InMemorySigner, KeysManager, SpendableOutputDescriptor, }; @@ -114,10 +115,10 @@ pub(crate) struct PaymentInfo { } impl_writeable_tlv_based!(PaymentInfo, { - (0, preimage, option), - (1, secret, option), - (2, status, required), - (3, amt_msat, required), + (0, preimage, required), + (2, secret, required), + (4, status, required), + (6, amt_msat, required), }); pub(crate) struct PaymentInfoStorage { @@ -740,12 +741,12 @@ async fn start_ldk() { }); let inbound_payments = Arc::new(Mutex::new(disk::read_payment_info(Path::new(&format!( - "{}/inbound_payments", - ldk_data_dir + "{}/{}", + ldk_data_dir, INBOUND_PAYMENTS_FNAME ))))); let outbound_payments = Arc::new(Mutex::new(disk::read_payment_info(Path::new(&format!( - "{}/outbound_payments", - ldk_data_dir + "{}/{}", + ldk_data_dir, OUTBOUND_PAYMENTS_FNAME ))))); // Step 18: Handle LDK Events