Add wallets --delete to remove saved wallet config - #312
Conversation
9c25d3d to
e987877
Compare
wallets --delete to remove saved wallet config
So |
tvpeter
left a comment
There was a problem hiding this comment.
I agree with the approach of the delete operation but the returned type of WalletList is unnecesary. If returning a message is not possible, then it is better to split the wallets into something like wallets list and wallets --delete <name>. So WalletsSubcommand will be the top-level.
| #[derive(Args, Debug, Clone, PartialEq)] | ||
| pub struct ListWalletsCommand; | ||
| pub struct WalletsCommand { | ||
| /// Delete the saved configuration for the given wallet instead of listing. |
There was a problem hiding this comment.
| /// Delete the saved configuration for the given wallet instead of listing. | |
| /// Delete the saved configuration for the given wallet. |
|
|
||
| /// List all saved wallet configurations. | ||
| Wallets(ListWalletsCommand), | ||
| /// List all saved wallet configurations, or delete one with `--delete`. |
There was a problem hiding this comment.
| /// List all saved wallet configurations, or delete one with `--delete`. | |
| /// Saved wallet configuration operations. |
| "Wallet '{wallet_name}' not found in config" | ||
| ))); | ||
| } | ||
| config.save(&ctx.datadir)?; |
There was a problem hiding this comment.
Non-blocking: deleting the last wallet leaves config.toml with an empty wallets table, a state that was unreachable before --delete. WalletConfig::load returns None only when the file is missing, so wallets then prints {} and exits 0, while the same situation on a fresh datadir fails with "No wallets configured yet." and a non-zero exit (test_list_wallets_empty).
Probably worth folding into the wallets list / wallets delete split you are doing anyway.
| WalletConfigInner { | ||
| wallet: name.to_string(), | ||
| network: "testnet".to_string(), | ||
| ext_descriptor: EXT_DESCRIPTOR.to_string(), | ||
| int_descriptor: Some(INT_DESCRIPTOR.to_string()), | ||
| #[cfg(any(feature = "sqlite", feature = "redb"))] | ||
| database_type: "sqlite".to_string(), | ||
| #[cfg(any( | ||
| feature = "electrum", | ||
| feature = "esplora", | ||
| feature = "rpc", | ||
| feature = "cbf" | ||
| ))] | ||
| client_type: Some("rpc".to_string()), | ||
| #[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))] | ||
| server_url: Some("http://localhost:18443".to_string()), | ||
| #[cfg(feature = "electrum")] | ||
| batch_size: None, | ||
| #[cfg(feature = "esplora")] | ||
| parallel_requests: None, | ||
| #[cfg(feature = "rpc")] | ||
| rpc_user: None, | ||
| #[cfg(feature = "rpc")] | ||
| rpc_password: None, | ||
| #[cfg(feature = "rpc")] | ||
| cookie: None, | ||
| #[cfg(any(feature = "electrum", feature = "esplora"))] | ||
| proxy: None, | ||
| #[cfg(any(feature = "electrum", feature = "esplora"))] | ||
| proxy_auth: None, | ||
| #[cfg(any(feature = "electrum", feature = "esplora"))] | ||
| proxy_retries: None, | ||
| #[cfg(any(feature = "electrum", feature = "esplora"))] | ||
| proxy_timeout: None, | ||
| #[cfg(feature = "cbf")] | ||
| conn_count: None, | ||
| } |
There was a problem hiding this comment.
Nit: test_wallet_config_inner_to_opts_conversion and test_invalid_client_type_fails still build WalletConfigInner by hand, repeating the same ~20 cfg-gated fields as the new helper.
Since you are adding a helper anyway, consider turning it into a small builder and reusing it there too - those two only differ in a few values. Fine to leave for a follow-up.
Description
Adds a
wallets --delete <wallet_name>command to remove a saved wallet configuration fromconfig.toml. Resolves #310.Notes to the reviewers
I first looked at putting delete like this:
wallet config --delete, that would be the symmetric spot.But it doesn't work with the clap 4 derive setup, since
WalletOptshas four non-Optionfields, that clap derives as implicitly required. So the command fails at parse time, before the handler ever runs.Working around it would mean converting all four fields to
Option<T>and touching every consumer that builds aWalletOpts, for a one-argument delete.I went with the top-level
wallets --delete <name>instead: it reads the saved config, removes the entry, and keeps thewalletslisting unchanged.Only the
config.tomlentry is affected, wallet data on disk is not touched (dont know if its the correct path).Changelog notice
wallets --deleteto remove a saved wallet configurationChecklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features:
CHANGELOG.md