Skip to content

Commit b0677c8

Browse files
committed
Use NoData instead of MissingWitnessVersion
In the `SegwitHrpstringError` we return the `MissingWitnessVersion` variant when the encoded data is empty. While true, the witness version is missing this error is not totally descriptive because the error case is more specific than that. Rename `SegwitHrpstringError::MissingWitnessVersion` to `SegwitHrpstringError::NoData`.
1 parent 0167421 commit b0677c8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/primitives/decode.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl<'s> CheckedHrpstring<'s> {
271271
#[inline]
272272
pub fn validate_segwit(mut self) -> Result<SegwitHrpstring<'s>, SegwitHrpstringError> {
273273
if self.data.is_empty() {
274-
return Err(SegwitHrpstringError::MissingWitnessVersion);
274+
return Err(SegwitHrpstringError::NoData);
275275
}
276276
// Unwrap ok since check_characters checked the bech32-ness of this char.
277277
let witness_version = Fe32::from_char(self.data[0].into()).unwrap();
@@ -371,7 +371,7 @@ impl<'s> SegwitHrpstring<'s> {
371371
let unchecked = UncheckedHrpstring::new(s)?;
372372

373373
if unchecked.data.is_empty() {
374-
return Err(SegwitHrpstringError::MissingWitnessVersion);
374+
return Err(SegwitHrpstringError::NoData);
375375
}
376376

377377
// Unwrap ok since check_characters (in `Self::new`) checked the bech32-ness of this char.
@@ -549,8 +549,8 @@ where
549549
pub enum SegwitHrpstringError {
550550
/// Error while parsing the encoded address string.
551551
Unchecked(UncheckedHrpstringError),
552-
/// The witness version byte is missing.
553-
MissingWitnessVersion,
552+
/// No data found after removing the checksum.
553+
NoData,
554554
/// Invalid witness version (must be 0-16 inclusive).
555555
InvalidWitnessVersion(Fe32),
556556
/// Invalid padding on the witness data.
@@ -567,7 +567,7 @@ impl fmt::Display for SegwitHrpstringError {
567567

568568
match *self {
569569
Unchecked(ref e) => write_err!(f, "parsing unchecked hrpstring failed"; e),
570-
MissingWitnessVersion => write!(f, "the witness version byte is missing"),
570+
NoData => write!(f, "no data found after removing the checksum"),
571571
InvalidWitnessVersion(fe) => write!(f, "invalid segwit witness version: {}", fe),
572572
Padding(ref e) => write_err!(f, "invalid padding on the witness data"; e),
573573
WitnessLength(ref e) => write_err!(f, "invalid witness length"; e),
@@ -586,7 +586,7 @@ impl std::error::Error for SegwitHrpstringError {
586586
Padding(ref e) => Some(e),
587587
WitnessLength(ref e) => Some(e),
588588
Checksum(ref e) => Some(e),
589-
MissingWitnessVersion | InvalidWitnessVersion(_) => None,
589+
NoData | InvalidWitnessVersion(_) => None,
590590
}
591591
}
592592
}

0 commit comments

Comments
 (0)