Skip to content

Commit 4f8b065

Browse files
committed
descriptor: fix key parsing error handling in parse_desc
1 parent 7c651f4 commit 4f8b065

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/descriptor/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,12 +725,9 @@ impl Descriptor<DescriptorPublicKey> {
725725
}
726726

727727
let descriptor = Descriptor::<String>::from_str(s)?;
728-
let descriptor = descriptor.translate_pk(&mut keymap_pk).map_err(|e| {
729-
Error::Unexpected(
730-
e.expect_translator_err("No Outer context errors")
731-
.to_string(),
732-
)
733-
})?;
728+
let descriptor = descriptor
729+
.translate_pk(&mut keymap_pk)
730+
.map_err(TranslateErr::flatten)?;
734731

735732
Ok((descriptor, keymap_pk.0))
736733
}

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,17 @@ impl<E> TranslateErr<E> {
348348
}
349349
}
350350

351+
impl TranslateErr<Error> {
352+
/// If we are doing a translation where our "outer error" is the generic
353+
/// Miniscript error, eliminate the `TranslateErr` type which is just noise.
354+
pub fn flatten(self) -> Error {
355+
match self {
356+
Self::TranslatorErr(e) => e,
357+
Self::OuterError(e) => e,
358+
}
359+
}
360+
}
361+
351362
impl<E> From<E> for TranslateErr<E> {
352363
fn from(v: E) -> Self { Self::TranslatorErr(v) }
353364
}

0 commit comments

Comments
 (0)