Skip to content

Commit 95cee08

Browse files
committed
descriptor: fix key parsing error handling in parse_desc
1 parent 18e03ed commit 95cee08

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/descriptor/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,9 @@ impl Descriptor<DescriptorPublicKey> {
695695
}
696696

697697
let descriptor = Descriptor::<String>::from_str(s)?;
698-
let descriptor = descriptor.translate_pk(&mut keymap_pk).map_err(|e| {
699-
Error::Unexpected(
700-
e.expect_translator_err("No Outer context errors")
701-
.to_string(),
702-
)
703-
})?;
698+
let descriptor = descriptor
699+
.translate_pk(&mut keymap_pk)
700+
.map_err(TranslateErr::flatten)?;
704701

705702
Ok((descriptor, keymap_pk.0))
706703
}

src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,17 @@ impl<E> TranslateErr<E> {
399399
}
400400
}
401401

402+
impl TranslateErr<Error> {
403+
/// If we are doing a translation where our "outer error" is the generic
404+
/// Miniscript error, eliminate the `TranslateErr` type which is just noise.
405+
pub fn flatten(self) -> Error {
406+
match self {
407+
Self::TranslatorErr(e) => e,
408+
Self::OuterError(e) => e,
409+
}
410+
}
411+
}
412+
402413
impl<E> From<E> for TranslateErr<E> {
403414
fn from(v: E) -> Self {
404415
Self::TranslatorErr(v)

0 commit comments

Comments
 (0)