1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use chain_impl_mockchain::fee::LinearFee;
use jormungandr_lib::interfaces::{CommitteeIdDef, ConsensusLeaderId, LinearFeeDef};
use jormungandr_lib::time::SecondsSinceUnixEpoch;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Blockchain {
    #[serde(default)]
    pub slot_duration: u8,
    #[serde(default)]
    pub block_content_max_size: u32,
    #[serde(with = "time::serde::rfc3339", default = "default_block0_time")]
    pub block0_time: OffsetDateTime,
    #[serde(default)]
    pub tx_max_expiry_epochs: Option<u8>,
    #[serde(default)]
    pub consensus_leader_ids: Vec<ConsensusLeaderId>,
    #[serde(with = "LinearFeeDef")]
    pub linear_fees: LinearFee,
    #[serde(default)]
    pub committees: Vec<CommitteeIdDef>,
}

impl Default for Blockchain {
    fn default() -> Self {
        Self {
            slot_duration: 20,
            block0_time: default_block0_time(),
            block_content_max_size: 102400,
            tx_max_expiry_epochs: Some(2),
            consensus_leader_ids: Vec::new(),
            linear_fees: LinearFee::new(0, 0, 0),
            committees: Vec::new(),
        }
    }
}
impl Blockchain {
    pub fn block0_date_as_unix(&self) -> SecondsSinceUnixEpoch {
        SecondsSinceUnixEpoch::from_secs(self.block0_time.unix_timestamp() as u64)
    }
}

fn default_block0_time() -> OffsetDateTime {
    OffsetDateTime::now_utc()
}