Skip to content

Commit

Permalink
Merge #116: Create wallet dir only when necessary
Browse files Browse the repository at this point in the history
bff2d37 `open_database` avoids creating a wallet dir if... ...not necessary (Daniela Brozzoni)

Pull request description:

  ### Description

  Making sure to create the wallet dir only when necessary (database is either sqlite or key-value)

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk-cli/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [ ] I've added tests for the new feature
  * [ ] I've added docs for the new feature
  * [ ] I've updated `CHANGELOG.md`

  #### Bugfixes:

  * [ ] This pull request breaks the existing API
  * [ ] I've added tests to reproduce the issue which are now passing
  * [ ] I'm linking the issue being fixed by this PR

ACKs for top commit:
  rajarshimaitra:
    tACK bff2d37

Tree-SHA512: ee019830269f5d8332043ef8de750930883eed1791c867da048bd72c945dc576f74e5178b6c0a27737b0035208f7c862cf44c90321dd2bf6f74900fab08e113b
  • Loading branch information
notmandatory committed Sep 23, 2022
2 parents f8a10e9 + bff2d37 commit 183e85e
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 @@ -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();

Expand All @@ -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)?;

Expand Down Expand Up @@ -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")]
Expand Down

0 comments on commit 183e85e

Please sign in to comment.