Rename NonStandardSigHashType -> NonStandardSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash' is a well known word in the Bitcoin ecosystem it should appear in identifiers as `Sighash`. Rename the `NonStandardSigHashType` type and error variant to `NonStandardSighashType`.
This commit is contained in:
parent
130e27349e
commit
c19ec339ef
|
@ -723,9 +723,9 @@ impl Decodable for Transaction {
|
|||
/// 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 NonStandardSighashType(pub u32);
|
||||
|
||||
impl fmt::Display for NonStandardSigHashType {
|
||||
impl fmt::Display for NonStandardSighashType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Non standard sighash type {}", self.0)
|
||||
}
|
||||
|
@ -733,7 +733,7 @@ impl fmt::Display for NonStandardSigHashType {
|
|||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
|
||||
impl error::Error for NonStandardSigHashType {}
|
||||
impl error::Error for NonStandardSighashType {}
|
||||
|
||||
/// Legacy Hashtype of an input's signature
|
||||
#[deprecated(since = "0.28.0", note = "Please use [`EcdsaSighashType`] instead")]
|
||||
|
@ -843,7 +843,7 @@ impl EcdsaSighashType {
|
|||
|
||||
/// Creates a [`EcdsaSighashType`] from a raw `u32`.
|
||||
#[deprecated(since="0.28.0", note="please use `from_standard`")]
|
||||
pub fn from_u32_standard(n: u32) -> Result<EcdsaSighashType, NonStandardSigHashType> {
|
||||
pub fn from_u32_standard(n: u32) -> Result<EcdsaSighashType, NonStandardSighashType> {
|
||||
EcdsaSighashType::from_standard(n)
|
||||
}
|
||||
|
||||
|
@ -852,7 +852,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, NonStandardSighashType> {
|
||||
match n {
|
||||
// Standard sighashes, see https://github.com/bitcoin/bitcoin/blob/b805dbb0b9c90dadef0424e5b3bf86ac308e103e/src/script/interpreter.cpp#L189-L198
|
||||
0x01 => Ok(EcdsaSighashType::All),
|
||||
|
@ -861,7 +861,7 @@ impl EcdsaSighashType {
|
|||
0x81 => Ok(EcdsaSighashType::AllPlusAnyoneCanPay),
|
||||
0x82 => Ok(EcdsaSighashType::NonePlusAnyoneCanPay),
|
||||
0x83 => Ok(EcdsaSighashType::SinglePlusAnyoneCanPay),
|
||||
non_standard => Err(NonStandardSigHashType(non_standard))
|
||||
non_standard => Err(NonStandardSighashType(non_standard))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1202,7 +1202,7 @@ mod tests {
|
|||
// This type is not well defined, by consensus it becomes ALL
|
||||
assert_eq!(EcdsaSighashType::from_u32_consensus(nonstandard_hashtype), EcdsaSighashType::All);
|
||||
// But it's policy-invalid to use it!
|
||||
assert_eq!(EcdsaSighashType::from_u32_standard(nonstandard_hashtype), Err(NonStandardSigHashType(0x04)));
|
||||
assert_eq!(EcdsaSighashType::from_u32_standard(nonstandard_hashtype), Err(NonStandardSighashType(0x04)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -20,7 +20,7 @@ use prelude::*;
|
|||
use core::str::FromStr;
|
||||
use core::{fmt, iter};
|
||||
use hashes::hex::{self, FromHex};
|
||||
use blockdata::transaction::NonStandardSigHashType;
|
||||
use blockdata::transaction::NonStandardSighashType;
|
||||
use secp256k1;
|
||||
use EcdsaSighashType;
|
||||
|
||||
|
@ -48,7 +48,7 @@ impl EcdsaSig {
|
|||
let (hash_ty, sig) = sl.split_last()
|
||||
.ok_or(EcdsaSigError::EmptySignature)?;
|
||||
let hash_ty = EcdsaSighashType::from_standard(*hash_ty as u32)
|
||||
.map_err(|_| EcdsaSigError::NonStandardSigHashType(*hash_ty as u32))?;
|
||||
.map_err(|_| EcdsaSigError::NonStandardSighashType(*hash_ty as u32))?;
|
||||
let sig = secp256k1::ecdsa::Signature::from_der(sig)
|
||||
.map_err(EcdsaSigError::Secp256k1)?;
|
||||
Ok(EcdsaSig { sig, hash_ty })
|
||||
|
@ -91,7 +91,7 @@ pub enum EcdsaSigError {
|
|||
/// Hex encoding error
|
||||
HexEncoding(hex::Error),
|
||||
/// Base58 encoding error
|
||||
NonStandardSigHashType(u32),
|
||||
NonStandardSighashType(u32),
|
||||
/// Empty Signature
|
||||
EmptySignature,
|
||||
/// secp256k1-related error
|
||||
|
@ -102,7 +102,7 @@ pub enum EcdsaSigError {
|
|||
impl fmt::Display for EcdsaSigError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
EcdsaSigError::NonStandardSigHashType(hash_ty) =>
|
||||
EcdsaSigError::NonStandardSighashType(hash_ty) =>
|
||||
write!(f, "Non standard signature hash type {}", hash_ty),
|
||||
EcdsaSigError::Secp256k1(ref e) =>
|
||||
write!(f, "Invalid Ecdsa signature: {}", e),
|
||||
|
@ -123,9 +123,9 @@ impl From<secp256k1::Error> for EcdsaSigError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<NonStandardSigHashType> for EcdsaSigError {
|
||||
fn from(err: NonStandardSigHashType) -> Self {
|
||||
EcdsaSigError::NonStandardSigHashType(err.0)
|
||||
impl From<NonStandardSighashType> for EcdsaSigError {
|
||||
fn from(err: NonStandardSighashType) -> Self {
|
||||
EcdsaSigError::NonStandardSighashType(err.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ pub enum Error {
|
|||
actual: Box<Transaction>,
|
||||
},
|
||||
/// Unable to parse as a standard SigHash type.
|
||||
NonStandardSigHashType(u32),
|
||||
NonStandardSighashType(u32),
|
||||
/// Parsing errors from bitcoin_hashes
|
||||
HashParseError(hashes::Error),
|
||||
/// The pre-image must hash to the correponding psbt hash
|
||||
|
@ -88,7 +88,7 @@ impl fmt::Display for Error {
|
|||
Error::InvalidProprietaryKey => write!(f, "non-proprietary key type found when proprietary key was expected"),
|
||||
Error::DuplicateKey(ref rkey) => write!(f, "duplicate key: {}", rkey),
|
||||
Error::UnexpectedUnsignedTx { expected: ref e, actual: ref a } => write!(f, "different unsigned transaction: expected {}, actual {}", e.txid(), a.txid()),
|
||||
Error::NonStandardSigHashType(ref sht) => write!(f, "non-standard sighash type: {}", sht),
|
||||
Error::NonStandardSighashType(ref sht) => write!(f, "non-standard sighash type: {}", sht),
|
||||
Error::InvalidMagic => f.write_str("invalid magic"),
|
||||
Error::InvalidSeparator => f.write_str("invalid separator"),
|
||||
Error::UnsignedTxHasScriptSigs => f.write_str("the unsigned transaction has script sigs"),
|
||||
|
|
|
@ -20,7 +20,7 @@ use core::str::FromStr;
|
|||
use secp256k1;
|
||||
use blockdata::script::Script;
|
||||
use blockdata::witness::Witness;
|
||||
use blockdata::transaction::{Transaction, TxOut, NonStandardSigHashType, SighashTypeParseError};
|
||||
use blockdata::transaction::{Transaction, TxOut, NonStandardSighashType, SighashTypeParseError};
|
||||
use consensus::encode;
|
||||
use hashes::{self, hash160, ripemd160, sha256, sha256d};
|
||||
use secp256k1::XOnlyPublicKey;
|
||||
|
@ -206,7 +206,7 @@ impl From<SchnorrSighashType> 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, NonStandardSighashType> {
|
||||
EcdsaSighashType::from_standard(self.inner)
|
||||
}
|
||||
|
||||
|
@ -244,7 +244,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, NonStandardSighashType> {
|
||||
self.sighash_type
|
||||
.map(|sighash_type| sighash_type.ecdsa_hash_ty())
|
||||
.unwrap_or(Ok(EcdsaSighashType::All))
|
||||
|
@ -600,7 +600,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(NonStandardSighashType(nonstd)));
|
||||
assert_eq!(back.schnorr_hash_ty(), Err(sighash::Error::InvalidSigHashType(nonstd)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,8 +130,8 @@ impl Deserialize for EcdsaSig {
|
|||
EcdsaSigError::EmptySignature => {
|
||||
encode::Error::ParseFailed("Empty partial signature data")
|
||||
}
|
||||
EcdsaSigError::NonStandardSigHashType(flag) => {
|
||||
encode::Error::from(psbt::Error::NonStandardSigHashType(flag))
|
||||
EcdsaSigError::NonStandardSighashType(flag) => {
|
||||
encode::Error::from(psbt::Error::NonStandardSighashType(flag))
|
||||
}
|
||||
EcdsaSigError::Secp256k1(..) => {
|
||||
encode::Error::ParseFailed("Invalid Ecdsa signature")
|
||||
|
@ -229,7 +229,7 @@ impl Deserialize for schnorr::SchnorrSig {
|
|||
schnorr::SchnorrSig::from_slice(&bytes)
|
||||
.map_err(|e| match e {
|
||||
schnorr::SchnorrSigError::InvalidSighashType(flag) => {
|
||||
encode::Error::from(psbt::Error::NonStandardSigHashType(flag as u32))
|
||||
encode::Error::from(psbt::Error::NonStandardSighashType(flag as u32))
|
||||
}
|
||||
schnorr::SchnorrSigError::InvalidSchnorrSigSize(_) => {
|
||||
encode::Error::ParseFailed("Invalid Schnorr signature length")
|
||||
|
|
Loading…
Reference in New Issue