Add further BeaconBlock v0.5.0 updates

This commit is contained in:
Paul Hauner 2019-03-15 18:34:54 +11:00
parent dffc26a466
commit 57c4389f9c
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6

View File

@ -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)]