Skip to content

Commit

Permalink
transaction: deprecate SigHashType::from_u32 in favor of from_u32_con…
Browse files Browse the repository at this point in the history
…sensus

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
  • Loading branch information
darosior committed Feb 19, 2021
1 parent bf98d9f commit e36f3a3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/blockdata/transaction.rs
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/util/bip143.rs
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/psbt/serialize.rs
Expand Up @@ -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)
Expand Down

0 comments on commit e36f3a3

Please sign in to comment.