Move all beacon_block fns into the same file
This commit is contained in:
parent
449312d95c
commit
b9dc8437c9
@ -1,12 +1,10 @@
|
|||||||
use super::{BeaconBlockBody, Eth1Data, Hash256};
|
use super::{BeaconBlockBody, ChainSpec, Eth1Data, Hash256, ProposalSignedData};
|
||||||
use crate::test_utils::TestRandom;
|
use crate::test_utils::TestRandom;
|
||||||
use bls::Signature;
|
use bls::Signature;
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use serde_derive::Serialize;
|
use serde_derive::Serialize;
|
||||||
use ssz::{hash, Decodable, DecodeError, Encodable, SszStream, TreeHash};
|
use ssz::{hash, Decodable, DecodeError, Encodable, SszStream, TreeHash};
|
||||||
|
|
||||||
mod signing;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Serialize)]
|
#[derive(Debug, PartialEq, Clone, Serialize)]
|
||||||
pub struct BeaconBlock {
|
pub struct BeaconBlock {
|
||||||
pub slot: u64,
|
pub slot: u64,
|
||||||
@ -22,6 +20,21 @@ impl BeaconBlock {
|
|||||||
pub fn canonical_root(&self) -> Hash256 {
|
pub fn canonical_root(&self) -> Hash256 {
|
||||||
Hash256::from(&self.hash_tree_root()[..])
|
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 {
|
impl Encodable for BeaconBlock {
|
@ -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()[..])
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user