From 35f03dc55dd3879614da270456389ab191bc9b44 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Thu, 26 Sep 2019 22:39:04 -0400 Subject: [PATCH] Make Message.Block just point at a Block type, in codec call block.zcash_serialize() --- zebra-network/src/protocol/codec.rs | 7 +++++- zebra-network/src/protocol/message.rs | 34 ++------------------------- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/zebra-network/src/protocol/codec.rs b/zebra-network/src/protocol/codec.rs index 06ffbc61..42e64535 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::{ - serialization::{ReadZcashExt, WriteZcashExt}, + serialization::{ReadZcashExt, WriteZcashExt, ZcashSerialize}, types::{BlockHeight, Sha256dChecksum}, }; @@ -197,6 +197,11 @@ impl Codec { Pong(nonce) => { writer.write_u64::(nonce.0)?; } + Block { ref block } => { + block + .zcash_serialize(&mut writer) + .expect("Blocks must serialize."); + } _ => bail!("unimplemented message type"), } Ok(()) diff --git a/zebra-network/src/protocol/message.rs b/zebra-network/src/protocol/message.rs index 78a98e8b..ebf32cd0 100644 --- a/zebra-network/src/protocol/message.rs +++ b/zebra-network/src/protocol/message.rs @@ -136,38 +136,8 @@ pub enum Message { /// /// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#block) Block { - /// Block version information (note, this is signed). - version: Version, - - /// The hash value of the previous block (header) this - /// particular block references. - prev_block: BlockHeaderHash, - - /// The reference to a Merkle tree collection which is a hash - /// of all transactions related to this block. - merkle_root: MerkleRootHash, - - /// The root of the Sapling note commitment tree corresponding - /// to the final Sapling treestate of this block. - // TODO: more than just an array of bytes. - final_sapling_root: [u8; 32], - - /// A Unix timestamp recording when this block was created. - time: DateTime, - - /// The calculated difficulty target being used for this - /// block. - bits: u32, - - /// The nonce used to generate this block, to allow variations - /// of the header and compute different hashes. - nonce: [u8; 32], - - /// The Equihash solution. - solution: Vec, - - /// Transactions. - txns: Vec, + /// The block itself. + block: Block, }, /// A `getblocks` message.