Skip to content

Commit

Permalink
post-review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedberg committed May 22, 2023
1 parent 7814899 commit c8c446c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
10 changes: 8 additions & 2 deletions src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
)
}
Expand Down
17 changes: 9 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c8c446c

Please sign in to comment.