Move all beacon_block fns into the same file

This commit is contained in:
Paul Hauner 2019-02-05 12:33:52 +11:00
parent 449312d95c
commit b9dc8437c9
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
2 changed files with 16 additions and 22 deletions

View File

@ -1,12 +1,10 @@
use super::{BeaconBlockBody, Eth1Data, Hash256};
use super::{BeaconBlockBody, ChainSpec, Eth1Data, Hash256, ProposalSignedData};
use crate::test_utils::TestRandom;
use bls::Signature;
use rand::RngCore;
use serde_derive::Serialize;
use ssz::{hash, Decodable, DecodeError, Encodable, SszStream, TreeHash};
mod signing;
#[derive(Debug, PartialEq, Clone, Serialize)]
pub struct BeaconBlock {
pub slot: u64,
@ -22,6 +20,21 @@ impl BeaconBlock {
pub fn canonical_root(&self) -> Hash256 {
Hash256::from(&self.hash_tree_root()[..])
}
pub fn proposal_root(&self, spec: &ChainSpec) -> Hash256 {
let block_without_signature_root = {
let mut block_without_signature = self.clone();
block_without_signature.signature = spec.empty_signature.clone();
block_without_signature.canonical_root()
};
let proposal = ProposalSignedData {
slot: self.slot,
shard: spec.beacon_chain_shard_number,
block_root: block_without_signature_root,
};
Hash256::from_slice(&proposal.hash_tree_root()[..])
}
}
impl Encodable for BeaconBlock {

View File

@ -1,19 +0,0 @@
use crate::{BeaconBlock, ChainSpec, Hash256, ProposalSignedData};
use ssz::TreeHash;
impl BeaconBlock {
pub fn proposal_root(&self, spec: &ChainSpec) -> Hash256 {
let block_without_signature_root = {
let mut block_without_signature = self.clone();
block_without_signature.signature = spec.empty_signature.clone();
block_without_signature.canonical_root()
};
let proposal = ProposalSignedData {
slot: self.slot,
shard: spec.beacon_chain_shard_number,
block_root: block_without_signature_root,
};
Hash256::from_slice(&proposal.hash_tree_root()[..])
}
}