ergo_chain_types/
preheader.rs1use crate::{BlockId, EcPoint, Header, Votes};
3
4#[derive(PartialEq, Eq, Debug, Clone)]
7pub struct PreHeader {
8 pub version: u8,
10 pub parent_id: BlockId,
12 pub timestamp: u64,
14 pub n_bits: u64,
16 pub height: u32,
18 pub miner_pk: Box<EcPoint>,
20 pub votes: Votes,
22}
23
24impl From<Header> for PreHeader {
25 fn from(bh: Header) -> Self {
26 PreHeader {
27 version: bh.version,
28 parent_id: bh.parent_id,
29 timestamp: bh.timestamp,
30 n_bits: bh.n_bits,
31 height: bh.height,
32 miner_pk: bh.autolykos_solution.miner_pk,
33 votes: bh.votes,
34 }
35 }
36}
37
38#[cfg(feature = "arbitrary")]
39mod arbitrary {
40 use proptest::array::{uniform3, uniform32};
41 use proptest::prelude::*;
42
43 use crate::EcPoint;
44
45 use super::*;
46
47 impl Arbitrary for PreHeader {
48 type Parameters = ();
49 fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
50 (
51 uniform32(1u8..),
52 946_674_000_000..2_500_400_300_000u64,
54 any::<u64>(),
55 1_000_000u32..10_000_000u32,
56 any::<Box<EcPoint>>(),
57 uniform3(1u8..),
58 )
59 .prop_map(|(parent_id, timestamp, n_bits, height, miner_pk, votes)| {
60 let parent_id = BlockId(parent_id.into());
61 let votes = Votes(votes);
62 Self {
63 version: 1,
64 parent_id,
65 timestamp,
66 n_bits,
67 height,
68 miner_pk,
69 votes,
70 }
71 })
72 .boxed()
73 }
74
75 type Strategy = BoxedStrategy<PreHeader>;
76 }
77}