Add saving wallet config with `bdk-cli wallet config`
Description
This PR adds bdk-cli wallet config command to save wallet configuration information to config.toml file in the data directory.
Fixes #192
Notes to the reviewers
- Reusing the exported
serdecrate frombdk_walletdid not offer thederivefeature
Changelog notice
- Add wallet subcommand
configto save wallet configs - Add top-level
walletscommand to show all saved wallet configs
Checklists
Features
- [x] 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> - [x] 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... - [x] Repl uses the same wallet configs:
repl [-w <name>] - [x] command to list all saved wallet configs:
wallets - [x] throw warnings if using mainnet and saving a private descriptor in a config.
All Submissions:
- [x] I've signed all my commits
- [x] I followed the contribution guidelines
- [x] I ran
cargo fmtandcargo clippybefore committing
New Features:
- [ ] I've added tests for the new feature
- [x] I've added docs for the new feature
- [x] I've updated
CHANGELOG.md
Pull Request Test Coverage Report for Build 19264362308
Details
- 3 of 331 (0.91%) changed or added relevant lines in 3 files are covered.
- 1 unchanged line in 1 file lost coverage.
- Overall coverage decreased (-1.9%) to 10.267%
| Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
|---|---|---|---|
| src/utils.rs | 0 | 43 | 0.0% |
| src/config.rs | 0 | 85 | 0.0% |
| src/handlers.rs | 3 | 203 | 1.48% |
| <!-- | Total: | 3 | 331 |
| Files with Coverage Reduction | New Missed Lines | % |
|---|---|---|
| src/handlers.rs | 1 | 13.32% |
| <!-- | Total: | 1 |
| Totals | |
|---|---|
| Change from base Build 19253249526: | -1.9% |
| Covered Lines: | 173 |
| Relevant Lines: | 1685 |
💛 - Coveralls
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.
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 usingjust?Creating the config file in rust should be easier to maintain/keep in sync than your
justapproach and shouldn't take too much more than adding theSerializetrait toWalletConfigInner. You should be able to reuse theWalletOptsto capture the values withclapthat you need to put in the config file too.
Alright, I will update.
Alright, I will update.
@notmandatory I have updated the PR
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.
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
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.
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.
How about something like:
- 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> - 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... - Repl uses the same wallet configs:
repl [-w <name>] - Add a command to list all available config names with summary of configured options:
wallet list - Should throw warnings if using mainnet and saving a private descriptor in a config.
How about something like:
- 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>- 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...- Repl uses the same wallet configs:
repl [-w <name>]- Add a command to list all available config names with summary of configured options:
wallet list- Should throw warnings if using mainnet and saving a private descriptor in a config.
Hi @notmandatory, there is an issues that we did not envisage and discuss on this PR that came up during implementation:
The wallet [-w <name>] config <wallet opts> command introduced a wallet name parameter that has to be supplied whenever the wallet command is used. This means that the list subcommand that should not require a wallet name has to accept the wallet name. If we make the wallet name optional above, we will have to do manual validation for the name.
Good point. Yes I agree a new top level command makes sense to list the wallets. Either "wallets" as you suggest or "list" makes sense to me.
I found an error when testing with testnet4, and a couple small nits should be fixed too. Otherwise this looks good.
Thank you for catching all these. I have updated.
In the future if everyone prefers the config approach it should probably become the only way to use the wallet features.
Yes, I agree.