From eda61ddfef52ffb6fbb30409d9c6990868a51eae Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 14 May 2024 10:47:02 +1000 Subject: [PATCH] Deprecate to_vec in favour of to_bytes Currently we have to method names for the same thing "copy this object into a vector". The library is easier to use if we are uniform and just use one. Elect to use `to_bytes`, for context see discussion in PR #2585. --- bitcoin/src/blockdata/witness.rs | 6 +++++- bitcoin/src/crypto/ecdsa.rs | 6 +++++- bitcoin/src/crypto/taproot.rs | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bitcoin/src/blockdata/witness.rs b/bitcoin/src/blockdata/witness.rs index d617f980b..6419f88b3 100644 --- a/bitcoin/src/blockdata/witness.rs +++ b/bitcoin/src/blockdata/witness.rs @@ -284,7 +284,11 @@ impl Witness { } /// Convenience method to create an array of byte-arrays from this witness. - pub fn to_vec(&self) -> Vec> { self.iter().map(|s| s.to_vec()).collect() } + pub fn to_bytes(&self) -> Vec> { self.iter().map(|s| s.to_vec()).collect() } + + /// Convenience method to create an array of byte-arrays from this witness. + #[deprecated(since = "TBD", note = "Use to_bytes instead")] + pub fn to_vec(&self) -> Vec> { self.to_bytes() } /// Returns `true` if the witness contains no element. pub fn is_empty(&self) -> bool { self.witness_elements == 0 } diff --git a/bitcoin/src/crypto/ecdsa.rs b/bitcoin/src/crypto/ecdsa.rs index 4e1a84002..4d26be012 100644 --- a/bitcoin/src/crypto/ecdsa.rs +++ b/bitcoin/src/crypto/ecdsa.rs @@ -57,7 +57,7 @@ impl Signature { /// /// Note: this performs an extra heap allocation, you might prefer the /// [`serialize`](Self::serialize) method instead. - pub fn to_vec(self) -> Vec { + pub fn to_bytes(self) -> Vec { self.signature .serialize_der() .iter() @@ -66,6 +66,10 @@ 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> { diff --git a/bitcoin/src/crypto/taproot.rs b/bitcoin/src/crypto/taproot.rs index c97c03f2e..096a87b8d 100644 --- a/bitcoin/src/crypto/taproot.rs +++ b/bitcoin/src/crypto/taproot.rs @@ -47,7 +47,7 @@ impl Signature { /// Serialize Signature /// /// Note: this allocates on the heap, prefer [`serialize`](Self::serialize) if vec is not needed. - pub fn to_vec(self) -> Vec { + pub fn to_bytes(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,6 +57,10 @@ impl Signature { ser_sig } + /// Serialize 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> {