Skip to content

Commit 1a3a944

Browse files
committed
Change try_into_translator_err to expect_translator_err
1 parent a3019c7 commit 1a3a944

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
@@ -584,10 +584,8 @@ impl Descriptor<DescriptorPublicKey> {
584584

585585
translate_hash_clone!(DescriptorPublicKey, DescriptorPublicKey, ConversionError);
586586
}
587-
self.translate_pk(&mut Derivator(index)).map_err(|e| {
588-
e.try_into_translator_err()
589-
.expect("No Context errors while translating")
590-
})
587+
self.translate_pk(&mut Derivator(index))
588+
.map_err(|e| e.expect_translator_err("No Context errors while translating"))
591589
}
592590

593591
#[deprecated(note = "use at_derivation_index instead")]
@@ -702,8 +700,7 @@ impl Descriptor<DescriptorPublicKey> {
702700
let descriptor = Descriptor::<String>::from_str(s)?;
703701
let descriptor = descriptor.translate_pk(&mut keymap_pk).map_err(|e| {
704702
Error::Unexpected(
705-
e.try_into_translator_err()
706-
.expect("No Outer context errors")
703+
e.expect_translator_err("No Outer context errors")
707704
.to_string(),
708705
)
709706
})?;
@@ -833,10 +830,9 @@ impl Descriptor<DescriptorPublicKey> {
833830

834831
for (i, desc) in descriptors.iter_mut().enumerate() {
835832
let mut index_choser = IndexChoser(i);
836-
*desc = desc.translate_pk(&mut index_choser).map_err(|e| {
837-
e.try_into_translator_err()
838-
.expect("No Context errors possible")
839-
})?;
833+
*desc = desc
834+
.translate_pk(&mut index_choser)
835+
.map_err(|e| e.expect_translator_err("No Context errors possible"))?;
840836
}
841837

842838
Ok(descriptors)
@@ -889,10 +885,7 @@ impl Descriptor<DefiniteDescriptorKey> {
889885
let derived = self.translate_pk(&mut Derivator(secp));
890886
match derived {
891887
Ok(derived) => Ok(derived),
892-
Err(e) => match e.try_into_translator_err() {
893-
Ok(e) => Err(e),
894-
Err(_) => unreachable!("No Context errors when deriving keys"),
895-
},
888+
Err(e) => Err(e.expect_translator_err("No Context errors when deriving keys")),
896889
}
897890
}
898891
}

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)