transaction: deprecate SigHashType::from_u32 in favor of from_u32_consensus

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This commit is contained in:
Antoine Poinsot 2021-02-19 11:22:26 +01:00
parent bf98d9fd60
commit e36f3a38e4
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
3 changed files with 9 additions and 3 deletions

View File

@ -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.

View File

@ -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);
}

View File

@ -132,7 +132,7 @@ impl Serialize for SigHashType {
impl Deserialize for SigHashType {
fn deserialize(bytes: &[u8]) -> Result<Self, encode::Error> {
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)