Skip to content

Conversation

tvpeter
Copy link
Collaborator

@tvpeter tvpeter commented Jun 18, 2025

Description

This PR adds bdk-cli wallet init command to save wallet configuration information to config.toml file in the data directory.

Fixes #192

Notes to the reviewers

  • Reusing the exported serde crate from bdk_wallet did not offer the derive feature
  • CLI parameters have higher precedence over saved config values

Changelog notice

  • Add wallet subcommand init to save wallet configs
  • Add an optional flag --use-config to use saved configs for a wallet

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • 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

@tvpeter tvpeter force-pushed the feat/init-wallet-support branch from 9e56084 to b3966e3 Compare June 18, 2025 20:41
@coveralls
Copy link

coveralls commented Jun 18, 2025

Pull Request Test Coverage Report for Build 17438777973

Details

  • 0 of 331 (0.0%) changed or added relevant lines in 5 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.5%) to 1.702%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/utils.rs 0 9 0.0%
src/commands.rs 0 28 0.0%
src/config.rs 0 67 0.0%
src/handlers.rs 0 97 0.0%
src/main.rs 0 130 0.0%
Files with Coverage Reduction New Missed Lines %
src/handlers.rs 1 2.49%
src/utils.rs 1 0.0%
Totals Coverage Status
Change from base Build 17324807959: -0.5%
Covered Lines: 25
Relevant Lines: 1469

💛 - Coveralls

@tvpeter tvpeter force-pushed the feat/init-wallet-support branch from b3966e3 to bf14df8 Compare June 19, 2025 04:32
@tvpeter tvpeter requested a review from notmandatory June 19, 2025 04:33
@notmandatory notmandatory moved this to Ready to Review in BDK-CLI Jun 24, 2025
@notmandatory notmandatory added this to the CLI 1.1.0 milestone Jun 24, 2025
@notmandatory
Copy link
Member

notmandatory commented Jun 24, 2025

I like the approach for loading the config file parameters if the file exists, but is there a reason you didn't add a CLI bdk-cli wallet init ... command in rust to create the config file rather than using just ?

Creating the config file in rust should be easier to maintain/keep in sync than your just approach and shouldn't take too much more than adding the Serialize trait to WalletConfigInner. You should be able to reuse the WalletOpts to capture the values with clap that you need to put in the config file too.

@notmandatory notmandatory added the enhancement New feature or request label Jun 24, 2025
@tvpeter
Copy link
Collaborator Author

tvpeter commented Jun 24, 2025

I like the approach for loading the config file parameters if the file exists, but is there a reason you didn't add a CLI bdk-cli wallet init ... command in rust to create the config file rather than using just ?

Creating the config file in rust should be easier to maintain/keep in sync than your just approach and shouldn't take too much more than adding the Serialize trait to WalletConfigInner. You should be able to reuse the WalletOpts to capture the values with clap that you need to put in the config file too.

Alright, I will update.

@tvpeter tvpeter force-pushed the feat/init-wallet-support branch from bf14df8 to 36ee973 Compare June 27, 2025 04:04
@tvpeter tvpeter changed the title Add initializing wallet configuration with Justfile Add initializing wallet configuration with bdk-cli wallet init Jun 27, 2025
@tvpeter tvpeter force-pushed the feat/init-wallet-support branch 4 times, most recently from 5125cf8 to fcf7ce8 Compare June 27, 2025 10:03
@tvpeter
Copy link
Collaborator Author

tvpeter commented Jun 27, 2025

Alright, I will update.

@notmandatory I have updated the PR

@tvpeter tvpeter force-pushed the feat/init-wallet-support branch 2 times, most recently from f77b1da to 70a5390 Compare August 25, 2025 19:26
@tvpeter tvpeter force-pushed the feat/init-wallet-support branch from 70a5390 to 9461e85 Compare September 1, 2025 04:17
- add config.rs to store and retrieve
values
- add toml and serde crates for desearilizing and
reading values
- update utils, commands and handlers files
to use values from config.toml
-refactor prepare_wallet_db fn
- fix clippy issues

[Issue: bitcoindevkit#192]
- update wallet initialization to use `bdk-cli
wallet init` command directly and read walletopts
- update README for how to use the bdk-cli wallet
init command
- fix clippy warnings
- update CHANGELOG

[Issue: bitcoindevkit#192]
@tvpeter tvpeter force-pushed the feat/init-wallet-support branch from 9461e85 to 5d9feb0 Compare September 1, 2025 04:20
@thunderbiscuit
Copy link
Member

I need to start keeping track of all these awesome new features I honestly see the PRs come in and can't keep up. This is super cool.

@tvpeter
Copy link
Collaborator Author

tvpeter commented Sep 3, 2025

I need to start keeping track of all these awesome new features I honestly see the PRs come in and can't keep up. This is super cool.

Thank you @thunderbiscuit

@tvpeter tvpeter force-pushed the feat/init-wallet-support branch from c902975 to 9549e09 Compare September 3, 2025 15:44
- move init subcommand to use existing walletopts
- add --use-config to use saved config
- add fetching required params before clap parsing
@tvpeter tvpeter force-pushed the feat/init-wallet-support branch from 9549e09 to 0f6b320 Compare September 3, 2025 15:45
@notmandatory
Copy link
Member

I spent some time today reviewing and even though this looks like a workable way to do it and is based on my suggestion I'm afraid it's going to be a hassle to maintain. I've been experimenting with somehow using the different clap parsing functions (https://docs.rs/clap/latest/clap/trait.Parser.html) but so far haven't figured out a better way. I'd like to keep thinking about it. We might have to simplify the problem somehow such as by not trying to merge loaded and CLI args.

@tvpeter
Copy link
Collaborator Author

tvpeter commented Sep 6, 2025

I'm afraid it's going to be a hassle to maintain. I've been experimenting with somehow using the different clap parsing functions (https://docs.rs/clap/latest/clap/trait.Parser.html) but so far haven't figured out a better way. I'd like to keep thinking about it. We might have to simplify the problem somehow such as by not trying to merge loaded and CLI args.

Thank you @notmandatory.
Yes, I agree that it will be challenging to maintain, as it involves two steps (pre clap parsing and after parsing) and even more difficult as they are in different locations in the codebase. I thought about moving everything to pre clap parsing based on the wallet sub-command the user has entered but that will clog the entry point as there will be lots of if...else checks.

Also, for the Parser trait, I read that it does not allow interacting with an external resource such as reading a file as I would want it.

I will also be trying out other approaches in case there is a cleaner way to handle it.

@notmandatory
Copy link
Member

notmandatory commented Sep 6, 2025

How about something like:

  1. One command to save a wallet config, give wallet name or a default name is used, clap enforces required options; optional -f to override existing config:
    wallet [-f] [-w <name>] config <wallet opts>
  2. All other wallet commands require that a config exists, use wallet name or the default is used. Give error if config is missing:
    wallet [-w <name>] sync | balance | new_address | etc...
  3. Repl uses the same wallet configs:
    repl [-w <name>]
  4. Add a command to list all available config names with summary of configured options:
    wallet list
  5. Should throw warnings if using mainnet and saving a private descriptor in a config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Ready to Review
Development

Successfully merging this pull request may close these issues.

Add "init" wallet support
4 participants