X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fdisk.rs;h=77cefd6d59a91bc25f26c855d9119235c62df78c;hb=bd7121e4cacd1f8e1b47bb3fe2d184ebda623ab0;hp=0c3085134bedcd8cf35ca57330a776ad196223a9;hpb=6621d7965d85861f958571f5cb29f6946c57aa57;p=ldk-sample diff --git a/src/disk.rs b/src/disk.rs index 0c30851..77cefd6 100644 --- a/src/disk.rs +++ b/src/disk.rs @@ -1,10 +1,10 @@ -use crate::{cli, NetworkGraph}; +use crate::{cli, NetworkGraph, PaymentInfoStorage}; use bitcoin::secp256k1::PublicKey; use bitcoin::Network; use chrono::Utc; use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters}; use lightning::util::logger::{Logger, Record}; -use lightning::util::ser::{ReadableArgs, Writer}; +use lightning::util::ser::{Readable, ReadableArgs, Writer}; use std::collections::HashMap; use std::fs; use std::fs::File; @@ -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, } @@ -83,6 +86,15 @@ pub(crate) fn read_network( NetworkGraph::new(network, logger) } +pub(crate) fn read_payment_info(path: &Path) -> PaymentInfoStorage { + if let Ok(file) = File::open(path) { + if let Ok(info) = PaymentInfoStorage::read(&mut BufReader::new(file)) { + return info; + } + } + PaymentInfoStorage { payments: HashMap::new() } +} + pub(crate) fn read_scorer( path: &Path, graph: Arc, logger: Arc, ) -> ProbabilisticScorer, Arc> {