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:
parent
cdf3e30b9d
commit
22c7aa8808
|
@ -13,7 +13,7 @@ use secp256k1;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::script::PushBytes;
|
use crate::script::PushBytes;
|
||||||
use crate::sighash::{EcdsaSighashType, NonStandardSighashType};
|
use crate::sighash::{EcdsaSighashType, NonStandardSighashTypeError};
|
||||||
|
|
||||||
const MAX_SIG_LEN: usize = 73;
|
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) }
|
fn from(e: secp256k1::Error) -> Error { Error::Secp256k1(e) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<NonStandardSighashType> for Error {
|
impl From<NonStandardSighashTypeError> for Error {
|
||||||
fn from(err: NonStandardSighashType) -> Self { Error::NonStandardSighashType(err.0) }
|
fn from(err: NonStandardSighashTypeError) -> Self { Error::NonStandardSighashType(err.0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<hex::HexToBytesError> for Error {
|
impl From<hex::HexToBytesError> for Error {
|
||||||
|
|
|
@ -446,7 +446,7 @@ impl EcdsaSighashType {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// If `n` is a non-standard sighash value.
|
/// 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::*;
|
use EcdsaSighashType::*;
|
||||||
|
|
||||||
match n {
|
match n {
|
||||||
|
@ -457,7 +457,7 @@ impl EcdsaSighashType {
|
||||||
0x81 => Ok(AllPlusAnyoneCanPay),
|
0x81 => Ok(AllPlusAnyoneCanPay),
|
||||||
0x82 => Ok(NonePlusAnyoneCanPay),
|
0x82 => Ok(NonePlusAnyoneCanPay),
|
||||||
0x83 => Ok(SinglePlusAnyoneCanPay),
|
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
|
/// This type is consensus valid but an input including it would prevent the transaction from
|
||||||
/// being relayed on today's Bitcoin network.
|
/// being relayed on today's Bitcoin network.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[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 {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "Non standard sighash type {}", self.0)
|
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.
|
/// Error returned for failure during parsing one of the sighash types.
|
||||||
///
|
///
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::psbt::map::Map;
|
||||||
use crate::psbt::serialize::Deserialize;
|
use crate::psbt::serialize::Deserialize;
|
||||||
use crate::psbt::{self, error, raw, Error};
|
use crate::psbt::{self, error, raw, Error};
|
||||||
use crate::sighash::{
|
use crate::sighash::{
|
||||||
self, EcdsaSighashType, NonStandardSighashType, SighashTypeParseError, TapSighashType,
|
self, EcdsaSighashType, NonStandardSighashTypeError, SighashTypeParseError, TapSighashType,
|
||||||
};
|
};
|
||||||
use crate::taproot::{ControlBlock, LeafVersion, TapLeafHash, TapNodeHash};
|
use crate::taproot::{ControlBlock, LeafVersion, TapLeafHash, TapNodeHash};
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ impl From<TapSighashType> for PsbtSighashType {
|
||||||
impl PsbtSighashType {
|
impl PsbtSighashType {
|
||||||
/// Returns the [`EcdsaSighashType`] if the [`PsbtSighashType`] can be
|
/// Returns the [`EcdsaSighashType`] if the [`PsbtSighashType`] can be
|
||||||
/// converted to one.
|
/// 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)
|
EcdsaSighashType::from_standard(self.inner)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ impl Input {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// If the `sighash_type` field is set to a non-standard ECDSA sighash value.
|
/// 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
|
self.sighash_type
|
||||||
.map(|sighash_type| sighash_type.ecdsa_hash_ty())
|
.map(|sighash_type| sighash_type.ecdsa_hash_ty())
|
||||||
.unwrap_or(Ok(EcdsaSighashType::All))
|
.unwrap_or(Ok(EcdsaSighashType::All))
|
||||||
|
@ -575,7 +575,7 @@ mod test {
|
||||||
let back = PsbtSighashType::from_str(&s).unwrap();
|
let back = PsbtSighashType::from_str(&s).unwrap();
|
||||||
|
|
||||||
assert_eq!(back, sighash);
|
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)));
|
assert_eq!(back.taproot_hash_ty(), Err(sighash::Error::InvalidSighashType(nonstd)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue