diff --git a/bitcoin/src/address/script_pubkey.rs b/bitcoin/src/address/script_pubkey.rs index 89b7298aa..e299bed78 100644 --- a/bitcoin/src/address/script_pubkey.rs +++ b/bitcoin/src/address/script_pubkey.rs @@ -22,7 +22,7 @@ define_extension_trait! { /// Extension functionality to add scriptPubkey support to the [`Builder`] type. pub trait BuilderExt impl for Builder { /// Adds instructions to push a public key onto the stack. - fn push_key(self, key: PublicKey) -> Builder { + fn push_key(self: Self, key: PublicKey) -> Builder { if key.compressed { self.push_slice(key.inner.serialize()) } else { @@ -31,7 +31,7 @@ define_extension_trait! { } /// Adds instructions to push an XOnly public key onto the stack. - fn push_x_only_key(self, x_only_key: XOnlyPublicKey) -> Builder { + fn push_x_only_key(self: Self, x_only_key: XOnlyPublicKey) -> Builder { self.push_slice(x_only_key.serialize()) } } @@ -42,14 +42,14 @@ define_extension_trait! { pub trait ScriptExt impl for Script { /// Computes the P2WSH output corresponding to this witnessScript (aka the "witness redeem /// script"). - fn to_p2wsh(&self) -> Result { + fn to_p2wsh(self: &Self) -> Result { self.wscript_hash().map(ScriptBuf::new_p2wsh) } /// Computes P2TR output with a given internal key and a single script spending path equal to /// the current script, assuming that the script is a Tapscript. fn to_p2tr( - &self, + self: &Self, secp: &Secp256k1, internal_key: UntweakedPublicKey, ) -> ScriptBuf { @@ -59,7 +59,7 @@ define_extension_trait! { } /// Computes the P2SH output corresponding to this redeem script. - fn to_p2sh(&self) -> Result { + fn to_p2sh(self: &Self) -> Result { self.script_hash().map(ScriptBuf::new_p2sh) } @@ -67,7 +67,7 @@ define_extension_trait! { /// for a P2WPKH output. The `scriptCode` is described in [BIP143]. /// /// [BIP143]: - fn p2wpkh_script_code(&self) -> Option { + fn p2wpkh_script_code(self: &Self) -> Option { if self.is_p2wpkh() { // The `self` script is 0x00, 0x14, let bytes = &self.as_bytes()[2..]; @@ -82,14 +82,14 @@ define_extension_trait! { /// /// You can obtain the public key, if its valid, /// by calling [`p2pk_public_key()`](Self::p2pk_public_key) - fn is_p2pk(&self) -> bool { self.p2pk_pubkey_bytes().is_some() } + fn is_p2pk(self: &Self) -> bool { self.p2pk_pubkey_bytes().is_some() } /// Returns the public key if this script is P2PK with a **valid** public key. /// /// This may return `None` even when [`is_p2pk()`](Self::is_p2pk) returns true. /// This happens when the public key is invalid (e.g. the point not being on the curve). /// In this situation the script is unspendable. - fn p2pk_public_key(&self) -> Option { + fn p2pk_public_key(self: &Self) -> Option { PublicKey::from_slice(self.p2pk_pubkey_bytes()?).ok() } } @@ -98,7 +98,7 @@ define_extension_trait! { define_extension_trait! { pub(crate) trait ScriptExtPrivate impl for Script { /// Returns the bytes of the (possibly invalid) public key if this script is P2PK. - fn p2pk_pubkey_bytes(&self) -> Option<&[u8]> { + fn p2pk_pubkey_bytes(self: &Self) -> Option<&[u8]> { match self.len() { 67 if self.as_bytes()[0] == OP_PUSHBYTES_65.to_u8() && self.as_bytes()[66] == OP_CHECKSIG.to_u8() => diff --git a/bitcoin/src/consensus_validation.rs b/bitcoin/src/consensus_validation.rs index b0177ec1e..f197a188e 100644 --- a/bitcoin/src/consensus_validation.rs +++ b/bitcoin/src/consensus_validation.rs @@ -131,7 +131,7 @@ define_extension_trait! { /// /// [`bitcoinconsensus::VERIFY_ALL_PRE_TAPROOT`]: https://docs.rs/bitcoinconsensus/0.106.0+26.0/bitcoinconsensus/constant.VERIFY_ALL_PRE_TAPROOT.html fn verify( - &self, + self: &Self, index: usize, amount: crate::Amount, spending_tx: &[u8], @@ -150,7 +150,7 @@ define_extension_trait! { /// /// [`bitcoinconsensus::VERIFY_ALL_PRE_TAPROOT`]: https://docs.rs/bitcoinconsensus/0.106.0+26.0/bitcoinconsensus/constant.VERIFY_ALL_PRE_TAPROOT.html fn verify_with_flags( - &self, + self: &Self, index: usize, amount: crate::Amount, spending_tx: &[u8], diff --git a/bitcoin/src/internal_macros.rs b/bitcoin/src/internal_macros.rs index 5d90b9592..568d91b75 100644 --- a/bitcoin/src/internal_macros.rs +++ b/bitcoin/src/internal_macros.rs @@ -214,67 +214,6 @@ pub(crate) use impl_asref_push_bytes; /// Defines an trait `$trait_name` and implements it for `ty`, used to define extension traits. macro_rules! define_extension_trait { - // With self, no generics. - ($(#[$($trait_attrs:tt)*])* $trait_vis:vis trait $trait_name:ident impl for $ty:ident { - $( - $(#[$($fn_attrs:tt)*])* - fn $fn:ident($slf:ident $(, $param_name:ident: $param_type:ty)* $(,)?) $( -> $ret:ty )? $body:block - )* - }) => { - $(#[$($trait_attrs)*])* $trait_vis trait $trait_name { - $( - $(#[$($fn_attrs)*])* - fn $fn($slf $(, $param_name: $param_type)*) $( -> $ret )?; - )* - } - - impl $trait_name for $ty { - $( - fn $fn($slf $(, $param_name: $param_type)*) $( -> $ret )? $body - )* - } - }; - // With &self, no generics. - ($(#[$($trait_attrs:tt)*])* $trait_vis:vis trait $trait_name:ident impl for $ty:ident { - $( - $(#[$($fn_attrs:tt)*])* - fn $fn:ident(&$slf:ident $(, $param_name:ident: $param_type:ty)* $(,)?) $( -> $ret:ty )? $body:block - )* - }) => { - $(#[$($trait_attrs)*])* $trait_vis trait $trait_name { - $( - $(#[$($fn_attrs)*])* - fn $fn(&$slf $(, $param_name: $param_type)*) $( -> $ret )?; - )* - } - - impl $trait_name for $ty { - $( - fn $fn(&$slf $(, $param_name: $param_type)*) $( -> $ret )? $body - )* - } - }; - // With &self, with generics. - ($(#[$($trait_attrs:tt)*])* $trait_vis:vis trait $trait_name:ident impl for $ty:ident { - $( - $(#[$($fn_attrs:tt)*])* - fn $fn:ident$(<$($gen:ident: $gent:ident),*>)?(&$slf:ident $(, $param_name:ident: $param_type:ty)* $(,)?) $( -> $ret:ty )? $body:block - )* - }) => { - $(#[$($trait_attrs)*])* $trait_vis trait $trait_name { - $( - $(#[$($fn_attrs)*])* - fn $fn$(<$($gen: $gent),*>)?(&$slf $(, $param_name: $param_type)*) $( -> $ret )?; - )* - } - - impl $trait_name for $ty { - $( - fn $fn$(<$($gen: $gent),*>)?(&$slf $(, $param_name: $param_type)*) $( -> $ret )? $body - )* - } - }; - // No self, with generics. ($(#[$($trait_attrs:tt)*])* $trait_vis:vis trait $trait_name:ident impl for $ty:ident { $( $(#[$($fn_attrs:tt)*])* @@ -294,25 +233,5 @@ macro_rules! define_extension_trait { )* } }; - // No self, with generic `>` - ($(#[$($trait_attrs:tt)*])* $trait_vis:vis trait $trait_name:ident impl for $ty:ident { - $( - $(#[$($fn_attrs:tt)*])* - fn $fn:ident>($($param_name:ident: $param_type:ty),* $(,)?) $( -> $ret:ty )? $body:block - )* - }) => { - $(#[$($trait_attrs)*])* $trait_vis trait $trait_name { - $( - $(#[$($fn_attrs)*])* - fn $fn>($($param_name: $param_type),*) $( -> $ret )?; - )* - } - - impl $trait_name for $ty { - $( - fn $fn>($($param_name: $param_type),*) $( -> $ret )? $body - )* - } - }; } pub(crate) use define_extension_trait;