Skip to content

Refractor WalletRuntime load to Combine wallet DB dir setup and config loading into one function - #319

Closed
emma31-dev wants to merge 1 commit into
bitcoindevkit:masterfrom
emma31-dev:walletruntimeconfigrefractor
Closed

Refractor WalletRuntime load to Combine wallet DB dir setup and config loading into one function#319
emma31-dev wants to merge 1 commit into
bitcoindevkit:masterfrom
emma31-dev:walletruntimeconfigrefractor

Conversation

@emma31-dev

@emma31-dev emma31-dev commented Sep 5, 2026

Copy link
Copy Markdown

Description

Merges prepare_wallet_db_dir and load_wallet_config into a single prepare_wallet_db_dir_and_config function that returns the database path alongside WalletOpts and Network.

The two functions were always called together in WalletRuntime::load, so combining them removes the duplication and simplifies the call site.

Notes to the reviewers

The main reason for this change is because the two functions merged were single-use.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

Thank you.

@emma31-dev
emma31-dev force-pushed the walletruntimeconfigrefractor branch from 1565f0a to dbae612 Compare September 5, 2026 17:59
Combine `prepare_wallet_db_dir` and `load_wallet_config` into a single
function that returns the database path alongside wallet options and
network, reducing code duplication in the `WalletRuntime` loader.

Signed-off-by: emma31-dev <emmanuelfidel07@gmail.com>
@emma31-dev
emma31-dev force-pushed the walletruntimeconfigrefractor branch from dbae612 to 2bdeb3d Compare September 5, 2026 18:02

@vadim-anfv vadim-anfv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch. I don't see the duplication this is meant to remove: both functions were called exactly once, on two consecutive lines of WalletRuntime::load. Being single-use isn't in itself a reason to merge two small helpers.

The call site reads worse to me now: two named calls became one returning (PathBuf, WalletOpts, Network) unpacked by position. I'd also rather each helper stayed responsible for a single thing, and a do_x_and_y name is a smell worth avoiding rather than introducing. Keeping the directory setup behind its own name reads better to me than having its body unfolded into the config loader.

This also isn't a pure refactor, it changes observable behavior. Same command on both, with a wallet name that isn't in the config:

$ bdk-cli --network testnet --datadir $D wallet --wallet ghost balance
Error: Generic error: No config found for wallet ghost

$ ls $D
master:      (empty)
this branch: ghost/

The merged function creates the directory before it validates the config, so a failed lookup now leaves an empty directory behind. Moving create_dir below the config parsing restores the old behavior, but then the function is just two independent blocks in a row.

@emma31-dev

Copy link
Copy Markdown
Author

My bad I didn't pay much attention to ordering. Should I reorder the change and keep it or forget it all together?

@vadim-anfv

Copy link
Copy Markdown
Contributor

My bad I didn't pay much attention to ordering. Should I reorder the change and keep it or forget it all together?

No worries. My take: I'd drop it. Reordering makes it behavior-neutral again, but then it's two independent blocks in one function and the duplication the description refers to isn't there, so not much is left that the change buys.

I'm not a maintainer though, so treat that as one reviewer's opinion rather than a verdict.

@emma31-dev emma31-dev closed this Sep 10, 2026
@github-project-automation github-project-automation Bot moved this to Done in BDK-CLI Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants