From e36f3a38e44a43bf5de5ced11c810f1ec9ac8211 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Fri, 19 Feb 2021 11:22:26 +0100 Subject: [PATCH] transaction: deprecate SigHashType::from_u32 in favor of from_u32_consensus Signed-off-by: Antoine Poinsot --- src/blockdata/transaction.rs | 8 +++++++- src/util/bip143.rs | 2 +- src/util/psbt/serialize.rs | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 2faa3d7c..acf50987 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -686,11 +686,17 @@ impl SigHashType { } } + /// 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 { + Self::from_u32_consensus(n) + } + /// Reads a 4-byte uint32 as a sighash type. /// /// **Note**: this replicates consensus behaviour, for current standardness rules correctness /// you probably want [from_u32_standard]. - pub fn from_u32(n: u32) -> SigHashType { + pub fn from_u32_consensus(n: u32) -> SigHashType { // 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. diff --git a/src/util/bip143.rs b/src/util/bip143.rs index de49bfbe..d12477db 100644 --- a/src/util/bip143.rs +++ b/src/util/bip143.rs @@ -292,7 +292,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(hash_type); + let sighash_type = SigHashType::from_u32_consensus(hash_type); let actual_result = cache.signature_hash(input_index, &script, value, sighash_type); assert_eq!(actual_result, expected_result); } diff --git a/src/util/psbt/serialize.rs b/src/util/psbt/serialize.rs index 7344c73f..5e530a45 100644 --- a/src/util/psbt/serialize.rs +++ b/src/util/psbt/serialize.rs @@ -132,7 +132,7 @@ impl Serialize for SigHashType { impl Deserialize for SigHashType { fn deserialize(bytes: &[u8]) -> Result { let raw: u32 = encode::deserialize(bytes)?; - let rv: SigHashType = SigHashType::from_u32(raw); + let rv: SigHashType = SigHashType::from_u32_consensus(raw); if rv.as_u32() == raw { Ok(rv)