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`.
This commit is contained in:
Tobin C. Harding 2024-10-31 14:23:34 +11:00
parent dc2ca785d2
commit c5cd0db493
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
6 changed files with 9 additions and 21 deletions

View File

@ -1604,7 +1604,7 @@ mod tests {
.is_err()); .is_err());
// test that we get a failure if we corrupt a signature // 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; witness[0][10] = 42;
spending.input[1].witness = Witness::from_slice(&witness); spending.input[1].witness = Witness::from_slice(&witness);

View File

@ -112,10 +112,6 @@ impl Encodable for Witness {
crate::internal_macros::define_extension_trait! { crate::internal_macros::define_extension_trait! {
/// Extension functionality for the [`Witness`] type. /// Extension functionality for the [`Witness`] type.
pub trait WitnessExt impl for Witness { 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<Vec<u8>> { self.to_bytes() }
/// Creates a witness required to spend a P2WPKH output. /// 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 /// 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!( let expected_witness = vec![hex!(
"304402207c800d698f4b0298c5aac830b822f011bb02df41eb114ade9a6702f364d5e39c0220366900d2a60cab903e77ef7dd415d46509b1f78ac78906e3296f495aa1b1b54101") "304402207c800d698f4b0298c5aac830b822f011bb02df41eb114ade9a6702f364d5e39c0220366900d2a60cab903e77ef7dd415d46509b1f78ac78906e3296f495aa1b1b54101")
]; ];
assert_eq!(witness.to_bytes(), expected_witness); assert_eq!(witness.to_vec(), expected_witness);
} }
#[test] #[test]

View File

@ -61,7 +61,7 @@ impl Signature {
/// ///
/// Note: this performs an extra heap allocation, you might prefer the /// Note: this performs an extra heap allocation, you might prefer the
/// [`serialize`](Self::serialize) method instead. /// [`serialize`](Self::serialize) method instead.
pub fn to_bytes(self) -> Vec<u8> { pub fn to_vec(self) -> Vec<u8> {
self.signature self.signature
.serialize_der() .serialize_der()
.iter() .iter()
@ -70,10 +70,6 @@ impl Signature {
.collect() .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<u8> { self.to_bytes() }
/// Serializes an ECDSA signature (inner secp256k1 signature in DER format) to a `writer`. /// Serializes an ECDSA signature (inner secp256k1 signature in DER format) to a `writer`.
#[inline] #[inline]
pub fn serialize_to_writer<W: Write + ?Sized>(&self, writer: &mut W) -> Result<(), io::Error> { pub fn serialize_to_writer<W: Write + ?Sized>(&self, writer: &mut W) -> Result<(), io::Error> {
@ -345,6 +341,6 @@ mod tests {
let mut buf = vec![]; let mut buf = vec![];
sig.serialize_to_writer(&mut buf).expect("write failed"); sig.serialize_to_writer(&mut buf).expect("write failed");
assert_eq!(sig.to_bytes(), buf) assert_eq!(sig.to_vec(), buf)
} }
} }

View File

@ -47,7 +47,7 @@ impl Signature {
/// Serializes the signature. /// Serializes the signature.
/// ///
/// Note: this allocates on the heap, prefer [`serialize`](Self::serialize) if vec is not needed. /// Note: this allocates on the heap, prefer [`serialize`](Self::serialize) if vec is not needed.
pub fn to_bytes(self) -> Vec<u8> { pub fn to_vec(self) -> Vec<u8> {
let mut ser_sig = self.signature.as_ref().to_vec(); let mut ser_sig = self.signature.as_ref().to_vec();
if self.sighash_type == TapSighashType::Default { if self.sighash_type == TapSighashType::Default {
// default sighash type, don't add extra sighash byte // default sighash type, don't add extra sighash byte
@ -57,10 +57,6 @@ impl Signature {
ser_sig ser_sig
} }
/// Serializes the signature.
#[deprecated(since = "TBD", note = "use `to_bytes` instead")]
pub fn to_vec(self) -> Vec<u8> { self.to_bytes() }
/// Serializes the signature to `writer`. /// Serializes the signature to `writer`.
#[inline] #[inline]
pub fn serialize_to_writer<W: Write + ?Sized>(&self, writer: &mut W) -> Result<(), io::Error> { pub fn serialize_to_writer<W: Write + ?Sized>(&self, writer: &mut W) -> Result<(), io::Error> {

View File

@ -172,7 +172,7 @@ impl Deserialize for secp256k1::PublicKey {
} }
impl Serialize for ecdsa::Signature { impl Serialize for ecdsa::Signature {
fn serialize(&self) -> Vec<u8> { self.to_bytes() } fn serialize(&self) -> Vec<u8> { self.to_vec() }
} }
impl Deserialize for ecdsa::Signature { impl Deserialize for ecdsa::Signature {
@ -265,7 +265,7 @@ impl Deserialize for XOnlyPublicKey {
} }
impl Serialize for taproot::Signature { impl Serialize for taproot::Signature {
fn serialize(&self) -> Vec<u8> { self.to_bytes() } fn serialize(&self) -> Vec<u8> { self.to_vec() }
} }
impl Deserialize for taproot::Signature { impl Deserialize for taproot::Signature {

View File

@ -17,7 +17,7 @@ use crate::prelude::Vec;
/// ///
/// Can be logically seen as an array of bytestrings, i.e. `Vec<Vec<u8>>`, and it is serialized on the wire /// Can be logically seen as an array of bytestrings, i.e. `Vec<Vec<u8>>`, and it is serialized on the wire
/// in that format. You can convert between this type and `Vec<Vec<u8>>` by using [`Witness::from_slice`] /// in that format. You can convert between this type and `Vec<Vec<u8>>` 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`, /// For serialization and deserialization performance it is stored internally as a single `Vec`,
/// saving some allocations. /// saving some allocations.
@ -97,7 +97,7 @@ impl Witness {
} }
/// Convenience method to create an array of byte-arrays from this witness. /// Convenience method to create an array of byte-arrays from this witness.
pub fn to_bytes(&self) -> Vec<Vec<u8>> { self.iter().map(|s| s.to_vec()).collect() } pub fn to_vec(&self) -> Vec<Vec<u8>> { self.iter().map(|s| s.to_vec()).collect() }
/// Returns `true` if the witness contains no element. /// Returns `true` if the witness contains no element.
pub fn is_empty(&self) -> bool { self.witness_elements == 0 } pub fn is_empty(&self) -> bool { self.witness_elements == 0 }