From cb97870c151383957c3b31e5f7812bc04b61c920 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 12 Feb 2019 11:57:34 +1100 Subject: [PATCH] Add `genesis()` function to BeaconBlock --- eth2/types/src/beacon_block.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/eth2/types/src/beacon_block.rs b/eth2/types/src/beacon_block.rs index 2e844859a3..f68f793164 100644 --- a/eth2/types/src/beacon_block.rs +++ b/eth2/types/src/beacon_block.rs @@ -17,6 +17,28 @@ pub struct BeaconBlock { } impl BeaconBlock { + /// Produce the first block of the Beacon Chain. + pub fn genesis(state_root: Hash256, spec: &ChainSpec) -> BeaconBlock { + BeaconBlock { + slot: spec.genesis_slot, + parent_root: spec.zero_hash, + state_root, + randao_reveal: spec.empty_signature.clone(), + eth1_data: Eth1Data { + deposit_root: spec.zero_hash, + block_hash: spec.zero_hash, + }, + signature: spec.empty_signature.clone(), + body: BeaconBlockBody { + proposer_slashings: vec![], + attester_slashings: vec![], + attestations: vec![], + deposits: vec![], + exits: vec![], + }, + } + } + pub fn canonical_root(&self) -> Hash256 { Hash256::from(&self.hash_tree_root()[..]) }