@@ -37,8 +37,7 @@ use bdk_wallet::{KeychainKind, SignOptions, Wallet};
3737use bdk_wallet:: keys:: DescriptorKey :: Secret ;
3838use bdk_wallet:: keys:: { DerivableKey , DescriptorKey , ExtendedKey , GeneratableKey , GeneratedKey } ;
3939use bdk_wallet:: miniscript:: miniscript;
40- use bdk_wallet:: serde:: ser:: Error as SerdeErrorTrait ;
41- use serde_json:: { json, Value , Error as SerdeError } ;
40+ use serde_json:: { json, Value } ;
4241use std:: collections:: BTreeMap ;
4342#[ cfg( any( feature = "electrum" , feature = "esplora" ) ) ]
4443use std:: collections:: HashSet ;
@@ -905,7 +904,7 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
905904 CliSubCommand :: Descriptor ( args) => {
906905 let network = cli_opts. network ;
907906 let descriptor = generate_descriptor_from_args ( args. clone ( ) , network)
908- . map_err ( |e| SerdeError :: custom ( e. to_string ( ) ) ) ?;
907+ . map_err ( |e| Error :: Generic ( e. to_string ( ) ) ) ?;
909908 let json = serde_json:: to_string_pretty ( & descriptor) ?;
910909 Ok ( json)
911910 }
@@ -984,19 +983,42 @@ pub fn generate_descriptor_from_args(
984983 args : GenerateDescriptorArgs ,
985984 network : Network ,
986985) -> Result < serde_json:: Value , Error > {
986+ let descriptor_type = match args. r#type {
987+ 44 => DescriptorType :: Bip44 ,
988+ 49 => DescriptorType :: Bip49 ,
989+ 84 => DescriptorType :: Bip84 ,
990+ 86 => DescriptorType :: Bip86 ,
991+ _ => {
992+ return Err ( Error :: Generic ( format ! (
993+ "Unsupported script type {}" ,
994+ args. r#type
995+ ) ) )
996+ }
997+ } ;
998+ if args. multipath && args. path . is_some ( ) {
999+ return Err ( Error :: InvalidArguments (
1000+ "Path can not be called here" . to_string ( ) ,
1001+ ) ) ;
1002+ }
1003+ if args. path . is_some ( ) && args. key . is_none ( ) {
1004+ return Err ( Error :: InvalidArguments (
1005+ "Custom path requires a key" . to_string ( ) ,
1006+ ) ) ;
1007+ }
9871008 match ( args. multipath , args. key . as_ref ( ) ) {
9881009 ( true , Some ( key) ) => generate_multipath_descriptor ( & network, args. r#type , key) ,
989- ( false , Some ( key) ) => generate_standard_descriptor ( & network, args. r#type , key) ,
990- ( false , None ) => {
991- // New default: generate descriptor from fresh mnemonic (for script_type 84 only)
992- if args. r#type == 84 {
993- generate_new_bip84_descriptor_with_mnemonic ( network)
1010+ ( false , Some ( key) ) => {
1011+ if let Some ( path) = args. path . as_ref ( ) {
1012+ // Use descriptor from custom derivation path
1013+ generate_bip_descriptor_from_key ( & network, key, path, descriptor_type)
9941014 } else {
995- Err ( Error :: Generic (
996- "Only script type 84 is supported for mnemonic-based generation" . to_string ( ) ,
997- ) )
1015+ generate_standard_descriptor ( & network, args. r#type , key)
9981016 }
9991017 }
1018+ ( false , None ) => {
1019+ // Generate from fresh mnemonic
1020+ generate_new_descriptor_with_mnemonic ( network, descriptor_type)
1021+ }
10001022 _ => Err ( Error :: InvalidArguments (
10011023 "Invalid arguments: please provide a key or a weak string" . to_string ( ) ,
10021024 ) ) ,
0 commit comments