Skip to content

Commit

Permalink
open_database avoids creating a wallet dir if...
Browse files Browse the repository at this point in the history
...not necessary

This is useful for the wasm integration, where we want to call the
`open_database` function directly, without wanting it to create any
directories.
Note that when using bdk-cli normally, it won't create a db directory
if it's useless, but it will still create a base directory (even if
empty). This is suboptimal, but fixing it would require a quite big
refactor to the code.
  • Loading branch information
danielabrozzoni committed Sep 14, 2022
1 parent 7869bdb commit a4f58dc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ pub(crate) fn prepare_home_dir(home_path: Option<PathBuf>) -> Result<PathBuf, Er
}

/// prepare bdk_cli wallet directory
#[cfg(any(
feature = "key-value-db",
feature = "sqlite-db",
feature = "compact_filters"
))]
fn prepare_wallet_dir(wallet_name: &str, home_path: &Path) -> Result<PathBuf, Error> {
let mut dir = home_path.to_owned();

Expand All @@ -177,6 +182,7 @@ fn prepare_wallet_dir(wallet_name: &str, home_path: &Path) -> Result<PathBuf, Er
}

/// Prepare wallet database directory
#[cfg(any(feature = "key-value-db", feature = "sqlite-db",))]
fn prepare_wallet_db_dir(wallet_name: &str, home_path: &Path) -> Result<PathBuf, Error> {
let mut db_dir = prepare_wallet_dir(wallet_name, home_path)?;

Expand Down Expand Up @@ -252,7 +258,9 @@ pub(crate) fn open_database(
wallet_opts: &WalletOpts,
home_path: &Path,
) -> Result<AnyDatabase, Error> {
#![allow(unused_variables)]
let wallet_name = wallet_opts.wallet.as_ref().expect("wallet name");
#[cfg(any(feature = "key-value-db", feature = "sqlite-db",))]
let database_path = prepare_wallet_db_dir(wallet_name, home_path)?;

#[cfg(feature = "key-value-db")]
Expand Down

0 comments on commit a4f58dc

Please sign in to comment.