From cbaee765e35e01a4fd045e8ce99618e35c8fa07e Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 10 Sep 2018 07:51:57 +0200 Subject: [PATCH] Update ssz for Block --- lighthouse/state/block.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lighthouse/state/block.rs b/lighthouse/state/block.rs index 676d716bd..a65c71f7c 100644 --- a/lighthouse/state/block.rs +++ b/lighthouse/state/block.rs @@ -1,6 +1,6 @@ use super::utils::types::Hash256; use super::attestation_record::AttestationRecord; -use super::ssz; +use super::ssz::{ Encodable, SszStream }; const SSZ_BLOCK_LENGTH: usize = 192; @@ -27,12 +27,12 @@ impl Block { } } - // Not sure if this will be useful, leaving it here for the - // time being. - pub fn ssz_encode_without_attestations(&self) + /// Return the bytes that should be signed in order to + /// attest for this block. + pub fn encode_for_signing(&self) -> [u8; SSZ_BLOCK_LENGTH] { - let mut s = ssz::SszStream::new(); + let mut s = SszStream::new(); s.append(&self.parent_hash); s.append(&self.slot_number); s.append(&self.randao_reveal); @@ -45,6 +45,19 @@ impl Block { } } +impl Encodable for Block { + fn ssz_append(&self, s: &mut SszStream) { + let mut s = SszStream::new(); + s.append(&self.parent_hash); + s.append(&self.slot_number); + s.append(&self.randao_reveal); + s.append(&self.attestations); + s.append(&self.pow_chain_ref); + s.append(&self.active_state_root); + s.append(&self.crystallized_state_root); + } +} + #[cfg(test)] mod tests {