Skip to content

Commit 7e4d0e0

Browse files
committed
feat(init-wallet): rename init & add walletopts
- rename init to config and move walletopts as config options
1 parent 01cd13b commit 7e4d0e0

File tree

4 files changed

+99
-156
lines changed

4 files changed

+99
-156
lines changed

src/commands.rs

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@
1313
//! All subcommands are defined in the below enums.
1414
1515
#![allow(clippy::large_enum_variant)]
16-
17-
use crate::config::WalletConfig;
18-
use crate::error::BDKCliError as Error;
1916
use bdk_wallet::bitcoin::{
2017
Address, Network, OutPoint, ScriptBuf,
2118
bip32::{DerivationPath, Xpriv},
2219
};
2320
use clap::{Args, Parser, Subcommand, ValueEnum, value_parser};
24-
use std::path::Path;
2521

2622
#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
2723
use crate::utils::parse_proxy_auth;
@@ -73,8 +69,10 @@ pub enum CliSubCommand {
7369
/// needs backend like `sync` and `broadcast`, compile the binary with specific backend feature
7470
/// and use the configuration options below to configure for that backend.
7571
Wallet {
76-
#[command(flatten)]
77-
wallet_opts: WalletOpts,
72+
/// Selects the wallet to use.
73+
#[arg(env = "WALLET_NAME", short = 'w', long = "wallet", required = true)]
74+
wallet: String,
75+
7876
#[command(subcommand)]
7977
subcommand: WalletSubCommand,
8078
},
@@ -107,6 +105,10 @@ pub enum CliSubCommand {
107105
/// REPL command loop can be used to make recurring callbacks to an already loaded wallet.
108106
/// This mode is useful for hands on live testing of wallet operations.
109107
Repl {
108+
/// Wallet name for this REPL session
109+
#[arg(env = "WALLET_NAME", short = 'w', long = "wallet", required = true)]
110+
wallet: String,
111+
110112
#[command(flatten)]
111113
wallet_opts: WalletOpts,
112114
},
@@ -115,11 +117,14 @@ pub enum CliSubCommand {
115117
/// Wallet operation subcommands.
116118
#[derive(Debug, Subcommand, Clone, PartialEq)]
117119
pub enum WalletSubCommand {
118-
/// Initialize a wallet configuration and save to `config.toml`.
119-
Init {
120+
/// Save wallet configuration to `config.toml`.
121+
Config {
120122
/// Overwrite existing wallet configuration if it exists.
121-
#[arg(long = "force", default_value_t = false)]
123+
#[arg(short = 'f', long = "force", default_value_t = false)]
122124
force: bool,
125+
126+
#[command(flatten)]
127+
wallet_opts: WalletOpts,
123128
},
124129
#[cfg(any(
125130
feature = "electrum",
@@ -165,14 +170,15 @@ pub enum ClientType {
165170
#[derive(Debug, Args, Clone, PartialEq, Eq)]
166171
pub struct WalletOpts {
167172
/// Selects the wallet to use.
168-
#[arg(env = "WALLET_NAME", short = 'w', long = "wallet")]
173+
#[arg(skip)]
169174
pub wallet: Option<String>,
175+
// #[arg(env = "WALLET_NAME", short = 'w', long = "wallet", required = true)]
170176
/// Adds verbosity, returns PSBT in JSON format alongside serialized, displays expanded objects.
171177
#[arg(env = "VERBOSE", short = 'v', long = "verbose")]
172178
pub verbose: bool,
173179
/// Sets the descriptor to use for the external addresses.
174-
#[arg(env = "EXT_DESCRIPTOR", short = 'e', long)]
175-
pub ext_descriptor: Option<String>,
180+
#[arg(env = "EXT_DESCRIPTOR", short = 'e', long, required = true)]
181+
pub ext_descriptor: String,
176182
/// Sets the descriptor to use for internal/change addresses.
177183
#[arg(env = "INT_DESCRIPTOR", short = 'i', long)]
178184
pub int_descriptor: Option<String>,
@@ -223,56 +229,6 @@ pub struct WalletOpts {
223229
pub compactfilter_opts: CompactFilterOpts,
224230
}
225231

226-
impl WalletOpts {
227-
/// Merges optional configuration values from config.toml into the current WalletOpts.
228-
pub fn load_config(&mut self, wallet_name: &str, datadir: &Path) -> Result<(), Error> {
229-
if let Some(config) = WalletConfig::load(datadir)? {
230-
if let Ok(config_opts) = config.get_wallet_opts(wallet_name) {
231-
self.verbose = self.verbose || config_opts.verbose;
232-
#[cfg(feature = "electrum")]
233-
{
234-
self.batch_size = if self.batch_size != 10 {
235-
self.batch_size
236-
} else {
237-
config_opts.batch_size
238-
};
239-
}
240-
#[cfg(feature = "esplora")]
241-
{
242-
self.parallel_requests = if self.parallel_requests != 5 {
243-
self.parallel_requests
244-
} else {
245-
config_opts.parallel_requests
246-
};
247-
}
248-
#[cfg(feature = "rpc")]
249-
{
250-
self.basic_auth = if self.basic_auth != ("user".into(), "password".into()) {
251-
self.basic_auth.clone()
252-
} else {
253-
config_opts.basic_auth
254-
};
255-
self.cookie = self.cookie.take().or(config_opts.cookie);
256-
}
257-
#[cfg(feature = "cbf")]
258-
{
259-
if self.compactfilter_opts.conn_count == 2
260-
&& config_opts.compactfilter_opts.conn_count != 2
261-
{
262-
self.compactfilter_opts.conn_count =
263-
config_opts.compactfilter_opts.conn_count;
264-
}
265-
if self.compactfilter_opts.skip_blocks.is_none() {
266-
self.compactfilter_opts.skip_blocks =
267-
config_opts.compactfilter_opts.skip_blocks;
268-
}
269-
}
270-
}
271-
}
272-
Ok(())
273-
}
274-
}
275-
276232
/// Options to configure a SOCKS5 proxy for a blockchain client connection.
277233
#[cfg(any(feature = "electrum", feature = "esplora"))]
278234
#[derive(Debug, Args, Clone, PartialEq, Eq)]

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl WalletConfig {
127127
Ok(WalletOpts {
128128
wallet: Some(wallet_config.wallet.clone()),
129129
verbose: false,
130-
ext_descriptor: Some(wallet_config.ext_descriptor.clone()),
130+
ext_descriptor: wallet_config.ext_descriptor.clone(),
131131
int_descriptor: wallet_config.int_descriptor.clone(),
132132
#[cfg(any(
133133
feature = "electrum",

0 commit comments

Comments
 (0)