Rename existing SigHashType to EcdsaSigHashType

This commit is contained in:
sanket1729 2021-11-15 12:55:24 -08:00
parent 648b3975a5
commit 94cfe79170
8 changed files with 104 additions and 99 deletions

View File

@ -333,10 +333,10 @@ impl Transaction {
let sighash_type : u32 = sighash_type.into();
assert!(input_index < self.input.len()); // Panic on OOB
let (sighash, anyone_can_pay) = SigHashType::from_u32_consensus(sighash_type).split_anyonecanpay_flag();
let (sighash, anyone_can_pay) = EcdsaSigHashType::from_u32_consensus(sighash_type).split_anyonecanpay_flag();
// Special-case sighash_single bug because this is easy enough.
if sighash == SigHashType::Single && input_index >= self.output.len() {
if sighash == EcdsaSigHashType::Single && input_index >= self.output.len() {
writer.write_all(&[1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
@ -365,22 +365,22 @@ impl Transaction {
tx.input.push(TxIn {
previous_output: input.previous_output,
script_sig: if n == input_index { script_pubkey.clone() } else { Script::new() },
sequence: if n != input_index && (sighash == SigHashType::Single || sighash == SigHashType::None) { 0 } else { input.sequence },
sequence: if n != input_index && (sighash == EcdsaSigHashType::Single || sighash == EcdsaSigHashType::None) { 0 } else { input.sequence },
witness: vec![],
});
}
}
// ..then all outputs
tx.output = match sighash {
SigHashType::All => self.output.clone(),
SigHashType::Single => {
EcdsaSigHashType::All => self.output.clone(),
EcdsaSigHashType::Single => {
let output_iter = self.output.iter()
.take(input_index + 1) // sign all outputs up to and including this one, but erase
.enumerate() // all of them except for this one
.map(|(n, out)| if n == input_index { out.clone() } else { TxOut::default() });
output_iter.collect()
}
SigHashType::None => vec![],
EcdsaSigHashType::None => vec![],
_ => unreachable!()
};
// hash the result
@ -673,10 +673,15 @@ impl fmt::Display for NonStandardSigHashType {
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl error::Error for NonStandardSigHashType {}
/// Legacy Hashtype of an input's signature
#[deprecated(since="0.28.0", note="Please use [`EcdsaSigHashType`] instead")]
pub type SigHashType = EcdsaSigHashType;
/// Hashtype of an input's signature, encoded in the last byte of the signature
/// Fixed values so they can be casted as integer types for encoding
/// See also [`crate::SchnorrSigHashType`]
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
pub enum SigHashType {
pub enum EcdsaSigHashType {
/// 0x1: Sign all outputs
All = 0x01,
/// 0x2: Sign no outputs --- anyone can choose the destination
@ -693,54 +698,54 @@ pub enum SigHashType {
/// 0x83: Sign one output and only this input (see `Single` for what "one output" means)
SinglePlusAnyoneCanPay = 0x83
}
serde_string_impl!(SigHashType, "a SigHashType data");
serde_string_impl!(EcdsaSigHashType, "a EcdsaSigHashType data");
impl fmt::Display for SigHashType {
impl fmt::Display for EcdsaSigHashType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
SigHashType::All => "SIGHASH_ALL",
SigHashType::None => "SIGHASH_NONE",
SigHashType::Single => "SIGHASH_SINGLE",
SigHashType::AllPlusAnyoneCanPay => "SIGHASH_ALL|SIGHASH_ANYONECANPAY",
SigHashType::NonePlusAnyoneCanPay => "SIGHASH_NONE|SIGHASH_ANYONECANPAY",
SigHashType::SinglePlusAnyoneCanPay => "SIGHASH_SINGLE|SIGHASH_ANYONECANPAY",
EcdsaSigHashType::All => "SIGHASH_ALL",
EcdsaSigHashType::None => "SIGHASH_NONE",
EcdsaSigHashType::Single => "SIGHASH_SINGLE",
EcdsaSigHashType::AllPlusAnyoneCanPay => "SIGHASH_ALL|SIGHASH_ANYONECANPAY",
EcdsaSigHashType::NonePlusAnyoneCanPay => "SIGHASH_NONE|SIGHASH_ANYONECANPAY",
EcdsaSigHashType::SinglePlusAnyoneCanPay => "SIGHASH_SINGLE|SIGHASH_ANYONECANPAY",
};
f.write_str(s)
}
}
impl str::FromStr for SigHashType {
impl str::FromStr for EcdsaSigHashType {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.as_ref() {
"SIGHASH_ALL" => Ok(SigHashType::All),
"SIGHASH_NONE" => Ok(SigHashType::None),
"SIGHASH_SINGLE" => Ok(SigHashType::Single),
"SIGHASH_ALL|SIGHASH_ANYONECANPAY" => Ok(SigHashType::AllPlusAnyoneCanPay),
"SIGHASH_NONE|SIGHASH_ANYONECANPAY" => Ok(SigHashType::NonePlusAnyoneCanPay),
"SIGHASH_SINGLE|SIGHASH_ANYONECANPAY" => Ok(SigHashType::SinglePlusAnyoneCanPay),
"SIGHASH_ALL" => Ok(EcdsaSigHashType::All),
"SIGHASH_NONE" => Ok(EcdsaSigHashType::None),
"SIGHASH_SINGLE" => Ok(EcdsaSigHashType::Single),
"SIGHASH_ALL|SIGHASH_ANYONECANPAY" => Ok(EcdsaSigHashType::AllPlusAnyoneCanPay),
"SIGHASH_NONE|SIGHASH_ANYONECANPAY" => Ok(EcdsaSigHashType::NonePlusAnyoneCanPay),
"SIGHASH_SINGLE|SIGHASH_ANYONECANPAY" => Ok(EcdsaSigHashType::SinglePlusAnyoneCanPay),
_ => Err("can't recognize SIGHASH string".to_string())
}
}
}
impl SigHashType {
impl EcdsaSigHashType {
/// Break the sighash flag into the "real" sighash flag and the ANYONECANPAY boolean
pub(crate) fn split_anyonecanpay_flag(self) -> (SigHashType, bool) {
pub(crate) fn split_anyonecanpay_flag(self) -> (EcdsaSigHashType, bool) {
match self {
SigHashType::All => (SigHashType::All, false),
SigHashType::None => (SigHashType::None, false),
SigHashType::Single => (SigHashType::Single, false),
SigHashType::AllPlusAnyoneCanPay => (SigHashType::All, true),
SigHashType::NonePlusAnyoneCanPay => (SigHashType::None, true),
SigHashType::SinglePlusAnyoneCanPay => (SigHashType::Single, true)
EcdsaSigHashType::All => (EcdsaSigHashType::All, false),
EcdsaSigHashType::None => (EcdsaSigHashType::None, false),
EcdsaSigHashType::Single => (EcdsaSigHashType::Single, false),
EcdsaSigHashType::AllPlusAnyoneCanPay => (EcdsaSigHashType::All, true),
EcdsaSigHashType::NonePlusAnyoneCanPay => (EcdsaSigHashType::None, true),
EcdsaSigHashType::SinglePlusAnyoneCanPay => (EcdsaSigHashType::Single, true)
}
}
/// Reads a 4-byte uint32 as a sighash type.
#[deprecated(since="0.26.1", note="please use `from_u32_consensus` or `from_u32_standard` instead")]
pub fn from_u32(n: u32) -> SigHashType {
pub fn from_u32(n: u32) -> EcdsaSigHashType {
Self::from_u32_consensus(n)
}
@ -748,7 +753,7 @@ impl SigHashType {
///
/// **Note**: this replicates consensus behaviour, for current standardness rules correctness
/// you probably want [Self::from_u32_standard].
pub fn from_u32_consensus(n: u32) -> SigHashType {
pub fn from_u32_consensus(n: u32) -> EcdsaSigHashType {
// In Bitcoin Core, the SignatureHash function will mask the (int32) value with
// 0x1f to (apparently) deactivate ACP when checking for SINGLE and NONE bits.
// We however want to be matching also against on ACP-masked ALL, SINGLE, and NONE.
@ -756,29 +761,29 @@ impl SigHashType {
let mask = 0x1f | 0x80;
match n & mask {
// "real" sighashes
0x01 => SigHashType::All,
0x02 => SigHashType::None,
0x03 => SigHashType::Single,
0x81 => SigHashType::AllPlusAnyoneCanPay,
0x82 => SigHashType::NonePlusAnyoneCanPay,
0x83 => SigHashType::SinglePlusAnyoneCanPay,
0x01 => EcdsaSigHashType::All,
0x02 => EcdsaSigHashType::None,
0x03 => EcdsaSigHashType::Single,
0x81 => EcdsaSigHashType::AllPlusAnyoneCanPay,
0x82 => EcdsaSigHashType::NonePlusAnyoneCanPay,
0x83 => EcdsaSigHashType::SinglePlusAnyoneCanPay,
// catchalls
x if x & 0x80 == 0x80 => SigHashType::AllPlusAnyoneCanPay,
_ => SigHashType::All
x if x & 0x80 == 0x80 => EcdsaSigHashType::AllPlusAnyoneCanPay,
_ => EcdsaSigHashType::All
}
}
/// Read a 4-byte uint32 as a standard sighash type, returning an error if the type
/// is non standard.
pub fn from_u32_standard(n: u32) -> Result<SigHashType, NonStandardSigHashType> {
pub fn from_u32_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(SigHashType::All),
0x02 => Ok(SigHashType::None),
0x03 => Ok(SigHashType::Single),
0x81 => Ok(SigHashType::AllPlusAnyoneCanPay),
0x82 => Ok(SigHashType::NonePlusAnyoneCanPay),
0x83 => Ok(SigHashType::SinglePlusAnyoneCanPay),
0x01 => Ok(EcdsaSigHashType::All),
0x02 => Ok(EcdsaSigHashType::None),
0x03 => Ok(EcdsaSigHashType::Single),
0x81 => Ok(EcdsaSigHashType::AllPlusAnyoneCanPay),
0x82 => Ok(EcdsaSigHashType::NonePlusAnyoneCanPay),
0x83 => Ok(EcdsaSigHashType::SinglePlusAnyoneCanPay),
_ => Err(NonStandardSigHashType)
}
}
@ -787,8 +792,8 @@ impl SigHashType {
pub fn as_u32(self) -> u32 { self as u32 }
}
impl From<SigHashType> for u32 {
fn from(t: SigHashType) -> u32 {
impl From<EcdsaSigHashType> for u32 {
fn from(t: EcdsaSigHashType) -> u32 {
t.as_u32()
}
}
@ -807,7 +812,7 @@ mod tests {
use hashes::hex::FromHex;
use hash_types::*;
use SigHashType;
use super::EcdsaSigHashType;
use util::sighash::SigHashCache;
#[test]
@ -1088,15 +1093,15 @@ mod tests {
#[test]
fn test_sighashtype_fromstr_display() {
let sighashtypes = vec![("SIGHASH_ALL", SigHashType::All),
("SIGHASH_NONE", SigHashType::None),
("SIGHASH_SINGLE", SigHashType::Single),
("SIGHASH_ALL|SIGHASH_ANYONECANPAY", SigHashType::AllPlusAnyoneCanPay),
("SIGHASH_NONE|SIGHASH_ANYONECANPAY", SigHashType::NonePlusAnyoneCanPay),
("SIGHASH_SINGLE|SIGHASH_ANYONECANPAY", SigHashType::SinglePlusAnyoneCanPay)];
let sighashtypes = vec![("SIGHASH_ALL", EcdsaSigHashType::All),
("SIGHASH_NONE", EcdsaSigHashType::None),
("SIGHASH_SINGLE", EcdsaSigHashType::Single),
("SIGHASH_ALL|SIGHASH_ANYONECANPAY", EcdsaSigHashType::AllPlusAnyoneCanPay),
("SIGHASH_NONE|SIGHASH_ANYONECANPAY", EcdsaSigHashType::NonePlusAnyoneCanPay),
("SIGHASH_SINGLE|SIGHASH_ANYONECANPAY", EcdsaSigHashType::SinglePlusAnyoneCanPay)];
for (s, sht) in sighashtypes {
assert_eq!(sht.to_string(), s);
assert_eq!(SigHashType::from_str(s).unwrap(), sht);
assert_eq!(EcdsaSigHashType::from_str(s).unwrap(), sht);
}
let sht_mistakes = vec![
"SIGHASH_ALL | SIGHASH_ANYONECANPAY",
@ -1111,7 +1116,7 @@ mod tests {
"SigHash_NONE",
];
for s in sht_mistakes {
assert_eq!(SigHashType::from_str(s).unwrap_err(), "can't recognize SIGHASH string");
assert_eq!(EcdsaSigHashType::from_str(s).unwrap_err(), "can't recognize SIGHASH string");
}
}
@ -1120,10 +1125,10 @@ mod tests {
fn test_sighashtype_standard() {
let nonstandard_hashtype = 0x04;
// This type is not well defined, by consensus it becomes ALL
assert_eq!(SigHashType::from_u32(nonstandard_hashtype), SigHashType::All);
assert_eq!(SigHashType::from_u32_consensus(nonstandard_hashtype), SigHashType::All);
assert_eq!(EcdsaSigHashType::from_u32(nonstandard_hashtype), EcdsaSigHashType::All);
assert_eq!(EcdsaSigHashType::from_u32_consensus(nonstandard_hashtype), EcdsaSigHashType::All);
// But it's policy-invalid to use it!
assert_eq!(SigHashType::from_u32_standard(nonstandard_hashtype), Err(NonStandardSigHashType));
assert_eq!(EcdsaSigHashType::from_u32_standard(nonstandard_hashtype), Err(NonStandardSigHashType));
}
// These test vectors were stolen from libbtc, which is Copyright 2014 Jonas Schnelli MIT

View File

@ -123,7 +123,7 @@ pub use blockdata::transaction::Transaction;
pub use blockdata::transaction::TxIn;
pub use blockdata::transaction::TxOut;
pub use blockdata::transaction::OutPoint;
pub use blockdata::transaction::SigHashType;
pub use blockdata::transaction::EcdsaSigHashType;
pub use consensus::encode::VarInt;
pub use network::constants::Network;
pub use util::Error;

View File

@ -22,7 +22,7 @@
use hashes::Hash;
use hash_types::SigHash;
use blockdata::script::Script;
use blockdata::transaction::{Transaction, TxIn, SigHashType};
use blockdata::transaction::{Transaction, TxIn, EcdsaSigHashType};
use consensus::{encode, Encodable};
use prelude::*;
@ -131,7 +131,7 @@ impl<R: Deref<Target=Transaction>> SigHashCache<R> {
input_index: usize,
script_code: &Script,
value: u64,
sighash_type: SigHashType,
sighash_type: EcdsaSigHashType,
) -> Result<(), encode::Error> {
self.cache
.segwit_encode_signing_data_to(writer, input_index, script_code, value, sighash_type.into())
@ -146,7 +146,7 @@ impl<R: Deref<Target=Transaction>> SigHashCache<R> {
input_index: usize,
script_code: &Script,
value: u64,
sighash_type: SigHashType
sighash_type: EcdsaSigHashType
) -> SigHash {
let mut enc = SigHash::engine();
self.encode_signing_data_to(&mut enc, input_index, script_code, value, sighash_type)
@ -165,7 +165,7 @@ impl<R: DerefMut<Target=Transaction>> SigHashCache<R> {
/// panics if `input_index` is out of bounds with respect of the number of inputs
///
/// ```
/// use bitcoin::blockdata::transaction::{Transaction, SigHashType};
/// use bitcoin::blockdata::transaction::{Transaction, EcdsaSigHashType};
/// use bitcoin::util::bip143::SigHashCache;
/// use bitcoin::Script;
///
@ -175,7 +175,7 @@ impl<R: DerefMut<Target=Transaction>> SigHashCache<R> {
/// let mut sig_hasher = SigHashCache::new(&mut tx_to_sign);
/// for inp in 0..input_count {
/// let prevout_script = Script::new();
/// let _sighash = sig_hasher.signature_hash(inp, &prevout_script, 42, SigHashType::All);
/// let _sighash = sig_hasher.signature_hash(inp, &prevout_script, 42, EcdsaSigHashType::All);
/// // ... sign the sighash
/// sig_hasher.access_witness(inp).push(Vec::new());
/// }
@ -212,7 +212,7 @@ mod tests {
let raw_expected = SigHash::from_hex(expected_result).unwrap();
let expected_result = SigHash::from_slice(&raw_expected[..]).unwrap();
let mut cache = SigHashCache::new(&tx);
let sighash_type = SigHashType::from_u32_consensus(hash_type);
let sighash_type = EcdsaSigHashType::from_u32_consensus(hash_type);
let actual_result = cache.signature_hash(input_index, &script, value, sighash_type);
assert_eq!(actual_result, expected_result);
}

View File

@ -29,7 +29,7 @@ use hashes::{Hash, hash160};
use hash_types::{PubkeyHash, WPubkeyHash};
use util::base58;
use util::key::Error;
use blockdata::transaction::SigHashType;
use blockdata::transaction::EcdsaSigHashType;
/// A Bitcoin ECDSA public key
@ -421,7 +421,7 @@ pub struct EcdsaSig {
/// The underlying ECDSA Signature
pub sig: secp256k1::Signature,
/// The corresponding hash type
pub hash_ty: SigHashType,
pub hash_ty: EcdsaSigHashType,
}
impl EcdsaSig {
@ -430,7 +430,7 @@ impl EcdsaSig {
pub fn from_slice(sl: &[u8]) -> Result<Self, EcdsaSigError> {
let (hash_ty, sig) = sl.split_last()
.ok_or(EcdsaSigError::EmptySignature)?;
let hash_ty = SigHashType::from_u32_standard(*hash_ty as u32)
let hash_ty = EcdsaSigHashType::from_u32_standard(*hash_ty as u32)
.map_err(|_| EcdsaSigError::NonStandardSigHashType(*hash_ty))?;
let sig = secp256k1::Signature::from_der(sig)
.map_err(EcdsaSigError::Secp256k1)?;

View File

@ -17,7 +17,7 @@ use prelude::*;
use io;
use blockdata::script::Script;
use blockdata::transaction::{SigHashType, Transaction, TxOut};
use blockdata::transaction::{EcdsaSigHashType, Transaction, TxOut};
use consensus::encode;
use util::bip32::KeySource;
use hashes::{self, hash160, ripemd160, sha256, sha256d};
@ -76,7 +76,7 @@ pub struct Input {
pub partial_sigs: BTreeMap<PublicKey, Vec<u8>>,
/// The sighash type to be used for this input. Signatures for this input
/// must use the sighash type.
pub sighash_type: Option<SigHashType>,
pub sighash_type: Option<EcdsaSigHashType>,
/// The redeem script for this input.
pub redeem_script: Option<Script>,
/// The witness script for this input.
@ -137,7 +137,7 @@ impl Map for Input {
}
PSBT_IN_SIGHASH_TYPE => {
impl_psbt_insert_pair! {
self.sighash_type <= <raw_key: _>|<raw_value: SigHashType>
self.sighash_type <= <raw_key: _>|<raw_value: EcdsaSigHashType>
}
}
PSBT_IN_REDEEM_SCRIPT => {

View File

@ -507,7 +507,7 @@ mod tests {
use hash_types::Txid;
use blockdata::script::Script;
use blockdata::transaction::{SigHashType, Transaction, TxIn, TxOut, OutPoint};
use blockdata::transaction::{EcdsaSigHashType, Transaction, TxIn, TxOut, OutPoint};
use consensus::encode::serialize_hex;
use util::psbt::map::{Map, Input, Output};
use util::psbt::raw;
@ -733,7 +733,7 @@ mod tests {
);
assert_eq!(
(&psbt.inputs[0].sighash_type).as_ref().unwrap(),
&SigHashType::All
&EcdsaSigHashType::All
);
}

View File

@ -23,7 +23,7 @@ use prelude::*;
use io;
use blockdata::script::Script;
use blockdata::transaction::{SigHashType, Transaction, TxOut};
use blockdata::transaction::{EcdsaSigHashType, Transaction, TxOut};
use consensus::encode::{self, serialize, Decodable};
use util::bip32::{ChildNumber, Fingerprint, KeySource};
use hashes::{hash160, ripemd160, sha256, sha256d, Hash};
@ -126,16 +126,16 @@ impl Deserialize for Vec<u8> {
}
}
impl Serialize for SigHashType {
impl Serialize for EcdsaSigHashType {
fn serialize(&self) -> Vec<u8> {
serialize(&self.as_u32())
}
}
impl Deserialize for SigHashType {
impl Deserialize for EcdsaSigHashType {
fn deserialize(bytes: &[u8]) -> Result<Self, encode::Error> {
let raw: u32 = encode::deserialize(bytes)?;
let rv: SigHashType = SigHashType::from_u32_consensus(raw);
let rv: EcdsaSigHashType = EcdsaSigHashType::from_u32_consensus(raw);
if rv.as_u32() == raw {
Ok(rv)

View File

@ -20,7 +20,7 @@
//! and legacy (before Bip143).
//!
pub use blockdata::transaction::SigHashType as LegacySigHashType;
pub use blockdata::transaction::EcdsaSigHashType;
use consensus::{encode, Encodable};
use core::fmt;
use core::ops::{Deref, DerefMut};
@ -79,7 +79,7 @@ struct TaprootCache {
}
/// Contains outputs of previous transactions.
/// In the case [`SigHashType`] variant is `ANYONECANPAY`, [`Prevouts::One`] may be provided
/// In the case [`SchnorrSigHashType`] variant is `ANYONECANPAY`, [`Prevouts::One`] may be provided
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum Prevouts<'u> {
/// `One` variant allows to provide the single Prevout needed. It's useful for example
@ -105,7 +105,7 @@ pub struct ScriptPath<'s> {
/// Fixed values so they can be casted as integer types for encoding
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum SchnorrSigHashType {
/// 0x0: Used when not explicitly specified, defaulting to [`SigHashType::All`]
/// 0x0: Used when not explicitly specified, defaulting to [`SchnorrSigHashType::All`]
Default = 0x00,
/// 0x1: Sign all outputs
All = 0x01,
@ -233,15 +233,15 @@ impl<'s> ScriptPath<'s> {
}
}
impl From<LegacySigHashType> for SchnorrSigHashType {
fn from(s: LegacySigHashType) -> Self {
impl From<EcdsaSigHashType> for SchnorrSigHashType {
fn from(s: EcdsaSigHashType) -> Self {
match s {
LegacySigHashType::All => SchnorrSigHashType::All,
LegacySigHashType::None => SchnorrSigHashType::None,
LegacySigHashType::Single => SchnorrSigHashType::Single,
LegacySigHashType::AllPlusAnyoneCanPay => SchnorrSigHashType::AllPlusAnyoneCanPay,
LegacySigHashType::NonePlusAnyoneCanPay => SchnorrSigHashType::NonePlusAnyoneCanPay,
LegacySigHashType::SinglePlusAnyoneCanPay => SchnorrSigHashType::SinglePlusAnyoneCanPay,
EcdsaSigHashType::All => SchnorrSigHashType::All,
EcdsaSigHashType::None => SchnorrSigHashType::None,
EcdsaSigHashType::Single => SchnorrSigHashType::Single,
EcdsaSigHashType::AllPlusAnyoneCanPay => SchnorrSigHashType::AllPlusAnyoneCanPay,
EcdsaSigHashType::NonePlusAnyoneCanPay => SchnorrSigHashType::NonePlusAnyoneCanPay,
EcdsaSigHashType::SinglePlusAnyoneCanPay => SchnorrSigHashType::SinglePlusAnyoneCanPay,
}
}
}
@ -460,7 +460,7 @@ impl<R: Deref<Target = Transaction>> SigHashCache<R> {
input_index: usize,
script_code: &Script,
value: u64,
sighash_type: LegacySigHashType,
sighash_type: EcdsaSigHashType,
) -> Result<(), Error> {
let zero_hash = sha256d::Hash::default();
@ -475,8 +475,8 @@ impl<R: Deref<Target = Transaction>> SigHashCache<R> {
}
if !anyone_can_pay
&& sighash != LegacySigHashType::Single
&& sighash != LegacySigHashType::None
&& sighash != EcdsaSigHashType::Single
&& sighash != EcdsaSigHashType::None
{
self.segwit_cache()
.sequences
@ -502,9 +502,9 @@ impl<R: Deref<Target = Transaction>> SigHashCache<R> {
txin.sequence.consensus_encode(&mut writer)?;
}
if sighash != LegacySigHashType::Single && sighash != LegacySigHashType::None {
if sighash != EcdsaSigHashType::Single && sighash != EcdsaSigHashType::None {
self.segwit_cache().outputs.consensus_encode(&mut writer)?;
} else if sighash == LegacySigHashType::Single && input_index < self.tx.output.len() {
} else if sighash == EcdsaSigHashType::Single && input_index < self.tx.output.len() {
let mut single_enc = SigHash::engine();
self.tx.output[input_index].consensus_encode(&mut single_enc)?;
SigHash::from_engine(single_enc).consensus_encode(&mut writer)?;
@ -523,7 +523,7 @@ impl<R: Deref<Target = Transaction>> SigHashCache<R> {
input_index: usize,
script_code: &Script,
value: u64,
sighash_type: LegacySigHashType,
sighash_type: EcdsaSigHashType,
) -> Result<SigHash, Error> {
let mut enc = SigHash::engine();
self.segwit_encode_signing_data_to(
@ -645,7 +645,7 @@ impl<R: DerefMut<Target = Transaction>> SigHashCache<R> {
///
/// This allows in-line signing such as
/// ```
/// use bitcoin::blockdata::transaction::{Transaction, SigHashType};
/// use bitcoin::blockdata::transaction::{Transaction, EcdsaSigHashType};
/// use bitcoin::util::sighash::SigHashCache;
/// use bitcoin::Script;
///
@ -655,7 +655,7 @@ impl<R: DerefMut<Target = Transaction>> SigHashCache<R> {
/// let mut sig_hasher = SigHashCache::new(&mut tx_to_sign);
/// for inp in 0..input_count {
/// let prevout_script = Script::new();
/// let _sighash = sig_hasher.segwit_signature_hash(inp, &prevout_script, 42, SigHashType::All);
/// let _sighash = sig_hasher.segwit_signature_hash(inp, &prevout_script, 42, EcdsaSigHashType::All);
/// // ... sign the sighash
/// sig_hasher.witness_mut(inp).unwrap().push(Vec::new());
/// }