From 57c4389f9c476c96cbad13484642e6bacb101e8e Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 15 Mar 2019 18:34:54 +1100 Subject: [PATCH] Add further BeaconBlock v0.5.0 updates --- eth2/types/src/beacon_block.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/eth2/types/src/beacon_block.rs b/eth2/types/src/beacon_block.rs index 7fa3f5e11..bfe266cbd 100644 --- a/eth2/types/src/beacon_block.rs +++ b/eth2/types/src/beacon_block.rs @@ -1,5 +1,5 @@ use crate::test_utils::TestRandom; -use crate::{BeaconBlockBody, ChainSpec, Eth1Data, Hash256, Slot}; +use crate::*; use bls::Signature; use rand::RngCore; use serde_derive::{Deserialize, Serialize}; @@ -31,14 +31,14 @@ pub struct BeaconBlock { } impl BeaconBlock { - /// The first block of the Beacon Chain. + /// Returns an empty block to be used during genesis. /// /// Spec v0.5.0 - pub fn genesis(state_root: Hash256, spec: &ChainSpec) -> BeaconBlock { + pub fn empty(spec: &ChainSpec) -> BeaconBlock { BeaconBlock { slot: spec.genesis_slot, previous_block_root: spec.zero_hash, - state_root, + state_root: spec.zero_hash, body: BeaconBlockBody { randao_reveal: spec.empty_signature.clone(), eth1_data: Eth1Data { @@ -62,6 +62,19 @@ impl BeaconBlock { pub fn canonical_root(&self) -> Hash256 { Hash256::from_slice(&self.hash_tree_root()[..]) } + + /// Returns a "temporary" header, where the `state_root` is `spec.zero_hash`. + /// + /// Spec v0.5.0 + pub fn into_temporary_header(&self, spec: &ChainSpec) -> BeaconBlockHeader { + BeaconBlockHeader { + slot: self.slot, + previous_block_root: self.previous_block_root, + state_root: spec.zero_hash, + block_body_root: Hash256::from_slice(&self.hash_tree_root()), + signature: self.signature, + } + } } #[cfg(test)]