What changed, and why it matters
This commit only moves existing code around in four source files. It reorders the encoding and decoding definitions so they follow the same pattern across the project. No logic was changed, no bugs were fixed, and no security issue is present.
No action required; this is a non-functional code-layout cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure refactor: macro invocations and impl blocks for Encode/Decode traits are reordered to a consistent convention (Encode impl, Decode impl, encoder macro, decoder macro/struct). The actual types, trait implementations, and behavior remain identical. Stats are +61 -61, confirming only line movement.
Changed components
primitives/src/block.rsprimitives/src/script/borrowed.rsprimitives/src/script/owned.rsprimitives/src/witness.rsInspect captured patch +61 / −61
diff --git a/primitives/src/block.rs b/primitives/src/block.rs
index d800e9c9..16755e92 100644
--- a/primitives/src/block.rs
+++ b/primitives/src/block.rs
@@ -324,15 +324,6 @@ impl<V: Validation> fmt::UpperHex for Block<V> {
}
}
-#[cfg(feature = "alloc")]
-encoding::encoder_newtype! {
- /// The encoder for the [`Block`] type.
- #[derive(Debug, Clone)]
- pub struct BlockEncoder<'e>(
- Encoder2<HeaderEncoder<'e>, Encoder2<CompactSizeEncoder, SliceEncoder<'e, Transaction>>>
- );
-}
-
#[cfg(feature = "alloc")]
impl<V> encoding::Encode for Block<V>
where
@@ -354,6 +345,20 @@ where
}
}
+#[cfg(feature = "alloc")]
+impl encoding::Decode for Block<Unchecked> {
+ type Decoder = BlockDecoder;
+}
+
+#[cfg(feature = "alloc")]
+encoding::encoder_newtype! {
+ /// The encoder for the [`Block`] type.
+ #[derive(Debug, Clone)]
+ pub struct BlockEncoder<'e>(
+ Encoder2<HeaderEncoder<'e>, Encoder2<CompactSizeEncoder, SliceEncoder<'e, Transaction>>>
+ );
+}
+
#[cfg(feature = "alloc")]
type BlockInnerDecoder = Decoder2<HeaderDecoder, VecDecoder<Transaction>>;
@@ -374,11 +379,6 @@ crate::decoder_newtype! {
}
}
-#[cfg(feature = "alloc")]
-impl encoding::Decode for Block<Unchecked> {
- type Decoder = BlockDecoder;
-}
-
/// Computes the Merkle root for a list of transactions.
///
/// Returns `None` if the iterator was empty, or if the transaction list contains
@@ -523,21 +523,6 @@ impl fmt::Debug for Header {
}
}
-encoding::encoder_newtype_exact! {
- /// The encoder for the [`Header`] type.
- #[derive(Debug, Clone)]
- pub struct HeaderEncoder<'e>(
- encoding::Encoder6<
- VersionEncoder<'e>,
- BlockHashEncoder<'e>,
- crate::merkle_tree::TxMerkleNodeEncoder<'e>,
- crate::time::BlockTimeEncoder<'e>,
- crate::pow::CompactTargetEncoder<'e>,
- encoding::ArrayEncoder<4>,
- >
- );
-}
-
impl encoding::Encode for Header {
type Encoder<'e> = HeaderEncoder<'e>;
@@ -553,6 +538,25 @@ impl encoding::Encode for Header {
}
}
+impl encoding::Decode for Header {
+ type Decoder = HeaderDecoder;
+}
+
+encoding::encoder_newtype_exact! {
+ /// The encoder for the [`Header`] type.
+ #[derive(Debug, Clone)]
+ pub struct HeaderEncoder<'e>(
+ encoding::Encoder6<
+ VersionEncoder<'e>,
+ BlockHashEncoder<'e>,
+ crate::merkle_tree::TxMerkleNodeEncoder<'e>,
+ crate::time::BlockTimeEncoder<'e>,
+ crate::pow::CompactTargetEncoder<'e>,
+ encoding::ArrayEncoder<4>,
+ >
+ );
+}
+
type HeaderInnerDecoder = Decoder6<
VersionDecoder,
BlockHashDecoder,
@@ -605,10 +609,6 @@ impl HeaderDecoder {
}
}
-impl encoding::Decode for Header {
- type Decoder = HeaderDecoder;
-}
-
impl From<Header> for BlockHash {
#[inline]
fn from(header: Header) -> Self { header.block_hash() }
@@ -716,12 +716,6 @@ impl Default for Version {
fn default() -> Self { Self::NO_SOFT_FORK_SIGNALLING }
}
-encoding::encoder_newtype_exact! {
- /// The encoder for the [`Version`] type.
- #[derive(Debug, Clone)]
- pub struct VersionEncoder<'e>(encoding::ArrayEncoder<4>);
-}
-
impl encoding::Encode for Version {
type Encoder<'e> = VersionEncoder<'e>;
fn encoder(&self) -> Self::Encoder<'_> {
@@ -731,6 +725,16 @@ impl encoding::Encode for Version {
}
}
+impl encoding::Decode for Version {
+ type Decoder = VersionDecoder;
+}
+
+encoding::encoder_newtype_exact! {
+ /// The encoder for the [`Version`] type.
+ #[derive(Debug, Clone)]
+ pub struct VersionEncoder<'e>(encoding::ArrayEncoder<4>);
+}
+
crate::decoder_newtype! {
/// The decoder for the [`Version`] type.
#[derive(Debug, Clone)]
@@ -746,10 +750,6 @@ crate::decoder_newtype! {
}
}
-impl encoding::Decode for Version {
- type Decoder = VersionDecoder;
-}
-
/// Error types for Bitcoin blocks.
pub mod error {
use core::convert::Infallible;
diff --git a/primitives/src/script/borrowed.rs b/primitives/src/script/borrowed.rs
index 0b1a7cad..66e6630b 100644
--- a/primitives/src/script/borrowed.rs
+++ b/primitives/src/script/borrowed.rs
@@ -183,12 +183,6 @@ impl<T> Script<T> {
pub fn to_hex(&self) -> alloc::string::String { alloc::format!("{:x}", self) }
}
-encoding::encoder_newtype_exact! {
- /// The encoder for the [`Script<T>`] type.
- #[derive(Debug, Clone)]
- pub struct ScriptEncoder<'e>(Encoder2<CompactSizeEncoder, BytesEncoder<'e>>);
-}
-
impl<T> Encode for Script<T> {
type Encoder<'e>
= ScriptEncoder<'e>
@@ -203,6 +197,12 @@ impl<T> Encode for Script<T> {
}
}
+encoding::encoder_newtype_exact! {
+ /// The encoder for the [`Script<T>`] type.
+ #[derive(Debug, Clone)]
+ pub struct ScriptEncoder<'e>(Encoder2<CompactSizeEncoder, BytesEncoder<'e>>);
+}
+
#[cfg(feature = "arbitrary")]
impl<'a, T> Arbitrary<'a> for &'a Script<T> {
#[inline]
diff --git a/primitives/src/script/owned.rs b/primitives/src/script/owned.rs
index a9fc9c8f..31a38226 100644
--- a/primitives/src/script/owned.rs
+++ b/primitives/src/script/owned.rs
@@ -180,6 +180,10 @@ impl<T> DerefMut for ScriptBuf<T> {
fn deref_mut(&mut self) -> &mut Self::Target { self.as_mut_script() }
}
+impl<T> encoding::Decode for ScriptBuf<T> {
+ type Decoder = ScriptBufDecoder<T>;
+}
+
/// The decoder for the [`ScriptBuf`] type.
#[derive(Debug, Clone)]
pub struct ScriptBufDecoder<T>(ByteVecDecoder, PhantomData<T>);
@@ -211,10 +215,6 @@ impl<T> encoding::Decoder for ScriptBufDecoder<T> {
fn read_limit(&self) -> usize { self.0.read_limit() }
}
-impl<T> encoding::Decode for ScriptBuf<T> {
- type Decoder = ScriptBufDecoder<T>;
-}
-
#[cfg(feature = "arbitrary")]
impl<'a, T> Arbitrary<'a> for ScriptBuf<T> {
#[inline]
diff --git a/primitives/src/witness.rs b/primitives/src/witness.rs
index 2362eb48..618debc8 100644
--- a/primitives/src/witness.rs
+++ b/primitives/src/witness.rs
@@ -280,10 +280,6 @@ fn decode_cursor(bytes: &[u8], start_of_indices: usize, index: usize) -> Option<
usize::try_from(pos).ok()
}
-/// The encoder for the [`Witness`] type.
-#[derive(Debug, Clone)]
-pub struct WitnessEncoder<'e>(Encoder2<CompactSizeEncoder, BytesEncoder<'e>>);
-
impl encoding::Encode for Witness {
type Encoder<'e>
= WitnessEncoder<'e>
@@ -299,6 +295,14 @@ impl encoding::Encode for Witness {
}
}
+impl encoding::Decode for Witness {
+ type Decoder = WitnessDecoder;
+}
+
+/// The encoder for the [`Witness`] type.
+#[derive(Debug, Clone)]
+pub struct WitnessEncoder<'e>(Encoder2<CompactSizeEncoder, BytesEncoder<'e>>);
+
impl encoding::Encoder for WitnessEncoder<'_> {
#[inline]
fn current_chunk(&self) -> &[u8] { self.0.current_chunk() }
@@ -531,10 +535,6 @@ impl encoding::Decoder for WitnessDecoder {
}
}
-impl encoding::Decode for Witness {
- type Decoder = WitnessDecoder;
-}
-
// Note: we use `Borrow` in the following `PartialEq` impls specifically because of its additional
// constraints on equality semantics.
impl<T: core::borrow::Borrow<[u8]>> PartialEq<[T]> for Witness {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.