Skip to content

Commit c5c4fdb

Browse files
committed
feat(wallet-init): add wallets command
- add wallets command - add warning for using priv descriptors - update readme - add loading network from config
1 parent 424b9f5 commit c5c4fdb

File tree

7 files changed

+239
-226
lines changed

7 files changed

+239
-226
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Changelog info is also documented on the [GitHub releases](https://github.com/bi
44
page. See [DEVELOPMENT_CYCLE.md](DEVELOPMENT_CYCLE.md) for more details.
55

66
## [Unreleased]
7-
- Add wallet configs initialization for initialiazing and saving wallet configs
87
- Add wallet subcommand `config` to save wallet configs
8+
- Add `wallets` command to list all wallets saved configs
99

1010
## [2.0.0]
1111

README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -203,41 +203,43 @@ cargo run --pretty -n signet wallet -w {wallet_name} -d sqlite balance
203203
```
204204
This is available for wallet, key, repl and compile features. When ommitted, outputs default to `JSON`.
205205

206-
## Initializing Wallet Configurations with `init` Subcommand
206+
## Saving and using wallet configurations
207207

208-
The `wallet init` sub-command simplifies wallet operations by saving configuration parameters to `config.toml` in the data directory (default `~/.bdk-bitcoin/config.toml`). This allows you to run subsequent `bdk-cli wallet` commands without repeatedly specifying configuration details, easing wallet operations.
208+
The `wallet config` sub-command allows you to save wallet settings to a `config.toml` file in the default directory (`~/.bdk-bitcoin/`) or custom directory specified with the `--datadir` flag. This eliminate the need to repeatedly specify descriptors, client types, and other parameters for each command. Once configured, you can use any wallet command by simply specifying the wallet name. All other parameters are automatically loaded from the saved configuration.
209209

210-
To initialize a wallet configuration, use the following command structure:
210+
To save a wallet settings:
211211

212212
```shell
213-
cargo run --features <list-of-features> -- -n <network> wallet --wallet <wallet_name> --ext-descriptor <ext_descriptor> --int-descriptor <int_descriptor> --client-type <client_type> --url <server_url> [--database-type <database_type>] [--rpc-user <rpc_user>]
214-
[--rpc-password <rpc_password>] init
213+
cargo run --features <list-of-features> -- -n <network> wallet --wallet <wallet_name> config [ -f ] --ext-descriptor <ext_descriptor> --int-descriptor <int_descriptor> --client-type <client_type> --url <server_url> [--database-type <database_type>] [--rpc-user <rpc_user>]
214+
[--rpc-password <rpc_password>]
215215
```
216216

217217
For example, to initialize a wallet named `my_wallet` with `electrum` as the backend on `signet` network:
218218

219219
```shell
220-
cargo run --features electrum -- -n signet wallet -w my_wallet -e "tr(tprv8Z.../0/*)#dtdqk3dx" -i "tr(tprv8Z.../1/*)#ulgptya7" -d sqlite -c electrum -u "ssl://mempool.space:60602" init
220+
cargo run --features electrum -- -n signet wallet -w my_wallet config -e "tr(tprv8Z.../0/*)#dtdqk3dx" -i "tr(tprv8Z.../1/*)#ulgptya7" -d sqlite -c electrum -u "ssl://mempool.space:60602"
221221
```
222222

223-
To overwrite an existing wallet configuration, use the `--force` flag after the `init` sub-command.
223+
To overwrite an existing wallet configuration, use the `--force` flag after the `config` sub-command.
224224

225-
You can omit the following arguments to use their default values:
225+
#### Using a Configured Wallet
226226

227-
`network`: Defaults to `testnet`
227+
Once configured, use any wallet command with just the wallet name:
228228

229-
`database_type`: Defaults to `sqlite`
230-
231-
#### Using Saved Configuration
232-
233-
After a wallet is initialized, you can then run `bdk-cli` wallet commands without specifying the parameters, referencing only the wallet subcommand.
234-
235-
For example, with the wallet `my_wallet` initialized, generate a new address and sync the wallet as follow:
236229

237230
```shell
238-
cargo run wallet -w my_wallet --use-config new_address
231+
cargo run --features electrum wallet -w my_wallet new_address
239232

240-
cargo run --features electrum wallet -w my_wallet --use-config sync
233+
cargo run --features electrum wallet -w my_wallet full_scan
241234
```
242235

243236
Note that each wallet has its own configuration, allowing multiple wallets with different configurations.
237+
238+
#### View all saved Wallet Configs
239+
240+
To view all saved wallet configurations:
241+
242+
```shell
243+
cargo run wallets`
244+
```
245+
You can also use the `--pretty` flag for a formatted output.

src/commands.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,9 @@ pub enum CliSubCommand {
108108
/// Wallet name for this REPL session
109109
#[arg(env = "WALLET_NAME", short = 'w', long = "wallet", required = true)]
110110
wallet: String,
111-
112-
#[command(flatten)]
113-
wallet_opts: WalletOpts,
114111
},
112+
/// List all saved wallet configurations.
113+
Wallets,
115114
}
116115

117116
/// Wallet operation subcommands.

src/config.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl WalletConfig {
9090
"testnet" => Network::Testnet,
9191
"regtest" => Network::Regtest,
9292
"signet" => Network::Signet,
93+
"testnet4" => Network::Testnet4,
9394
_ => {
9495
return Err(Error::Generic("Invalid network".to_string()));
9596
}
@@ -105,7 +106,6 @@ impl WalletConfig {
105106
return Err(Error::Generic("Invalid database type".to_string()));
106107
}
107108
};
108-
109109
#[cfg(any(
110110
feature = "electrum",
111111
feature = "esplora",
@@ -144,9 +144,9 @@ impl WalletConfig {
144144
.clone()
145145
.ok_or_else(|| Error::Generic(format!("Server url not found")))?,
146146
#[cfg(feature = "electrum")]
147-
batch_size: 10,
147+
batch_size: wallet_config.batch_size.unwrap_or(10),
148148
#[cfg(feature = "esplora")]
149-
parallel_requests: 5,
149+
parallel_requests: wallet_config.parallel_requests.unwrap_or(5),
150150
#[cfg(feature = "rpc")]
151151
basic_auth: (
152152
wallet_config
@@ -161,10 +161,7 @@ impl WalletConfig {
161161
#[cfg(feature = "rpc")]
162162
cookie: wallet_config.cookie.clone(),
163163
#[cfg(feature = "cbf")]
164-
compactfilter_opts: crate::commands::CompactFilterOpts {
165-
conn_count: 2,
166-
skip_blocks: None,
167-
},
164+
compactfilter_opts: crate::commands::CompactFilterOpts { conn_count: 2 },
168165
})
169166
}
170167
}

0 commit comments

Comments
 (0)