diff --git a/zebra-network/src/protocol/codec.rs b/zebra-network/src/protocol/codec.rs index 4ba97b037..ed2064045 100644 --- a/zebra-network/src/protocol/codec.rs +++ b/zebra-network/src/protocol/codec.rs @@ -9,7 +9,7 @@ use failure::Error; use tokio::codec::{Decoder, Encoder}; use zebra_chain::{ - block::{BlockHeader, BlockHeaderHash}, + block::{Block, BlockHeader, BlockHeaderHash}, serialization::{ReadZcashExt, WriteZcashExt, ZcashDeserialize, ZcashSerialize}, transaction::Transaction, types::{BlockHeight, Sha256dChecksum}, @@ -211,7 +211,11 @@ impl Codec { hash.zcash_serialize(&mut writer)?; } } - Block { ref block } => { + Block { + ref version, + ref block, + } => { + writer.write_u32::(version.0)?; block .zcash_serialize(&mut writer) .expect("Blocks must serialize."); @@ -246,7 +250,15 @@ impl Codec { header.zcash_serialize(&mut writer)?; } } - + Tx { + ref version, + ref transaction, + } => { + writer.write_u32::(version.0)?; + transaction + .zcash_serialize(&mut writer) + .expect("Transactions must serialize."); + } _ => bail!("unimplemented message type"), } Ok(()) @@ -427,9 +439,12 @@ impl Codec { Ok(Message::Verack) } - fn read_block(&self, mut _reader: R) -> Result { - trace!("block"); - bail!("unimplemented message type") + fn read_block(&self, mut reader: R) -> Result { + Ok(Message::Block { + version: Version(reader.read_u32::()?), + + block: Block::zcash_deserialize(&mut reader)?, + }) } fn read_getblocks(&self, mut reader: R) -> Result { diff --git a/zebra-network/src/protocol/message.rs b/zebra-network/src/protocol/message.rs index 29c98f99c..7c9bde4a6 100644 --- a/zebra-network/src/protocol/message.rs +++ b/zebra-network/src/protocol/message.rs @@ -138,6 +138,9 @@ pub enum Message { /// /// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#block) Block { + /// Transaction data format version (note, this is signed). + version: Version, + /// The block itself. block: Block, },