Skip to content

Add wallets --delete to remove saved wallet config - #312

Open
yan-pi wants to merge 2 commits into
bitcoindevkit:masterfrom
yan-pi:feat/wallets-delete
Open

Add wallets --delete to remove saved wallet config#312
yan-pi wants to merge 2 commits into
bitcoindevkit:masterfrom
yan-pi:feat/wallets-delete

Conversation

@yan-pi

@yan-pi yan-pi commented Aug 6, 2026

Copy link
Copy Markdown

Description

Adds a wallets --delete <wallet_name> command to remove a saved wallet configuration from config.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 WalletOpts has four non-Option fields, 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 a WalletOpts, 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 the wallets listing unchanged.

Only the config.toml entry is affected, wallet data on disk is not touched (dont know if its the correct path).

Changelog notice

  • Added wallets --delete to remove a saved wallet configuration

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

@yan-pi
yan-pi force-pushed the feat/wallets-delete branch from 9c25d3d to e987877 Compare August 6, 2026 18:06
@yan-pi yan-pi changed the title feat(wallet): add wallets --delete to remove saved wallet config Add wallets --delete to remove saved wallet config Aug 6, 2026
@tvpeter

tvpeter commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Only the config.toml entry is affected, wallet data on disk is not touched (dont know if its the correct path).

So wallet config only writes config.toml. The DB file is created lazily during an actual wallet operation. So deleting a config that was never used leaves nothing on disk. However, if the wallet was used, the DB file remains.

@tvpeter tvpeter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread src/handlers/config.rs
#[derive(Args, Debug, Clone, PartialEq)]
pub struct ListWalletsCommand;
pub struct WalletsCommand {
/// Delete the saved configuration for the given wallet instead of listing.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// Delete the saved configuration for the given wallet instead of listing.
/// Delete the saved configuration for the given wallet.

Comment thread src/commands.rs

/// List all saved wallet configurations.
Wallets(ListWalletsCommand),
/// List all saved wallet configurations, or delete one with `--delete`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// List all saved wallet configurations, or delete one with `--delete`.
/// Saved wallet configuration operations.

@vadim-anfv vadim-anfv left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

cACK e987877

Thanks for picking this up. I left a couple of non-blocking comments inline, both of which fold naturally into the wallets list / wallets delete restructure @tvpeter asked for.

Comment thread src/handlers/config.rs
"Wallet '{wallet_name}' not found in config"
)));
}
config.save(&ctx.datadir)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/config.rs
Comment on lines +356 to +392
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,
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Add command to delete saved wallet config

3 participants