Rename non standard sighash error type

Error types conventionally include `Error` as a suffix.

Rename `NonStandardSighashType` to `NonStandardSighashTypeError`.

While we are at it make the inner type private to the crate, there is no
need to leak the inner values type.
This commit is contained in:
Tobin C. Harding 2023-05-18 15:11:26 +10:00
parent cdf3e30b9d
commit 22c7aa8808
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
3 changed files with 12 additions and 12 deletions

View File

@ -13,7 +13,7 @@ use secp256k1;
use crate::prelude::*;
use crate::script::PushBytes;
use crate::sighash::{EcdsaSighashType, NonStandardSighashType};
use crate::sighash::{EcdsaSighashType, NonStandardSighashTypeError};
const MAX_SIG_LEN: usize = 73;
@ -226,8 +226,8 @@ impl From<secp256k1::Error> for Error {
fn from(e: secp256k1::Error) -> Error { Error::Secp256k1(e) }
}
impl From<NonStandardSighashType> for Error {
fn from(err: NonStandardSighashType) -> Self { Error::NonStandardSighashType(err.0) }
impl From<NonStandardSighashTypeError> for Error {
fn from(err: NonStandardSighashTypeError) -> Self { Error::NonStandardSighashType(err.0) }
}
impl From<hex::HexToBytesError> for Error {

View File

@ -446,7 +446,7 @@ impl EcdsaSighashType {
/// # Errors
///
/// If `n` is a non-standard sighash value.
pub fn from_standard(n: u32) -> Result<EcdsaSighashType, NonStandardSighashType> {
pub fn from_standard(n: u32) -> Result<EcdsaSighashType, NonStandardSighashTypeError> {
use EcdsaSighashType::*;
match n {
@ -457,7 +457,7 @@ impl EcdsaSighashType {
0x81 => Ok(AllPlusAnyoneCanPay),
0x82 => Ok(NonePlusAnyoneCanPay),
0x83 => Ok(SinglePlusAnyoneCanPay),
non_standard => Err(NonStandardSighashType(non_standard)),
non_standard => Err(NonStandardSighashTypeError(non_standard)),
}
}
@ -518,15 +518,15 @@ impl TapSighashType {
/// This type is consensus valid but an input including it would prevent the transaction from
/// being relayed on today's Bitcoin network.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NonStandardSighashType(pub u32);
pub struct NonStandardSighashTypeError(pub u32);
impl fmt::Display for NonStandardSighashType {
impl fmt::Display for NonStandardSighashTypeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Non standard sighash type {}", self.0)
}
}
impl_std_error!(NonStandardSighashType);
impl_std_error!(NonStandardSighashTypeError);
/// Error returned for failure during parsing one of the sighash types.
///

View File

@ -18,7 +18,7 @@ use crate::psbt::map::Map;
use crate::psbt::serialize::Deserialize;
use crate::psbt::{self, error, raw, Error};
use crate::sighash::{
self, EcdsaSighashType, NonStandardSighashType, SighashTypeParseError, TapSighashType,
self, EcdsaSighashType, NonStandardSighashTypeError, SighashTypeParseError, TapSighashType,
};
use crate::taproot::{ControlBlock, LeafVersion, TapLeafHash, TapNodeHash};
@ -190,7 +190,7 @@ impl From<TapSighashType> for PsbtSighashType {
impl PsbtSighashType {
/// Returns the [`EcdsaSighashType`] if the [`PsbtSighashType`] can be
/// converted to one.
pub fn ecdsa_hash_ty(self) -> Result<EcdsaSighashType, NonStandardSighashType> {
pub fn ecdsa_hash_ty(self) -> Result<EcdsaSighashType, NonStandardSighashTypeError> {
EcdsaSighashType::from_standard(self.inner)
}
@ -223,7 +223,7 @@ impl Input {
/// # Errors
///
/// If the `sighash_type` field is set to a non-standard ECDSA sighash value.
pub fn ecdsa_hash_ty(&self) -> Result<EcdsaSighashType, NonStandardSighashType> {
pub fn ecdsa_hash_ty(&self) -> Result<EcdsaSighashType, NonStandardSighashTypeError> {
self.sighash_type
.map(|sighash_type| sighash_type.ecdsa_hash_ty())
.unwrap_or(Ok(EcdsaSighashType::All))
@ -575,7 +575,7 @@ mod test {
let back = PsbtSighashType::from_str(&s).unwrap();
assert_eq!(back, sighash);
assert_eq!(back.ecdsa_hash_ty(), Err(NonStandardSighashType(nonstd)));
assert_eq!(back.ecdsa_hash_ty(), Err(sighash::NonStandardSighashTypeError(nonstd)));
assert_eq!(back.taproot_hash_ty(), Err(sighash::Error::InvalidSighashType(nonstd)));
}
}