/// Generate output descriptors from either extended key (Xprv/Xpub) or mnemonic phrase.
/// This feature is intended for development and testing purposes only.
Descriptor {
- #[clap(subcommand)]
- subcommand: DescriptorSubCommand,
+ /// Descriptor type (script type)
+ #[arg(
+ long = "type",
+ short = 't',
+ value_parser = ["pkh", "wpkh", "sh", "wsh", "tr"],
+ default_value = "wsh"
+ )]
+ desc_type: String,
+ /// Optional key: xprv, xpub, or mnemonic phrase
+ key: Option<String>,
},
}
/// Wallet operation subcommands.
#[command(subcommand)]
subcommand: KeySubCommand,
},
- /// Exit REPL loop.
- Exit,
-}
-/// Subcommands for Key operations.
-#[derive(Debug, Subcommand, Clone, PartialEq, Eq)]
-pub enum DescriptorSubCommand {
- /// Generate a descriptor
- Generate {
+ /// Generate descriptors
+ Descriptor {
/// Descriptor type (script type).
#[arg(
long = "type",
default_value = "wsh"
)]
desc_type: String,
- /// Optional key input
+ /// Optional key: xprv, xpub, or mnemonic phrase
key: Option<String>,
},
+ /// Exit REPL loop.
+ Exit,
}
}
Ok("".to_string())
}
- CliSubCommand::Descriptor {
- subcommand: descriptor_subcommand,
- } => {
- let network = cli_opts.network;
- let descriptor = handle_descriptor_subcommand(network, descriptor_subcommand, pretty)?;
+ CliSubCommand::Descriptor { desc_type, key } => {
+ let descriptor = handle_descriptor_command(cli_opts.network, desc_type, key, pretty)?;
Ok(descriptor)
}
};
.map_err(|e| e.to_string())?;
Some(value)
}
+ ReplSubCommand::Descriptor { desc_type, key } => {
+ let value = handle_descriptor_command(network, desc_type, key, cli_opts.pretty)
+ .map_err(|e| e.to_string())?;
+ Some(value)
+ }
ReplSubCommand::Exit => None,
};
if let Some(value) = response {
Ok(buffer)
}
-pub fn handle_descriptor_subcommand(
+/// Handle the descriptor command
+pub fn handle_descriptor_command(
network: Network,
- subcommand: DescriptorSubCommand,
+ desc_type: String,
+ key: Option<String>,
pretty: bool,
) -> Result<String, Error> {
- let result = match subcommand {
- DescriptorSubCommand::Generate { desc_type, key } => {
- match key {
- Some(key) => {
- if is_mnemonic(&key) {
- // User provided mnemonic
- generate_descriptor_from_mnemonic(&key, network, &desc_type)
- } else {
- // User provided xprv/xpub
- generate_descriptors(&desc_type, &key, network)
- }
- }
- // Generate new mnemonic and descriptors
- None => generate_descriptor_with_mnemonic(network, &desc_type),
+ let result = match key {
+ Some(key) => {
+ if is_mnemonic(&key) {
+ // User provided mnemonic
+ generate_descriptor_from_mnemonic(&key, network, &desc_type)
+ } else {
+ // User provided xprv/xpub
+ generate_descriptors(&desc_type, &key, network)
}
}
+ // Generate new mnemonic and descriptors
+ None => generate_descriptor_with_mnemonic(network, &desc_type),
}?;
format_descriptor_output(&result, pretty)
}
+
#[cfg(any(
feature = "electrum",
feature = "esplora",