Skip to content

Commit c8f23ba

Browse files
committed
feat(descriptors): fix descriptor generation
- remove multipath descriptor generation - fix descriptor type
1 parent 550e816 commit c8f23ba

File tree

3 files changed

+128
-228
lines changed

3 files changed

+128
-228
lines changed

src/commands.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ use bdk_wallet::bitcoin::{
1717
Address, Network, OutPoint, ScriptBuf,
1818
bip32::{DerivationPath, Xpriv},
1919
};
20-
use clap::{
21-
Args, Parser, Subcommand, ValueEnum,
22-
builder::{PossibleValuesParser, TypedValueParser},
23-
value_parser,
24-
};
20+
use clap::{Args, Parser, Subcommand, ValueEnum, value_parser};
2521

2622
#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
2723
use crate::utils::parse_proxy_auth;
@@ -492,14 +488,10 @@ pub enum DescriptorSubCommand {
492488
#[arg(
493489
long = "type",
494490
short = 't',
495-
value_parser = PossibleValuesParser::new(["44", "49", "84", "86"])
496-
.map(|s| s.parse::<u8>().unwrap()),
497-
default_value = "84"
491+
value_parser = ["pkh", "wpkh", "sh", "wsh", "tr"],
492+
default_value = "wsh"
498493
)]
499-
r#type: u8,
500-
/// Enable multipath descriptors
501-
#[arg(long = "multipath", short = 'm', default_value_t = false)]
502-
multipath: bool,
494+
desc_type: String,
503495
/// Optional key input
504496
key: Option<String>,
505497
},

src/handlers.rs

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,10 @@ use bdk_wallet::{
4747
use cli_table::{Cell, CellStruct, Style, Table, format::Justify};
4848
use serde_json::json;
4949
#[cfg(feature = "cbf")]
50-
use {
51-
crate::utils::BlockchainClient::KyotoClient,
52-
bdk_kyoto::{Info, LightClient},
53-
tokio::select,
54-
};
50+
use {crate::utils::BlockchainClient::KyotoClient, bdk_kyoto::LightClient, tokio::select};
5551

5652
#[cfg(feature = "electrum")]
5753
use crate::utils::BlockchainClient::Electrum;
58-
#[cfg(feature = "cbf")]
59-
use bdk_kyoto::LightClient;
60-
#[cfg(feature = "compiler")]
61-
use bdk_wallet::bitcoin::XOnlyPublicKey;
62-
use bdk_wallet::bitcoin::base64::prelude::*;
63-
use serde_json::Value;
6454
use std::collections::BTreeMap;
6555
#[cfg(any(feature = "electrum", feature = "esplora"))]
6656
use std::collections::HashSet;
@@ -1352,44 +1342,23 @@ pub fn handle_descriptor_subcommand(
13521342
pretty: bool,
13531343
) -> Result<String, Error> {
13541344
let result = match subcommand {
1355-
DescriptorSubCommand::Generate {
1356-
r#type,
1357-
multipath,
1358-
key,
1359-
} => {
1360-
let descriptor_type = DescriptorType::from_bip32_num(r#type)
1361-
.ok_or_else(|| Error::Generic(format!("Unsupported script type: {type}")))?;
1362-
1363-
match (multipath, key) {
1364-
// generate multipath descriptors with a key
1365-
(true, Some(key)) => {
1366-
if is_mnemonic(&key) {
1367-
return Err(Error::Generic(
1368-
"Mnemonic not supported for multipath descriptors".to_string(),
1369-
));
1370-
}
1371-
generate_descriptors(descriptor_type, &key, true)
1372-
}
1345+
DescriptorSubCommand::Generate { desc_type, key } => {
1346+
match key {
13731347
// generate descriptors with a key or mnemonic
1374-
(false, Some(key)) => {
1348+
Some(key) => {
13751349
if is_mnemonic(&key) {
1376-
generate_descriptor_from_mnemonic_string(&key, network, descriptor_type)
1350+
generate_descriptor_from_mnemonic(&key, network, &desc_type)
13771351
} else {
1378-
generate_descriptors(descriptor_type, &key, false)
1352+
generate_descriptors(&desc_type, &key, network)
13791353
}
13801354
}
13811355
// Generate new mnemonic and descriptors
1382-
(false, None) => generate_new_descriptor_with_mnemonic(network, descriptor_type),
1383-
// Invalid case
1384-
(true, None) => Err(Error::Generic(
1385-
"A key is required for multipath descriptors".to_string(),
1386-
)),
1356+
None => generate_descriptor_with_mnemonic(network, &desc_type),
13871357
}
13881358
}
13891359
}?;
13901360
format_descriptor_output(&result, pretty)
13911361
}
1392-
13931362
#[cfg(any(
13941363
feature = "electrum",
13951364
feature = "esplora",

0 commit comments

Comments
 (0)