Skip to content

Commit 9e6d6c5

Browse files
committed
Merge #831: backport #830 to rust-miniscript 12.x
a3561f9 bump version to 12.3.3 (Andrew Poelstra) 08b446e descriptor: add unit tests for constructing multipath keys (Andrew Poelstra) 042cd08 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 a3561f9 Tree-SHA512: e0ddaaa2313a791330d1bc1ca7a90604f223405b4219e66a8a840d9568a4b81789866ed80839c6e22d8453af6b5fb8cb808fc9ab2ed3a51d81df5ac14b5c626b
2 parents ce9c50f + a3561f9 commit 9e6d6c5

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

Cargo-minimal.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ dependencies = [
316316

317317
[[package]]
318318
name = "miniscript"
319-
version = "12.3.2"
319+
version = "12.3.3"
320320
dependencies = [
321321
"bech32",
322322
"bitcoin",

Cargo-recent.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ dependencies = [
294294

295295
[[package]]
296296
name = "miniscript"
297-
version = "12.3.2"
297+
version = "12.3.3"
298298
dependencies = [
299299
"bech32",
300300
"bitcoin",

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 = "12.3.2"
3+
version = "12.3.3"
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ impl DefiniteDescriptorKey {
10371037
///
10381038
/// Returns `None` if the key contains a wildcard
10391039
fn new(key: DescriptorPublicKey) -> Option<Self> {
1040-
if key.has_wildcard() {
1040+
if key.has_wildcard() || key.is_multipath() {
10411041
None
10421042
} else {
10431043
Some(Self(key))
@@ -1071,7 +1071,7 @@ impl FromStr for DefiniteDescriptorKey {
10711071
fn from_str(s: &str) -> Result<Self, Self::Err> {
10721072
let inner = DescriptorPublicKey::from_str(s)?;
10731073
DefiniteDescriptorKey::new(inner).ok_or(DescriptorKeyParseError(
1074-
"cannot parse key with a wilcard as a DerivedDescriptorKey",
1074+
"cannot parse multi-path keys or keys with a wilcard as a DerivedDescriptorKey",
10751075
))
10761076
}
10771077
}
@@ -1150,6 +1150,7 @@ mod test {
11501150
MiniscriptKey, Wildcard,
11511151
};
11521152
use crate::prelude::*;
1153+
use crate::DefiniteDescriptorKey;
11531154

11541155
#[test]
11551156
fn parse_descriptor_key_errors() {
@@ -1497,4 +1498,23 @@ mod test {
14971498
let public_key = DescriptorPublicKey::from_str(desc).unwrap();
14981499
assert_tokens(&public_key, &[Token::String(desc)]);
14991500
}
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+
}
15001520
}

0 commit comments

Comments
 (0)