Merge rust-bitcoin/rust-bitcoin#3498: Seal extension traits

e7d326f071 Seal extension traits (Tobin C. Harding)

Pull request description:

  The extension traits are temporary just while we try to stabalize `primitives`, they are not intended to be implemented by downstream.

  Seal the extension traits so that downstream crates cannot implement them.

  Fix: #3231

ACKs for top commit:
  apoelstra:
    ACK e7d326f071a368389f087ddb10ee9bbf3552c33a; successfully ran local tests; thanks! I know this is tedious and annoying

Tree-SHA512: 365979aeabb7941b9c8fa526f71aaadae3ab1cdd6a39e992c5eea2c1057b4b7c2b3a846ffd96a7eab47b9ad4e3e4de4fb141c24c62747e5cee45c74f52f9a172
This commit is contained in:
merge-script 2024-10-22 02:19:02 +00:00
commit b4f52ac87a
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
9 changed files with 47 additions and 7 deletions

View File

@ -195,6 +195,13 @@ pub(super) fn new_witness_program_unchecked<T: AsRef<PushBytes>>(
Builder::new().push_opcode(version.into()).push_slice(program).into_script() Builder::new().push_opcode(version.into()).push_slice(program).into_script()
} }
mod sealed {
pub trait Sealed {}
impl Sealed for super::Script {}
impl Sealed for super::ScriptBuf {}
impl Sealed for super::Builder {}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View File

@ -71,6 +71,11 @@ crate::internal_macros::define_extension_trait! {
} }
} }
mod sealed {
pub trait Sealed {}
impl Sealed for super::Header {}
}
impl Encodable for Version { impl Encodable for Version {
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> { fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
self.to_consensus().consensus_encode(w) self.to_consensus().consensus_encode(w)

View File

@ -387,6 +387,11 @@ crate::internal_macros::define_extension_trait! {
} }
} }
mod sealed {
pub trait Sealed {}
impl Sealed for super::Script {}
}
crate::internal_macros::define_extension_trait! { crate::internal_macros::define_extension_trait! {
pub(crate) trait ScriptExtPriv impl for Script { pub(crate) trait ScriptExtPriv impl for Script {
fn minimal_non_dust_internal(&self, dust_relay_fee: u64) -> crate::Amount { fn minimal_non_dust_internal(&self, dust_relay_fee: u64) -> crate::Amount {

View File

@ -81,6 +81,11 @@ crate::internal_macros::define_extension_trait! {
} }
} }
mod sealed {
pub trait Sealed {}
impl Sealed for super::ScriptBuf {}
}
crate::internal_macros::define_extension_trait! { crate::internal_macros::define_extension_trait! {
pub(crate) trait ScriptBufExtPriv impl for ScriptBuf { pub(crate) trait ScriptBufExtPriv impl for ScriptBuf {
/// Pretends to convert `&mut ScriptBuf` to `&mut Vec<u8>` so that it can be modified. /// Pretends to convert `&mut ScriptBuf` to `&mut Vec<u8>` so that it can be modified.

View File

@ -61,12 +61,6 @@ pub trait TxIdentifier: sealed::Sealed + AsRef<[u8]> {}
impl TxIdentifier for Txid {} impl TxIdentifier for Txid {}
impl TxIdentifier for Wtxid {} impl TxIdentifier for Wtxid {}
mod sealed {
pub trait Sealed {}
impl Sealed for super::Txid {}
impl Sealed for super::Wtxid {}
}
/// The marker MUST be a 1-byte zero value: 0x00. (BIP-141) /// The marker MUST be a 1-byte zero value: 0x00. (BIP-141)
const SEGWIT_MARKER: u8 = 0x00; const SEGWIT_MARKER: u8 = 0x00;
/// The flag MUST be a 1-byte non-zero value. Currently, 0x01 MUST be used. (BIP-141) /// The flag MUST be a 1-byte non-zero value. Currently, 0x01 MUST be used. (BIP-141)
@ -1334,6 +1328,15 @@ impl<'a> Arbitrary<'a> for Transaction {
} }
} }
mod sealed {
pub trait Sealed {}
impl Sealed for super::Txid {}
impl Sealed for super::Wtxid {}
impl Sealed for super::OutPoint {}
impl Sealed for super::TxOut {}
impl Sealed for super::Version {}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use hex::{test_hex_unwrap as hex, FromHex}; use hex::{test_hex_unwrap as hex, FromHex};

View File

@ -216,6 +216,11 @@ crate::internal_macros::define_extension_trait! {
} }
} }
mod sealed {
pub trait Sealed {}
impl Sealed for super::Witness {}
}
/// Correctness Requirements: value must always fit within u32 /// Correctness Requirements: value must always fit within u32
// This is duplicated in `primitives::witness`, if you change it please do so over there also. // This is duplicated in `primitives::witness`, if you change it please do so over there also.
#[inline] #[inline]

View File

@ -161,6 +161,11 @@ define_extension_trait! {
} }
} }
mod sealed {
pub trait Sealed {}
impl Sealed for super::Script {}
}
impl Transaction { impl Transaction {
/// Verifies that this transaction is able to spend its inputs. /// Verifies that this transaction is able to spend its inputs.
/// ///

View File

@ -252,7 +252,7 @@ macro_rules! define_extension_trait {
fn $fn:ident$(<$($gen:ident: $gent:path),*>)?($($params:tt)*) $( -> $ret:ty )? $body:block fn $fn:ident$(<$($gen:ident: $gent:path),*>)?($($params:tt)*) $( -> $ret:ty )? $body:block
)* )*
}) => { }) => {
$(#[$($trait_attrs)*])* $trait_vis trait $trait_name { $(#[$($trait_attrs)*])* $trait_vis trait $trait_name: sealed::Sealed {
$( $(
$crate::internal_macros::only_doc_attrs! { $crate::internal_macros::only_doc_attrs! {
{ $(#[$($fn_attrs)*])* }, { $(#[$($fn_attrs)*])* },

View File

@ -430,6 +430,11 @@ define_extension_trait! {
} }
} }
mod sealed {
pub trait Sealed {}
impl Sealed for super::CompactTarget {}
}
impl From<CompactTarget> for Target { impl From<CompactTarget> for Target {
fn from(c: CompactTarget) -> Self { Target::from_compact(c) } fn from(c: CompactTarget) -> Self { Target::from_compact(c) }
} }