Make `ScriptHash` & `WScriptHash` obey sanity rule

These were re-implementing hashing after the check rather than calling
the `_unchecked` method, so this replaces the manual implementation with
the method.
This commit is contained in:
Martin Habovstiak 2025-02-20 18:10:53 +01:00
parent 9ec9adc71d
commit ce55dd5b70
1 changed files with 4 additions and 2 deletions

View File

@ -69,7 +69,8 @@ impl ScriptHash {
return Err(RedeemScriptSizeError { size: redeem_script.len() });
}
Ok(ScriptHash(hash160::Hash::hash(redeem_script.as_bytes())))
// We've just checked the length
Ok(ScriptHash::from_script_unchecked(redeem_script))
}
/// Constructs a new `ScriptHash` from any script irrespective of script size.
@ -99,7 +100,8 @@ impl WScriptHash {
return Err(WitnessScriptSizeError { size: witness_script.len() });
}
Ok(WScriptHash(sha256::Hash::hash(witness_script.as_bytes())))
// We've just checked the length
Ok(WScriptHash::from_script_unchecked(witness_script))
}
/// Constructs a new `WScriptHash` from any script irrespective of script size.