cml_chain/genesis/
network_info.rs

1use crate::{
2    byron::ProtocolMagic,
3    plutus::{CostModels, Language},
4};
5use cml_core::network::{
6    BYRON_MAINNET_NETWORK_MAGIC, BYRON_TESTNET_NETWORK_MAGIC, PREPROD_NETWORK_MAGIC,
7    PREVIEW_NETWORK_MAGIC, SANCHO_TESTNET_NETWORK_MAGIC,
8};
9
10#[derive(
11    Debug, Clone, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize,
12)]
13pub struct NetworkInfo {
14    network_id: u8,
15    protocol_magic: ProtocolMagic,
16}
17impl NetworkInfo {
18    pub fn new(network_id: u8, protocol_magic: ProtocolMagic) -> Self {
19        Self {
20            network_id,
21            protocol_magic,
22        }
23    }
24
25    pub fn network_id(&self) -> u8 {
26        self.network_id
27    }
28
29    pub fn protocol_magic(&self) -> ProtocolMagic {
30        self.protocol_magic
31    }
32
33    /// This is the old testnet - most likely you want to use preview()/preprod()
34    pub fn testnet() -> Self {
35        Self {
36            network_id: 0b0000,
37            protocol_magic: ProtocolMagic::from(BYRON_TESTNET_NETWORK_MAGIC),
38        }
39    }
40
41    pub fn mainnet() -> Self {
42        Self {
43            network_id: 0b0001,
44            protocol_magic: ProtocolMagic::from(BYRON_MAINNET_NETWORK_MAGIC),
45        }
46    }
47
48    pub fn preview() -> Self {
49        Self {
50            network_id: 0b0000,
51            protocol_magic: ProtocolMagic::from(PREVIEW_NETWORK_MAGIC),
52        }
53    }
54
55    pub fn preprod() -> Self {
56        Self {
57            network_id: 0b0000,
58            protocol_magic: ProtocolMagic::from(PREPROD_NETWORK_MAGIC),
59        }
60    }
61
62    pub fn sancho_testnet() -> Self {
63        Self {
64            network_id: 0b0000,
65            protocol_magic: ProtocolMagic::from(SANCHO_TESTNET_NETWORK_MAGIC),
66        }
67    }
68}
69
70// TODO: https://github.com/dcSpark/cardano-multiplatform-lib/issues/92
71pub fn plutus_alonzo_cost_models() -> CostModels {
72    let ops = vec![
73        197209, 0, 1, 1, 396231, 621, 0, 1, 150000, 1000, 0, 1, 150000, 32, 2477736, 29175, 4,
74        29773, 100, 29773, 100, 29773, 100, 29773, 100, 29773, 100, 29773, 100, 100, 100, 29773,
75        100, 150000, 32, 150000, 32, 150000, 32, 150000, 1000, 0, 1, 150000, 32, 150000, 1000, 0,
76        8, 148000, 425507, 118, 0, 1, 1, 150000, 1000, 0, 8, 150000, 112536, 247, 1, 150000, 10000,
77        1, 136542, 1326, 1, 1000, 150000, 1000, 1, 150000, 32, 150000, 32, 150000, 32, 1, 1,
78        150000, 1, 150000, 4, 103599, 248, 1, 103599, 248, 1, 145276, 1366, 1, 179690, 497, 1,
79        150000, 32, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 148000, 425507,
80        118, 0, 1, 1, 61516, 11218, 0, 1, 150000, 32, 148000, 425507, 118, 0, 1, 1, 148000, 425507,
81        118, 0, 1, 1, 2477736, 29175, 4, 0, 82363, 4, 150000, 5000, 0, 1, 150000, 32, 197209, 0, 1,
82        1, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 150000, 32,
83        3345831, 1, 1,
84    ];
85
86    let mut res = CostModels::default();
87    res.inner.insert(Language::PlutusV1 as u64, ops);
88    res
89}