Skip to content

Commit 4823d86

Browse files
committed
descriptor: fix key parsing error handling in parse_desc
1 parent 9d658a9 commit 4823d86

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
@@ -731,12 +731,9 @@ impl Descriptor<DescriptorPublicKey> {
731731
}
732732

733733
let descriptor = Descriptor::<String>::from_str(s)?;
734-
let descriptor = descriptor.translate_pk(&mut keymap_pk).map_err(|e| {
735-
Error::Unexpected(
736-
e.expect_translator_err("No Outer context errors")
737-
.to_string(),
738-
)
739-
})?;
734+
let descriptor = descriptor
735+
.translate_pk(&mut keymap_pk)
736+
.map_err(TranslateErr::flatten)?;
740737

741738
Ok((descriptor, keymap_pk.0))
742739
}

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,17 @@ impl<E> TranslateErr<E> {
358358
}
359359
}
360360

361+
impl TranslateErr<Error> {
362+
/// If we are doing a translation where our "outer error" is the generic
363+
/// Miniscript error, eliminate the `TranslateErr` type which is just noise.
364+
pub fn flatten(self) -> Error {
365+
match self {
366+
Self::TranslatorErr(e) => e,
367+
Self::OuterError(e) => e,
368+
}
369+
}
370+
}
371+
361372
impl<E> From<E> for TranslateErr<E> {
362373
fn from(v: E) -> Self { Self::TranslatorErr(v) }
363374
}

0 commit comments

Comments
 (0)