<commit_before>use super::utils::types::Hash256;
use super::attestation_record::AttestationRecord;
use super::ssz;

const SSZ_BLOCK_LENGTH: usize = 192;

pub struct Block {
    pub parent_hash: Hash256,
    pub slot_number: u64,
    pub randao_reveal: Hash256,
    pub attestations: Vec<AttestationRecord>,
    pub pow_chain_ref: Hash256,
    pub active_state_root: Hash256,
    pub crystallized_state_root: Hash256,
}

impl Block {
    pub fn zero() -> Self {
        Self {
            parent_hash: Hash256::zero(),
            slot_number: 0,
            randao_reveal: Hash256::zero(),
            attestations: vec![],
            pow_chain_ref: Hash256::zero(),
            active_state_root: Hash256::zero(),
            crystallized_state_root: Hash256::zero(),
        }
    }

    // Not sure if this will be useful, leaving it here for the
    // time being.
    pub fn ssz_encode_without_attestations(&self) 
        -> [u8; SSZ_BLOCK_LENGTH]
    {
        let mut s = ssz::SszStream::new();
        s.append(&self.parent_hash);
        s.append(&self.slot_number);
        s.append(&self.randao_reveal);
        s.append(&self.pow_chain_ref);
        s.append(&self.active_state_root);
        s.append(&self.crystallized_state_root);
        let vec = s.drain();
        let mut encoded = [0; SSZ_BLOCK_LENGTH];
        encoded.copy_from_slice(&vec); encoded
    }<commit_msg>Update ssz for Block<commit_after>use super::utils::types::Hash256;
use super::attestation_record::AttestationRecord;
use super::ssz::{ Encodable, SszStream };

const SSZ_BLOCK_LENGTH: usize = 192;

pub struct Block {
    pub parent_hash: Hash256,
    pub slot_number: u64,
    pub randao_reveal: Hash256,
    pub attestations: Vec<AttestationRecord>,
    pub pow_chain_ref: Hash256,
    pub active_state_root: Hash256,
    pub crystallized_state_root: Hash256,
}

impl Block {
    pub fn zero() -> Self {
        Self {
            parent_hash: Hash256::zero(),
            slot_number: 0,
            randao_reveal: Hash256::zero(),
            attestations: vec![],
            pow_chain_ref: Hash256::zero(),
            active_state_root: Hash256::zero(),
            crystallized_state_root: Hash256::zero(),
        }
    }

    /// 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 = SszStream::new();
        s.append(&self.parent_hash);
        s.append(&self.slot_number);
        s.append(&self.randao_reveal);
        s.append(&self.pow_chain_ref);
        s.append(&self.active_state_root);
        s.append(&self.crystallized_state_root);
        let vec = s.drain();
        let mut encoded = [0; SSZ_BLOCK_LENGTH];
        encoded.copy_from_slice(&vec); encoded
    }
}

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);
    }
{'fraction_non_alphanumeric': 0.11926319075866375, 'fraction_numerical': 0.025600999063378083, 'mean_word_length': 2.640909090909091, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4195138', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1034, 'n_words': 213}