Files
breez-sdk-liquid/lib/core/src/persist/backup.rs
ok300 e5dba1043e Add ability to parse an invoice (#240)
* Add ability to parse an invoice

* Simplify LNInvoice initialization

* Add missing LNInvoice fields

* Cargo fmt

* Re-generate bindings after merging main branch

* Explicitly check the invoice signature

* Remove redundant signature check

* Strip potential lightning: prefix before parsing bolt11
2024-05-30 13:26:00 +00:00

35 lines
988 B
Rust

use anyhow::Result;
use rusqlite::{backup::Backup, Connection};
use std::path::{Path, PathBuf};
use super::Persister;
use crate::model::Network;
impl Persister {
pub(crate) fn get_default_backup_path(&self) -> PathBuf {
self.main_db_dir.join(match self.network {
Network::Mainnet => "backup.sql",
Network::Testnet => "backup-testnet.sql",
})
}
pub(crate) fn backup(&self, backup_path: PathBuf) -> Result<()> {
let con = self.get_connection()?;
con.backup(rusqlite::DatabaseName::Main, backup_path, None)?;
Ok(())
}
pub(crate) fn restore_from_backup<P>(&self, backup_path: P) -> Result<()>
where
P: AsRef<Path>,
{
let src_con = self.get_connection()?;
let mut dst_con = Connection::open(backup_path)?;
let backup = Backup::new(&src_con, &mut dst_con)?;
backup.run_to_completion(5, std::time::Duration::from_millis(250), None)?;
Ok(())
}
}