]> Untitled Git - bdk-cli/commitdiff
`open_database` avoids creating a wallet dir if...
authorDaniela Brozzoni <danielabrozzoni@protonmail.com>
Tue, 30 Aug 2022 15:22:12 +0000 (17:22 +0200)
committerDaniela Brozzoni <danielabrozzoni@protonmail.com>
Tue, 20 Sep 2022 15:40:05 +0000 (17:40 +0200)
...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.

src/utils.rs

index 566db9fb5604fb52fdd4bedae91092fd69b1d59a..0ebd9a5ab6247abf82de6b9aa5c5d45a9332e712 100644 (file)
@@ -164,6 +164,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();
 
@@ -178,6 +183,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)?;
 
@@ -248,12 +254,14 @@ pub(crate) fn prepare_electrum_datadir(home_path: &Path) -> Result<PathBuf, Erro
     Ok(dir)
 }
 
+#[allow(unused_variables)]
 /// Open the wallet database.
 pub(crate) fn open_database(
     wallet_opts: &WalletOpts,
     home_path: &Path,
 ) -> Result<AnyDatabase, Error> {
     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")]