Skip to content

Commit b90cdda

Browse files
committed
Change try_into_translator_err to expect_translator_err
1 parent be07a9c commit b90cdda

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

src/descriptor/mod.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,8 @@ impl Descriptor<DescriptorPublicKey> {
581581

582582
translate_hash_clone!(DescriptorPublicKey, DescriptorPublicKey, ConversionError);
583583
}
584-
self.translate_pk(&mut Derivator(index)).map_err(|e| {
585-
e.try_into_translator_err()
586-
.expect("No Context errors while translating")
587-
})
584+
self.translate_pk(&mut Derivator(index))
585+
.map_err(|e| e.expect_translator_err("No Context errors while translating"))
588586
}
589587

590588
#[deprecated(note = "use at_derivation_index instead")]
@@ -699,8 +697,7 @@ impl Descriptor<DescriptorPublicKey> {
699697
let descriptor = Descriptor::<String>::from_str(s)?;
700698
let descriptor = descriptor.translate_pk(&mut keymap_pk).map_err(|e| {
701699
Error::Unexpected(
702-
e.try_into_translator_err()
703-
.expect("No Outer context errors")
700+
e.expect_translator_err("No Outer context errors")
704701
.to_string(),
705702
)
706703
})?;
@@ -830,10 +827,9 @@ impl Descriptor<DescriptorPublicKey> {
830827

831828
for (i, desc) in descriptors.iter_mut().enumerate() {
832829
let mut index_choser = IndexChoser(i);
833-
*desc = desc.translate_pk(&mut index_choser).map_err(|e| {
834-
e.try_into_translator_err()
835-
.expect("No Context errors possible")
836-
})?;
830+
*desc = desc
831+
.translate_pk(&mut index_choser)
832+
.map_err(|e| e.expect_translator_err("No Context errors possible"))?;
837833
}
838834

839835
Ok(descriptors)
@@ -886,10 +882,7 @@ impl Descriptor<DefiniteDescriptorKey> {
886882
let derived = self.translate_pk(&mut Derivator(secp));
887883
match derived {
888884
Ok(derived) => Ok(derived),
889-
Err(e) => match e.try_into_translator_err() {
890-
Ok(e) => Err(e),
891-
Err(_) => unreachable!("No Context errors when deriving keys"),
892-
},
885+
Err(e) => Err(e.expect_translator_err("No Context errors when deriving keys")),
893886
}
894887
}
895888
}

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,14 @@ impl<E> TranslateErr<E> {
391391
/// - Translating into multi-path descriptors should have same number of path
392392
/// for all the keys in the descriptor
393393
///
394-
/// # Errors
394+
/// # Panics
395395
///
396-
/// This function will return an error if the Error is OutError.
397-
pub fn try_into_translator_err(self) -> Result<E, Self> {
396+
/// This function will panic if the Error is OutError.
397+
pub fn expect_translator_err(self, msg: &str) -> E {
398398
if let Self::TranslatorErr(v) = self {
399-
Ok(v)
399+
v
400400
} else {
401-
Err(self)
401+
panic!("{}", msg)
402402
}
403403
}
404404
}

src/psbt/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,10 +1238,7 @@ fn update_item_with_descriptor_helper<F: PsbtFields>(
12381238
let mut bip32_derivation = KeySourceLookUp(BTreeMap::new(), Secp256k1::verification_only());
12391239
let derived = descriptor
12401240
.translate_pk(&mut bip32_derivation)
1241-
.map_err(|e| {
1242-
e.try_into_translator_err()
1243-
.expect("No Outer Context errors in translations")
1244-
})?;
1241+
.map_err(|e| e.expect_translator_err("No Outer Context errors in translations"))?;
12451242

12461243
if let Some(check_script) = check_script {
12471244
if check_script != &derived.script_pubkey() {

0 commit comments

Comments
 (0)