Skip to content

Commit 8f6ed4d

Browse files
committed
get rid of unneeded errors
1 parent a6b469a commit 8f6ed4d

File tree

3 files changed

+6
-30
lines changed

3 files changed

+6
-30
lines changed

lightning-invoice/src/de.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -556,34 +556,24 @@ impl FromBase32 for Fallback {
556556
return Err(ParseError::InvalidSegWitProgramLength);
557557
}
558558

559-
let version = match WitnessVersion::try_from(version) {
560-
Ok(version) => version,
561-
Err(_) => return Err(ParseError::InvalidSegWitVersion),
562-
};
563-
559+
let version = WitnessVersion::try_from(version).expect("0 through 16 are valid SegWit versions");
564560
Ok(Fallback::SegWitProgram {
565561
version: version,
566562
program: bytes
567563
})
568564
},
569565
17 => {
570-
if bytes.len() != 20 {
571-
return Err(ParseError::InvalidPubKeyHashLength);
572-
}
573566
let pkh = match PubkeyHash::from_slice(&bytes) {
574567
Ok(pkh) => pkh,
575-
Err(_) => return Err(ParseError::InvalidPubKeyHash),
568+
Err(bitcoin_hashes::Error::InvalidLength(_, _)) => return Err(ParseError::InvalidPubKeyHashLength),
576569
};
577570

578571
Ok(Fallback::PubKeyHash(pkh))
579572
}
580573
18 => {
581-
if bytes.len() != 20 {
582-
return Err(ParseError::InvalidScriptHashLength);
583-
}
584574
let sh = match ScriptHash::from_slice(&bytes) {
585575
Ok(sh) => sh,
586-
Err(_) => return Err(ParseError::InvalidScriptHash),
576+
Err(bitcoin_hashes::Error::InvalidLength(_, _)) => return Err(ParseError::InvalidScriptHashLength),
587577
};
588578

589579
Ok(Fallback::ScriptHash(sh))
@@ -668,21 +658,12 @@ impl Display for ParseError {
668658
ParseError::InvalidSegWitProgramLength => {
669659
f.write_str("fallback SegWit program is too long or too short")
670660
},
671-
ParseError::InvalidSegWitVersion => {
672-
f.write_str("fallback SegWit version is not valid")
673-
},
674661
ParseError::InvalidPubKeyHashLength => {
675662
f.write_str("fallback public key hash has a length unequal 20 bytes")
676663
},
677-
ParseError::InvalidPubKeyHash => {
678-
f.write_str("fallback public key hash is not a valid")
679-
},
680664
ParseError::InvalidScriptHashLength => {
681665
f.write_str("fallback script hash has a length unequal 32 bytes")
682666
},
683-
ParseError::InvalidScriptHash => {
684-
f.write_str("fallback script hash is not a valid")
685-
},
686667
ParseError::InvalidRecoveryId => {
687668
f.write_str("recovery id is out of range (should be in [0,3])")
688669
},

lightning-invoice/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,8 @@ pub enum ParseError {
122122
PaddingError,
123123
IntegerOverflowError,
124124
InvalidSegWitProgramLength,
125-
InvalidSegWitVersion,
126125
InvalidPubKeyHashLength,
127-
InvalidPubKeyHash,
128126
InvalidScriptHashLength,
129-
InvalidScriptHash,
130127
InvalidRecoveryId,
131128
InvalidSliceLength(String),
132129

@@ -1263,8 +1260,6 @@ impl Invoice {
12631260
///
12641261
/// (C-not exported) as we don't support Vec<&NonOpaqueType>
12651262
pub fn fallbacks(&self) -> Vec<&Fallback> {
1266-
1267-
12681263
self.signed_invoice.fallbacks()
12691264
}
12701265

@@ -1284,10 +1279,10 @@ impl Invoice {
12841279
Script::new_witness_program(*version, program.as_slice())
12851280
}
12861281
Fallback::PubKeyHash(pkh) => {
1287-
Script::new_p2pkh(&pkh)
1282+
Script::new_p2pkh(pkh)
12881283
}
12891284
Fallback::ScriptHash(sh) => {
1290-
Script::new_p2sh(&sh)
1285+
Script::new_p2sh(sh)
12911286
}
12921287
};
12931288

lightning-invoice/src/ser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl ToBase32 for Fallback {
329329
fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
330330
match *self {
331331
Fallback::SegWitProgram {version: v, program: ref p} => {
332-
writer.write_u5(u5::try_from_u8(v.to_num()).expect("0-16 < 32"))?;
332+
writer.write_u5(Into::<u5>::into(v))?;
333333
p.write_base32(writer)
334334
},
335335
Fallback::PubKeyHash(ref hash) => {

0 commit comments

Comments
 (0)