]> Untitled Git - bdk-cli/commitdiff
feat(desc): remove generate subcommand
authorVihiga Tyonum <withtvpeter@gmail.com>
Wed, 5 Nov 2025 17:41:04 +0000 (18:41 +0100)
committerVihiga Tyonum <withtvpeter@gmail.com>
Wed, 5 Nov 2025 17:43:24 +0000 (18:43 +0100)
- remove generate subcommand
- add descriptor to the repl

src/commands.rs
src/handlers.rs

index 2b82c4b23c0b91b4c9ebb754a6e4ce6e0970949c..d3f2d98313a7ffd62f7396528024339008382a0f 100644 (file)
@@ -111,8 +111,16 @@ pub enum CliSubCommand {
     /// 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.
@@ -476,14 +484,8 @@ pub enum ReplSubCommand {
         #[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",
@@ -492,7 +494,9 @@ pub enum DescriptorSubCommand {
             default_value = "wsh"
         )]
         desc_type: String,
-        /// Optional key input
+        /// Optional key: xprv, xpub, or mnemonic phrase
         key: Option<String>,
     },
+    /// Exit REPL loop.
+    Exit,
 }
index b39712ee310917beaa29e3703a68e5eea9141fed..6c58a83839083fb957f43eef88e60b711d52ed7a 100644 (file)
@@ -1256,11 +1256,8 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
             }
             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)
         }
     };
@@ -1310,6 +1307,11 @@ async fn respond(
                 .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 {
@@ -1336,30 +1338,29 @@ fn readline() -> Result<String, Error> {
     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",