Seal extension traits

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
This commit is contained in:
Tobin C. Harding 2024-10-21 14:50:22 +11:00
parent 98548548d6
commit e7d326f071
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
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) }
} }