Skip to content

Commit 7bf0982

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 - fix review comments
1 parent f3ee4ee commit 7bf0982

File tree

8 files changed

+248
-231
lines changed

8 files changed

+248
-231
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

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

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

219-
## Initializing Wallet Configurations with `init` Subcommand
219+
## Saving and using wallet configurations
220220

221-
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.
221+
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.
222222

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

225225
```shell
226-
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>]
227-
[--rpc-password <rpc_password>] init
226+
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>]
227+
[--rpc-password <rpc_password>]
228228
```
229229

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

232232
```shell
233-
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
233+
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"
234234
```
235235

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

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

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

242-
`database_type`: Defaults to `sqlite`
243-
244-
#### Using Saved Configuration
245-
246-
After a wallet is initialized, you can then run `bdk-cli` wallet commands without specifying the parameters, referencing only the wallet subcommand.
247-
248-
For example, with the wallet `my_wallet` initialized, generate a new address and sync the wallet as follow:
249242

250243
```shell
251-
cargo run wallet -w my_wallet --use-config new_address
244+
cargo run --features electrum wallet -w my_wallet new_address
252245

253-
cargo run --features electrum wallet -w my_wallet --use-config sync
246+
cargo run --features electrum wallet -w my_wallet full_scan
254247
```
255248

256249
Note that each wallet has its own configuration, allowing multiple wallets with different configurations.
250+
251+
#### View all saved Wallet Configs
252+
253+
To view all saved wallet configurations:
254+
255+
```shell
256+
cargo run wallets`
257+
```
258+
You can also use the `--pretty` flag for a formatted output.

src/commands.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ 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
},
115112
/// Output Descriptors operations.
116113
///
@@ -128,6 +125,8 @@ pub enum CliSubCommand {
128125
/// Optional key: xprv, xpub, or mnemonic phrase
129126
key: Option<String>,
130127
},
128+
/// List all saved wallet configurations.
129+
Wallets,
131130
}
132131
/// Wallet operation subcommands.
133132
#[derive(Debug, Subcommand, Clone, PartialEq)]
@@ -187,7 +186,6 @@ pub struct WalletOpts {
187186
/// Selects the wallet to use.
188187
#[arg(skip)]
189188
pub wallet: Option<String>,
190-
// #[arg(env = "WALLET_NAME", short = 'w', long = "wallet", required = true)]
191189
/// Adds verbosity, returns PSBT in JSON format alongside serialized, displays expanded objects.
192190
#[arg(env = "VERBOSE", short = 'v', long = "verbose")]
193191
pub verbose: bool,

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)