Skip to main content

ogmios_client/schema/
genesis.rs

1//! Genesis configuration types for different Cardano eras.
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5use super::primitives::*;
6use super::protocol::*;
7
8/// Genesis configuration - varies by era.
9#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10#[serde(tag = "era", rename_all = "camelCase")]
11pub enum GenesisConfiguration {
12    /// Byron genesis configuration.
13    Byron(GenesisByron),
14    /// Shelley genesis configuration.
15    Shelley(GenesisShelley),
16    /// Alonzo genesis configuration.
17    Alonzo(GenesisAlonzo),
18    /// Conway genesis configuration.
19    Conway(GenesisConway),
20}
21
22/// Byron genesis configuration.
23#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase")]
25pub struct GenesisByron {
26    /// Genesis key hashes.
27    #[serde(default)]
28    pub genesis_key_hashes: Vec<DigestBlake2b224>,
29    /// Genesis delegates.
30    #[serde(default)]
31    pub genesis_delegates: HashMap<String, GenesisDelegate>,
32    /// Start time.
33    pub start_time: UtcTime,
34    /// Initial funds.
35    #[serde(default)]
36    pub initial_funds: HashMap<Address, Lovelace>,
37    /// Security parameter.
38    pub security_parameter: u64,
39    /// Network magic.
40    pub network_magic: NetworkMagic,
41    /// Protocol parameters.
42    #[serde(default)]
43    pub protocol_parameters: Option<BootstrapProtocolParameters>,
44}
45
46/// Genesis delegate.
47#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
48#[serde(rename_all = "camelCase")]
49pub struct GenesisDelegate {
50    /// Delegate key hash.
51    pub delegate: DigestBlake2b224,
52    /// VRF key hash.
53    pub vrf: VrfVerificationKey,
54}
55
56/// Bootstrap (Byron) protocol parameters.
57#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
58#[serde(rename_all = "camelCase")]
59pub struct BootstrapProtocolParameters {
60    /// Minimum fee coefficient.
61    pub min_fee_coefficient: u64,
62    /// Minimum fee constant.
63    pub min_fee_constant: Lovelace,
64    /// Maximum block size.
65    pub max_block_body_size: NumberOfBytes,
66    /// Maximum header size.
67    pub max_block_header_size: NumberOfBytes,
68    /// Maximum transaction size.
69    pub max_transaction_size: NumberOfBytes,
70    /// Max proposals per epoch.
71    #[serde(default)]
72    pub max_update_proposals_per_epoch: Option<u64>,
73}
74
75/// Shelley genesis configuration.
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
77#[serde(rename_all = "camelCase")]
78pub struct GenesisShelley {
79    /// Network ID.
80    pub network: String,
81    /// Network magic.
82    pub network_magic: NetworkMagic,
83    /// Start time.
84    pub start_time: UtcTime,
85    /// Security parameter.
86    pub security_parameter: u64,
87    /// Active slots coefficient.
88    pub active_slots_coefficient: Ratio,
89    /// Epoch length.
90    pub epoch_length: u64,
91    /// Slots per KES period.
92    pub slots_per_kes_period: u64,
93    /// Max KES evolutions.
94    pub max_kes_evolutions: u64,
95    /// Slot length in seconds.
96    pub slot_length: RelativeTime,
97    /// Update quorum.
98    pub update_quorum: u64,
99    /// Max lovelace supply.
100    pub max_lovelace_supply: Lovelace,
101    /// Initial funds.
102    #[serde(default)]
103    pub initial_funds: HashMap<Address, Lovelace>,
104    /// Initial stake pools.
105    #[serde(default)]
106    pub initial_stake_pools: GenesisStakePools,
107    /// Initial delegates.
108    #[serde(default)]
109    pub initial_delegates: Vec<InitialDelegate>,
110    /// Protocol parameters.
111    #[serde(default)]
112    pub protocol_parameters: Option<ProtocolParameters>,
113}
114
115/// Genesis stake pools configuration.
116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
117#[serde(rename_all = "camelCase")]
118pub struct GenesisStakePools {
119    /// Stake pool registrations.
120    #[serde(default)]
121    pub stake_pools: HashMap<StakePoolId, serde_json::Value>,
122    /// Stake delegations.
123    #[serde(default)]
124    pub delegators: HashMap<DigestBlake2b224, StakePoolId>,
125}
126
127/// Initial delegate configuration.
128#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
129#[serde(rename_all = "camelCase")]
130pub struct InitialDelegate {
131    /// Issuer (genesis key hash).
132    pub issuer: DigestBlake2b224,
133    /// Delegate.
134    pub delegate: DigestBlake2b224,
135    /// VRF key.
136    pub vrf: VrfVerificationKey,
137}
138
139/// Alonzo genesis configuration.
140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
141#[serde(rename_all = "camelCase")]
142pub struct GenesisAlonzo {
143    /// Plutus cost models.
144    pub cost_models: CostModels,
145    /// Script execution prices.
146    pub prices: ScriptExecutionPrices,
147    /// Max execution units per transaction.
148    pub max_execution_units_per_transaction: super::transaction::ExUnits,
149    /// Max execution units per block.
150    pub max_execution_units_per_block: super::transaction::ExUnits,
151    /// Max value size.
152    pub max_value_size: NumberOfBytes,
153    /// Collateral percentage.
154    pub collateral_percentage: u64,
155    /// Max collateral inputs.
156    pub max_collateral_inputs: u64,
157}
158
159/// Conway genesis configuration.
160#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
161#[serde(rename_all = "camelCase")]
162pub struct GenesisConway {
163    /// Constitution.
164    #[serde(default)]
165    pub constitution: Option<super::governance::Constitution>,
166    /// Constitutional committee.
167    #[serde(default)]
168    pub constitutional_committee: Option<ConstitutionalCommitteeConfig>,
169    /// DRep voting thresholds.
170    #[serde(default)]
171    pub delegate_representative_voting_thresholds: Option<DelegateRepresentativeVotingThresholds>,
172    /// Stake pool voting thresholds.
173    #[serde(default)]
174    pub stake_pool_voting_thresholds: Option<StakePoolVotingThresholds>,
175    /// Governance action lifetime.
176    #[serde(default)]
177    pub governance_action_lifetime: Option<u64>,
178    /// Governance action deposit.
179    #[serde(default)]
180    pub governance_action_deposit: Option<AdaValue>,
181    /// DRep deposit.
182    #[serde(default)]
183    pub delegate_representative_deposit: Option<AdaValue>,
184    /// DRep max idle time.
185    #[serde(default)]
186    pub delegate_representative_max_idle_time: Option<u64>,
187    /// Constitutional committee min size.
188    #[serde(default)]
189    pub constitutional_committee_min_size: Option<u64>,
190    /// Constitutional committee max term length.
191    #[serde(default)]
192    pub constitutional_committee_max_term_length: Option<u64>,
193    /// Plutus V3 cost model.
194    #[serde(default)]
195    pub plutus_cost_models: Option<CostModels>,
196    /// Min fee for reference scripts.
197    #[serde(default)]
198    pub min_fee_reference_scripts: Option<MinFeeReferenceScripts>,
199}
200
201/// Constitutional committee initial configuration.
202#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
203#[serde(rename_all = "camelCase")]
204pub struct ConstitutionalCommitteeConfig {
205    /// Initial members.
206    #[serde(default)]
207    pub members: Vec<super::governance::ConstitutionalCommitteeMember>,
208    /// Quorum threshold.
209    pub quorum: Ratio,
210}