f8de7954b2 Remove unused pow::TryFromError type (Tobin C. Harding)
43c5eb765c Fix witness_version leaf error type (Tobin C. Harding)
2af764e859 hashes: Fix leaf error type (Tobin C. Harding)

Pull request description:

  In light of recent discussion go over the codebase and look for some places that the leaf errors are wrong. Does not do the whole code base, excludes `p2p` and a couple of other places.

ACKs for top commit:
  apoelstra:
    ACK f8de7954b2
  Kixunil:
    ACK f8de7954b2

Tree-SHA512: 2905878363869ee205cce49c58c060c712c9b7b55965ee60bb856128842968a4be86c93a194ffffdb35e215b2bea8ad33b04ee47e8e17cc784b0641ea48518e5
This commit is contained in:
Andrew Poelstra 2024-03-13 14:50:58 +00:00
commit d2617f99b2
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 16 additions and 25 deletions

View File

@ -249,10 +249,14 @@ impl From<TryFromError> for TryFromInstructionError {
/// Error attempting to create a [`WitnessVersion`] from an integer.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct TryFromError {
/// The invalid non-witness version integer.
pub invalid: u8,
invalid: u8,
}
impl TryFromError {
/// Returns the invalid non-witness version integer.
pub fn invalid_version(&self) -> u8 { self.invalid }
}
impl fmt::Display for TryFromError {
@ -262,6 +266,4 @@ impl fmt::Display for TryFromError {
}
#[cfg(feature = "std")]
impl std::error::Error for TryFromError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
}
impl std::error::Error for TryFromError {}

View File

@ -736,22 +736,6 @@ impl<T: Into<u128>> From<T> for U256 {
fn from(x: T) -> Self { U256(0, x.into()) }
}
/// Error from `TryFrom<signed type>` implementations, occurs when input is negative.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct TryFromError(i128);
impl fmt::Display for TryFromError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "attempt to create unsigned integer type from negative number: {}", self.0)
}
}
#[cfg(feature = "std")]
impl std::error::Error for TryFromError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
}
impl Add for U256 {
type Output = Self;
fn add(self, rhs: Self) -> Self {

View File

@ -234,12 +234,19 @@ pub trait Hash:
/// Attempted to create a hash from an invalid length slice.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct FromSliceError {
expected: usize,
got: usize,
}
impl FromSliceError {
/// Returns the expected slice length.
pub fn expected_length(&self) -> usize { self.expected }
/// Returns the invalid slice length.
pub fn invalid_length(&self) -> usize { self.got }
}
impl fmt::Display for FromSliceError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "invalid slice length {} (expected {})", self.got, self.expected)
@ -247,9 +254,7 @@ impl fmt::Display for FromSliceError {
}
#[cfg(feature = "std")]
impl std::error::Error for FromSliceError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
}
impl std::error::Error for FromSliceError {}
#[cfg(test)]
mod tests {