Skip to content

Commit 7d3720e

Browse files
committed
feat(desc): remove generate subcommand
- remove generate subcommand - add descriptor to the repl
1 parent 32a2c88 commit 7d3720e

File tree

2 files changed

+37
-32
lines changed

2 files changed

+37
-32
lines changed

src/commands.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,16 @@ pub enum CliSubCommand {
111111
/// Generate output descriptors from either extended key (Xprv/Xpub) or mnemonic phrase.
112112
/// This feature is intended for development and testing purposes only.
113113
Descriptor {
114-
#[clap(subcommand)]
115-
subcommand: DescriptorSubCommand,
114+
/// Descriptor type (script type)
115+
#[arg(
116+
long = "type",
117+
short = 't',
118+
value_parser = ["pkh", "wpkh", "sh", "wsh", "tr"],
119+
default_value = "wsh"
120+
)]
121+
desc_type: String,
122+
/// Optional key: xprv, xpub, or mnemonic phrase
123+
key: Option<String>,
116124
},
117125
}
118126
/// Wallet operation subcommands.
@@ -476,14 +484,8 @@ pub enum ReplSubCommand {
476484
#[command(subcommand)]
477485
subcommand: KeySubCommand,
478486
},
479-
/// Exit REPL loop.
480-
Exit,
481-
}
482-
/// Subcommands for Key operations.
483-
#[derive(Debug, Subcommand, Clone, PartialEq, Eq)]
484-
pub enum DescriptorSubCommand {
485-
/// Generate a descriptor
486-
Generate {
487+
/// Generate descriptors
488+
Descriptor {
487489
/// Descriptor type (script type).
488490
#[arg(
489491
long = "type",
@@ -492,7 +494,9 @@ pub enum DescriptorSubCommand {
492494
default_value = "wsh"
493495
)]
494496
desc_type: String,
495-
/// Optional key input
497+
/// Optional key: xprv, xpub, or mnemonic phrase
496498
key: Option<String>,
497499
},
500+
/// Exit REPL loop.
501+
Exit,
498502
}

src/handlers.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,11 +1256,8 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
12561256
}
12571257
Ok("".to_string())
12581258
}
1259-
CliSubCommand::Descriptor {
1260-
subcommand: descriptor_subcommand,
1261-
} => {
1262-
let network = cli_opts.network;
1263-
let descriptor = handle_descriptor_subcommand(network, descriptor_subcommand, pretty)?;
1259+
CliSubCommand::Descriptor { desc_type, key } => {
1260+
let descriptor = handle_descriptor_command(cli_opts.network, desc_type, key, pretty)?;
12641261
Ok(descriptor)
12651262
}
12661263
};
@@ -1310,6 +1307,11 @@ async fn respond(
13101307
.map_err(|e| e.to_string())?;
13111308
Some(value)
13121309
}
1310+
ReplSubCommand::Descriptor { desc_type, key } => {
1311+
let value = handle_descriptor_command(network, desc_type, key, cli_opts.pretty)
1312+
.map_err(|e| e.to_string())?;
1313+
Some(value)
1314+
}
13131315
ReplSubCommand::Exit => None,
13141316
};
13151317
if let Some(value) = response {
@@ -1336,30 +1338,29 @@ fn readline() -> Result<String, Error> {
13361338
Ok(buffer)
13371339
}
13381340

1339-
pub fn handle_descriptor_subcommand(
1341+
/// Handle the descriptor command
1342+
pub fn handle_descriptor_command(
13401343
network: Network,
1341-
subcommand: DescriptorSubCommand,
1344+
desc_type: String,
1345+
key: Option<String>,
13421346
pretty: bool,
13431347
) -> Result<String, Error> {
1344-
let result = match subcommand {
1345-
DescriptorSubCommand::Generate { desc_type, key } => {
1346-
match key {
1347-
Some(key) => {
1348-
if is_mnemonic(&key) {
1349-
// User provided mnemonic
1350-
generate_descriptor_from_mnemonic(&key, network, &desc_type)
1351-
} else {
1352-
// User provided xprv/xpub
1353-
generate_descriptors(&desc_type, &key, network)
1354-
}
1355-
}
1356-
// Generate new mnemonic and descriptors
1357-
None => generate_descriptor_with_mnemonic(network, &desc_type),
1348+
let result = match key {
1349+
Some(key) => {
1350+
if is_mnemonic(&key) {
1351+
// User provided mnemonic
1352+
generate_descriptor_from_mnemonic(&key, network, &desc_type)
1353+
} else {
1354+
// User provided xprv/xpub
1355+
generate_descriptors(&desc_type, &key, network)
13581356
}
13591357
}
1358+
// Generate new mnemonic and descriptors
1359+
None => generate_descriptor_with_mnemonic(network, &desc_type),
13601360
}?;
13611361
format_descriptor_output(&result, pretty)
13621362
}
1363+
13631364
#[cfg(any(
13641365
feature = "electrum",
13651366
feature = "esplora",

0 commit comments

Comments
 (0)