use crate::{BlockId, EcPoint, Header, Votes};
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct PreHeader {
pub version: u8,
pub parent_id: BlockId,
pub timestamp: u64,
pub n_bits: u64,
pub height: u32,
pub miner_pk: Box<EcPoint>,
pub votes: Votes,
}
impl From<Header> for PreHeader {
fn from(bh: Header) -> Self {
PreHeader {
version: bh.version,
parent_id: bh.parent_id,
timestamp: bh.timestamp,
n_bits: bh.n_bits,
height: bh.height,
miner_pk: bh.autolykos_solution.miner_pk,
votes: bh.votes,
}
}
}
#[cfg(feature = "arbitrary")]
mod arbitrary {
use proptest::array::{uniform3, uniform32};
use proptest::prelude::*;
use crate::EcPoint;
use super::*;
impl Arbitrary for PreHeader {
type Parameters = ();
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
(
uniform32(1u8..),
946_674_000_000..2_500_400_300_000u64,
any::<u64>(),
1_000_000u32..10_000_000u32,
any::<Box<EcPoint>>(),
uniform3(1u8..),
)
.prop_map(|(parent_id, timestamp, n_bits, height, miner_pk, votes)| {
let parent_id = BlockId(parent_id.into());
let votes = Votes(votes);
Self {
version: 1,
parent_id,
timestamp,
n_bits,
height,
miner_pk,
votes,
}
})
.boxed()
}
type Strategy = BoxedStrategy<PreHeader>;
}
}