script: deprecate to_bytes

Deprecate the `Script::to_bytes` function in favour of `to_vec` as we
are doing elsewhere.

Note that `ScriptBuf` has `into_bytes` because it does not copy.
Potentially this should be deprecated in favour of `into_vec`?

Note that in regards to the `to_` prefix this naming as valid according
to convention because the `Script` type is borrowed and `to_vec` copies
the underlying bytes.
This commit is contained in:
Tobin C. Harding 2024-10-31 14:30:19 +11:00
parent c5cd0db493
commit db40297f87
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
4 changed files with 9 additions and 4 deletions

View File

@ -690,7 +690,7 @@ impl BeneficiaryWallet {
script_witness.push(signature.to_vec());
}
for (control_block, (script, _)) in input.tap_scripts.iter() {
script_witness.push(script.to_bytes());
script_witness.push(script.to_vec());
script_witness.push(control_block.serialize());
}
input.final_script_witness = Some(script_witness);

View File

@ -140,7 +140,7 @@ impl_psbt_hash_de_serialize!(sha256d::Hash);
impl_psbt_de_serialize!(Vec<TapLeafHash>);
impl Serialize for ScriptBuf {
fn serialize(&self) -> Vec<u8> { self.to_bytes() }
fn serialize(&self) -> Vec<u8> { self.to_vec() }
}
impl Deserialize for ScriptBuf {

View File

@ -343,7 +343,7 @@ fn finalize_psbt_for_script_path_spend(mut psbt: Psbt) -> Psbt {
script_witness.push(signature.to_vec());
}
for (control_block, (script, _)) in input.tap_scripts.iter() {
script_witness.push(script.to_bytes());
script_witness.push(script.to_vec());
script_witness.push(control_block.serialize());
}
input.final_script_witness = Some(script_witness);

View File

@ -107,7 +107,12 @@ impl Script {
/// Returns a copy of the script data.
#[inline]
pub fn to_bytes(&self) -> Vec<u8> { self.0.to_owned() }
pub fn to_vec(&self) -> Vec<u8> { self.0.to_owned() }
/// Returns a copy of the script data.
#[inline]
#[deprecated(since = "TBD", note = "use to_vec instead")]
pub fn to_bytes(&self) -> Vec<u8> { self.to_vec() }
/// Converts a [`Box<Script>`](Box) into a [`ScriptBuf`] without copying or allocating.
#[must_use = "`self` will be dropped if the result is not used"]