From db40297f873d23e4bce164c0f06778fd535c67a2 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 31 Oct 2024 14:30:19 +1100 Subject: [PATCH] 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. --- bitcoin/examples/taproot-psbt.rs | 2 +- bitcoin/src/psbt/serialize.rs | 2 +- bitcoin/tests/psbt-sign-taproot.rs | 2 +- primitives/src/script/borrowed.rs | 7 ++++++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bitcoin/examples/taproot-psbt.rs b/bitcoin/examples/taproot-psbt.rs index 9125559b6..9d418a50c 100644 --- a/bitcoin/examples/taproot-psbt.rs +++ b/bitcoin/examples/taproot-psbt.rs @@ -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); diff --git a/bitcoin/src/psbt/serialize.rs b/bitcoin/src/psbt/serialize.rs index 896cbeb3f..5b505d4b7 100644 --- a/bitcoin/src/psbt/serialize.rs +++ b/bitcoin/src/psbt/serialize.rs @@ -140,7 +140,7 @@ impl_psbt_hash_de_serialize!(sha256d::Hash); impl_psbt_de_serialize!(Vec); impl Serialize for ScriptBuf { - fn serialize(&self) -> Vec { self.to_bytes() } + fn serialize(&self) -> Vec { self.to_vec() } } impl Deserialize for ScriptBuf { diff --git a/bitcoin/tests/psbt-sign-taproot.rs b/bitcoin/tests/psbt-sign-taproot.rs index 3d5a71d77..15ff88115 100644 --- a/bitcoin/tests/psbt-sign-taproot.rs +++ b/bitcoin/tests/psbt-sign-taproot.rs @@ -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); diff --git a/primitives/src/script/borrowed.rs b/primitives/src/script/borrowed.rs index 7717a70bc..03f596a27 100644 --- a/primitives/src/script/borrowed.rs +++ b/primitives/src/script/borrowed.rs @@ -107,7 +107,12 @@ impl Script { /// Returns a copy of the script data. #[inline] - pub fn to_bytes(&self) -> Vec { self.0.to_owned() } + pub fn to_vec(&self) -> Vec { 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 { self.to_vec() } /// Converts a [`Box