From c5cd0db493b3d4427ff3c6c5b8433c217e7e195b Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 31 Oct 2024 14:23:34 +1100 Subject: [PATCH] Revert the change to to_bytes During this release cycle we deprecated `to_vec` in favour of `to_bytes`, we have since reversed our position on the name. Remove the deprecation of `to_bytes` from the three types that had it and use `to_vec`. --- bitcoin/src/blockdata/transaction.rs | 2 +- bitcoin/src/blockdata/witness.rs | 6 +----- bitcoin/src/crypto/ecdsa.rs | 8 ++------ bitcoin/src/crypto/taproot.rs | 6 +----- bitcoin/src/psbt/serialize.rs | 4 ++-- primitives/src/witness.rs | 4 ++-- 6 files changed, 9 insertions(+), 21 deletions(-) diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index 03a98f564..e9207099a 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -1604,7 +1604,7 @@ mod tests { .is_err()); // test that we get a failure if we corrupt a signature - let mut witness = spending.input[1].witness.to_bytes(); + let mut witness = spending.input[1].witness.to_vec(); witness[0][10] = 42; spending.input[1].witness = Witness::from_slice(&witness); diff --git a/bitcoin/src/blockdata/witness.rs b/bitcoin/src/blockdata/witness.rs index c8901a9c2..e7dc292f0 100644 --- a/bitcoin/src/blockdata/witness.rs +++ b/bitcoin/src/blockdata/witness.rs @@ -112,10 +112,6 @@ impl Encodable for Witness { crate::internal_macros::define_extension_trait! { /// Extension functionality for the [`Witness`] type. pub trait WitnessExt impl for Witness { - /// Convenience method to create an array of byte-arrays from this witness. - #[deprecated(since = "TBD", note = "use `to_bytes` instead")] - fn to_vec(&self) -> Vec> { self.to_bytes() } - /// Creates a witness required to spend a P2WPKH output. /// /// The witness will be made up of the DER encoded signature + sighash_type followed by the @@ -269,7 +265,7 @@ mod test { let expected_witness = vec![hex!( "304402207c800d698f4b0298c5aac830b822f011bb02df41eb114ade9a6702f364d5e39c0220366900d2a60cab903e77ef7dd415d46509b1f78ac78906e3296f495aa1b1b54101") ]; - assert_eq!(witness.to_bytes(), expected_witness); + assert_eq!(witness.to_vec(), expected_witness); } #[test] diff --git a/bitcoin/src/crypto/ecdsa.rs b/bitcoin/src/crypto/ecdsa.rs index b74756fdb..19fbb0f80 100644 --- a/bitcoin/src/crypto/ecdsa.rs +++ b/bitcoin/src/crypto/ecdsa.rs @@ -61,7 +61,7 @@ impl Signature { /// /// Note: this performs an extra heap allocation, you might prefer the /// [`serialize`](Self::serialize) method instead. - pub fn to_bytes(self) -> Vec { + pub fn to_vec(self) -> Vec { self.signature .serialize_der() .iter() @@ -70,10 +70,6 @@ impl Signature { .collect() } - /// Serializes an ECDSA signature (inner secp256k1 signature in DER format) into `Vec`. - #[deprecated(since = "TBD", note = "use `to_bytes` instead")] - pub fn to_vec(self) -> Vec { self.to_bytes() } - /// Serializes an ECDSA signature (inner secp256k1 signature in DER format) to a `writer`. #[inline] pub fn serialize_to_writer(&self, writer: &mut W) -> Result<(), io::Error> { @@ -345,6 +341,6 @@ mod tests { let mut buf = vec![]; sig.serialize_to_writer(&mut buf).expect("write failed"); - assert_eq!(sig.to_bytes(), buf) + assert_eq!(sig.to_vec(), buf) } } diff --git a/bitcoin/src/crypto/taproot.rs b/bitcoin/src/crypto/taproot.rs index da72690b0..bfa857aa0 100644 --- a/bitcoin/src/crypto/taproot.rs +++ b/bitcoin/src/crypto/taproot.rs @@ -47,7 +47,7 @@ impl Signature { /// Serializes the signature. /// /// Note: this allocates on the heap, prefer [`serialize`](Self::serialize) if vec is not needed. - pub fn to_bytes(self) -> Vec { + pub fn to_vec(self) -> Vec { let mut ser_sig = self.signature.as_ref().to_vec(); if self.sighash_type == TapSighashType::Default { // default sighash type, don't add extra sighash byte @@ -57,10 +57,6 @@ impl Signature { ser_sig } - /// Serializes the signature. - #[deprecated(since = "TBD", note = "use `to_bytes` instead")] - pub fn to_vec(self) -> Vec { self.to_bytes() } - /// Serializes the signature to `writer`. #[inline] pub fn serialize_to_writer(&self, writer: &mut W) -> Result<(), io::Error> { diff --git a/bitcoin/src/psbt/serialize.rs b/bitcoin/src/psbt/serialize.rs index dfe840e2e..896cbeb3f 100644 --- a/bitcoin/src/psbt/serialize.rs +++ b/bitcoin/src/psbt/serialize.rs @@ -172,7 +172,7 @@ impl Deserialize for secp256k1::PublicKey { } impl Serialize for ecdsa::Signature { - fn serialize(&self) -> Vec { self.to_bytes() } + fn serialize(&self) -> Vec { self.to_vec() } } impl Deserialize for ecdsa::Signature { @@ -265,7 +265,7 @@ impl Deserialize for XOnlyPublicKey { } impl Serialize for taproot::Signature { - fn serialize(&self) -> Vec { self.to_bytes() } + fn serialize(&self) -> Vec { self.to_vec() } } impl Deserialize for taproot::Signature { diff --git a/primitives/src/witness.rs b/primitives/src/witness.rs index a2673fdc0..ff626b8ca 100644 --- a/primitives/src/witness.rs +++ b/primitives/src/witness.rs @@ -17,7 +17,7 @@ use crate::prelude::Vec; /// /// Can be logically seen as an array of bytestrings, i.e. `Vec>`, and it is serialized on the wire /// in that format. You can convert between this type and `Vec>` by using [`Witness::from_slice`] -/// and [`Witness::to_bytes`]. +/// and [`Witness::to_vec`]. /// /// For serialization and deserialization performance it is stored internally as a single `Vec`, /// saving some allocations. @@ -97,7 +97,7 @@ impl Witness { } /// Convenience method to create an array of byte-arrays from this witness. - pub fn to_bytes(&self) -> Vec> { self.iter().map(|s| s.to_vec()).collect() } + pub fn to_vec(&self) -> Vec> { self.iter().map(|s| s.to_vec()).collect() } /// Returns `true` if the witness contains no element. pub fn is_empty(&self) -> bool { self.witness_elements == 0 }