From f5c46cd4112edf9fcab10c06b5a658c445700d7f Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 19 Sep 2024 14:14:42 +1000 Subject: [PATCH] Introduce OutPoint extension traits In preparation for moving the `OutPoint` over to `primitives` add an extension trait to hold everything that will stay behind. --- bitcoin/src/bip152.rs | 1 + bitcoin/src/blockdata/transaction.rs | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bitcoin/src/bip152.rs b/bitcoin/src/bip152.rs index cb6fb9ec3..42ce0fe39 100644 --- a/bitcoin/src/bip152.rs +++ b/bitcoin/src/bip152.rs @@ -404,6 +404,7 @@ mod test { use crate::consensus::encode::{deserialize, serialize}; use crate::locktime::absolute; use crate::merkle_tree::TxMerkleNode; + use crate::transaction::OutPointExt; use crate::{ transaction, Amount, CompactTarget, OutPoint, ScriptBuf, Sequence, TxIn, TxOut, Txid, Witness, diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index e672322f0..c5e5dd09d 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -99,21 +99,20 @@ impl OutPoint { pub const COINBASE_PREVOUT: Self = Self { txid: Txid::COINBASE_PREVOUT, vout: u32::MAX }; } -impl OutPoint { - /// Creates a new [`OutPoint`]. - #[inline] - #[deprecated(since = "TBD", note = "use struct initialization syntax instead")] - pub const fn new(txid: Txid, vout: u32) -> OutPoint { OutPoint { txid, vout } } +crate::internal_macros::define_extension_trait! { + /// Extension functionality for the [`OutPoint`] type. + pub trait OutPointExt impl for OutPoint { + /// Creates a new [`OutPoint`]. + #[inline] + #[deprecated(since = "TBD", note = "use struct initialization syntax instead")] + #[allow(clippy::new-ret-no-self)] + fn new(txid: Txid, vout: u32) -> Self { OutPoint { txid, vout } } - /// Creates a "null" `OutPoint`. - #[inline] - #[deprecated(since = "TBD", note = "use OutPoint::COINBASE_PREVOUT instead")] - pub fn null() -> OutPoint { Self::COINBASE_PREVOUT } - - /// Checks if an `OutPoint` is "null". - #[inline] - #[deprecated(since = "TBD", note = "use outpoint == OutPoint::COINBASE_PREVOUT instead")] - pub fn is_null(&self) -> bool { *self == OutPoint::null() } + /// Checks if an `OutPoint` is "null". + #[inline] + #[deprecated(since = "TBD", note = "use outpoint == OutPoint::COINBASE_PREVOUT instead")] + fn is_null(&self) -> bool { *self == OutPoint::COINBASE_PREVOUT } + } } impl fmt::Display for OutPoint {