diff --git a/bitcoin/src/blockdata/block.rs b/bitcoin/src/blockdata/block.rs index f6a039042..96dbb1b7a 100644 --- a/bitcoin/src/blockdata/block.rs +++ b/bitcoin/src/blockdata/block.rs @@ -110,8 +110,6 @@ pub struct Block { pub txdata: Vec, } -impl_consensus_encoding!(Block, header, txdata); - impl Block { /// Returns the block hash. pub fn block_hash(&self) -> BlockHash { self.header.block_hash() } @@ -272,6 +270,37 @@ impl From<&Block> for BlockHash { fn from(block: &Block) -> BlockHash { block.block_hash() } } +impl Encodable for Block { + #[inline] + fn consensus_encode(&self, r: &mut R) -> Result { + let mut len = 0; + len += self.header.consensus_encode(r)?; + len += self.txdata.consensus_encode(r)?; + Ok(len) + } +} + +impl Decodable for Block { + #[inline] + fn consensus_decode_from_finite_reader( + r: &mut R, + ) -> Result { + Ok(Block { + header: Decodable::consensus_decode_from_finite_reader(r)?, + txdata: Decodable::consensus_decode_from_finite_reader(r)?, + }) + } + + #[inline] + fn consensus_decode(r: &mut R) -> Result { + let mut r = r.take(internals::ToU64::to_u64(encode::MAX_VEC_SIZE)); + Ok(Block { + header: Decodable::consensus_decode(&mut r)?, + txdata: Decodable::consensus_decode(&mut r)?, + }) + } +} + /// An error when looking up a BIP34 block height. #[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive]