Skip to content

Commit 9ae0172

Browse files
committed
Merge #832: backport #830 to rust-miniscript 11.x
cfa85be bump version to 11.2.2 (Andrew Poelstra) f652949 descriptor: add unit tests for constructing multipath keys (Andrew Poelstra) c07272a DefiniteDescriptorKey: disallow multipath keys (Andrew Poelstra) Pull request description: Just the logic fix; the error refactoring doesn't apply. ACKs for top commit: sanket1729: utACK cfa85be Tree-SHA512: 182c5b199c82460f80e8d9ae6bce9c0ea5905af36c372a92ad0ce189daff8b99fec7a7177f295e9101f78b5567cfcffb01bd4bfc921d8ed394878b22aa9309e2
2 parents 7b459e2 + cfa85be commit 9ae0172

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "miniscript"
3-
version = "11.2.1"
3+
version = "11.2.2"
44
authors = ["Andrew Poelstra <[email protected]>, Sanket Kanjalkar <[email protected]>"]
55
license = "CC0-1.0"
66
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"

src/descriptor/key.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ impl DefiniteDescriptorKey {
10381038
///
10391039
/// Returns `None` if the key contains a wildcard
10401040
fn new(key: DescriptorPublicKey) -> Option<Self> {
1041-
if key.has_wildcard() {
1041+
if key.has_wildcard() || key.is_multipath() {
10421042
None
10431043
} else {
10441044
Some(Self(key))
@@ -1072,7 +1072,7 @@ impl FromStr for DefiniteDescriptorKey {
10721072
fn from_str(s: &str) -> Result<Self, Self::Err> {
10731073
let inner = DescriptorPublicKey::from_str(s)?;
10741074
DefiniteDescriptorKey::new(inner).ok_or(DescriptorKeyParseError(
1075-
"cannot parse key with a wilcard as a DerivedDescriptorKey",
1075+
"cannot parse multi-path keys or keys with a wilcard as a DerivedDescriptorKey",
10761076
))
10771077
}
10781078
}
@@ -1150,7 +1150,7 @@ mod test {
11501150
DescriptorKeyParseError, DescriptorMultiXKey, DescriptorPublicKey, DescriptorSecretKey,
11511151
MiniscriptKey, Wildcard,
11521152
};
1153-
use crate::prelude::*;
1153+
use crate::{prelude::*, DefiniteDescriptorKey};
11541154

11551155
#[test]
11561156
fn parse_descriptor_key_errors() {
@@ -1498,4 +1498,23 @@ mod test {
14981498
let public_key = DescriptorPublicKey::from_str(desc).unwrap();
14991499
assert_tokens(&public_key, &[Token::String(desc)]);
15001500
}
1501+
1502+
#[test]
1503+
fn definite_keys() {
1504+
// basic xpub
1505+
let desc = "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8"
1506+
.parse::<DescriptorPublicKey>()
1507+
.unwrap();
1508+
assert!(DefiniteDescriptorKey::new(desc).is_some());
1509+
// xpub with wildcard
1510+
let desc = "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8/*"
1511+
.parse::<DescriptorPublicKey>()
1512+
.unwrap();
1513+
assert!(DefiniteDescriptorKey::new(desc).is_none());
1514+
// multipath xpub
1515+
let desc = "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8/<0;1>"
1516+
.parse::<DescriptorPublicKey>()
1517+
.unwrap();
1518+
assert!(DefiniteDescriptorKey::new(desc).is_none());
1519+
}
15011520
}

0 commit comments

Comments
 (0)