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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
// This recently introduced lint does not play well with the derivative crate.
// We have both Ord and PartialOrd derive automatically by derivative's proc macros
// but clippy sees these as hand implementations.
// Putting this allow locally where it's found did not seem to supress it,
// likely due to the structure of how the proc macro derives the code.
// Doing what is suggested by this lint would just result in us actually doing
// hand implementations of the PartialOrd (an maybe PartialEq) when there's no need,
// possibly impacting PartialOrd performance on top of being unnecessary and occuring in generated code.
// Possibly the derivative crate could get updated to suppress this lint
// from within their proc macros itself. Issue: https://github.com/mcarton/rust-derivative/issues/115
#![allow(clippy::non_canonical_partial_ord_impl)]

pub mod address;
pub mod assets;
pub mod auxdata;
pub mod block;
pub mod builders;
pub mod byron;
pub mod certs;
pub mod crypto;
pub mod deposit;
pub mod fees;
pub mod genesis;
pub mod governance;
pub mod json;
pub mod min_ada;
pub mod plutus;
pub mod serialization;
pub mod transaction;
pub mod utils;

pub use assets::{Coin, Value};
pub use utils::NetworkId;

//pub mod legacy_address;

pub use cml_core::{
    error::{DeserializeError, DeserializeFailure},
    metadata::{TransactionMetadatum, TransactionMetadatumLabel},
    ordered_hash_map::OrderedHashMap,
    serialization::{Deserialize, LenEncoding, Serialize, StringEncoding},
    CertificateIndex, Epoch, Int, Slot, TransactionIndex,
};

pub mod cbor_encodings;

extern crate derivative;

// This file was code-generated using an experimental CDDL to rust tool:
// https://github.com/dcSpark/cddl-codegen

use address::RewardAccount;
use cbor_encodings::{
    DRepVotingThresholdsEncoding, PoolVotingThresholdsEncoding, ProtocolParamUpdateEncoding,
    RationalEncoding, UnitIntervalEncoding,
};
use governance::Voter;
use plutus::{CostModels, ExUnitPrices, ExUnits, PlutusV1Script, PlutusV2Script, PlutusV3Script};
use transaction::NativeScript;

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
pub struct DRepVotingThresholds {
    pub motion_no_confidence: UnitInterval,
    pub committee_normal: UnitInterval,
    pub committee_no_confidence: UnitInterval,
    pub update_constitution: UnitInterval,
    pub hard_fork_initiation: UnitInterval,
    pub pp_network_group: UnitInterval,
    pub pp_economic_group: UnitInterval,
    pub pp_technical_group: UnitInterval,
    pub pp_governance_group: UnitInterval,
    pub treasury_withdrawal: UnitInterval,
    #[serde(skip)]
    pub encodings: Option<DRepVotingThresholdsEncoding>,
}

impl DRepVotingThresholds {
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        motion_no_confidence: UnitInterval,
        committee_normal: UnitInterval,
        committee_no_confidence: UnitInterval,
        update_constitution: UnitInterval,
        hard_fork_initiation: UnitInterval,
        pp_network_group: UnitInterval,
        pp_economic_group: UnitInterval,
        pp_technical_group: UnitInterval,
        pp_governance_group: UnitInterval,
        treasury_withdrawal: UnitInterval,
    ) -> Self {
        Self {
            motion_no_confidence,
            committee_normal,
            committee_no_confidence,
            update_constitution,
            hard_fork_initiation,
            pp_network_group,
            pp_economic_group,
            pp_technical_group,
            pp_governance_group,
            treasury_withdrawal,
            encodings: None,
        }
    }
}

pub type DeltaCoin = Int;

pub type PolicyId = cml_crypto::ScriptHash;

pub type PolicyIdList = Vec<PolicyId>;

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
pub struct PoolVotingThresholds {
    pub motion_no_confidence: UnitInterval,
    pub committee_normal: UnitInterval,
    pub committee_no_confidence: UnitInterval,
    pub hard_fork_initiation: UnitInterval,
    #[serde(skip)]
    pub encodings: Option<PoolVotingThresholdsEncoding>,
}

impl PoolVotingThresholds {
    pub fn new(
        motion_no_confidence: UnitInterval,
        committee_normal: UnitInterval,
        committee_no_confidence: UnitInterval,
        hard_fork_initiation: UnitInterval,
    ) -> Self {
        Self {
            motion_no_confidence,
            committee_normal,
            committee_no_confidence,
            hard_fork_initiation,
            encodings: None,
        }
    }
}

pub type Port = u16;

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
pub struct ProtocolParamUpdate {
    pub minfee_a: Option<u64>,
    pub minfee_b: Option<u64>,
    pub max_block_body_size: Option<u64>,
    pub max_transaction_size: Option<u64>,
    pub max_block_header_size: Option<u64>,
    pub key_deposit: Option<Coin>,
    pub pool_deposit: Option<Coin>,
    pub maximum_epoch: Option<Epoch>,
    pub n_opt: Option<u64>,
    pub pool_pledge_influence: Option<Rational>,
    pub expansion_rate: Option<UnitInterval>,
    pub treasury_growth_rate: Option<UnitInterval>,
    pub min_pool_cost: Option<Coin>,
    pub ada_per_utxo_byte: Option<Coin>,
    pub cost_models_for_script_languages: Option<CostModels>,
    pub execution_costs: Option<ExUnitPrices>,
    pub max_tx_ex_units: Option<ExUnits>,
    pub max_block_ex_units: Option<ExUnits>,
    pub max_value_size: Option<u64>,
    pub collateral_percentage: Option<u64>,
    pub max_collateral_inputs: Option<u64>,
    pub pool_voting_thresholds: Option<PoolVotingThresholds>,
    pub d_rep_voting_thresholds: Option<DRepVotingThresholds>,
    pub min_committee_size: Option<u64>,
    pub committee_term_limit: Option<u64>,
    pub governance_action_validity_period: Option<Epoch>,
    pub governance_action_deposit: Option<Coin>,
    pub d_rep_deposit: Option<Coin>,
    pub d_rep_inactivity_period: Option<Epoch>,
    #[serde(skip)]
    pub encodings: Option<ProtocolParamUpdateEncoding>,
}

impl ProtocolParamUpdate {
    pub fn new() -> Self {
        Self {
            minfee_a: None,
            minfee_b: None,
            max_block_body_size: None,
            max_transaction_size: None,
            max_block_header_size: None,
            key_deposit: None,
            pool_deposit: None,
            maximum_epoch: None,
            n_opt: None,
            pool_pledge_influence: None,
            expansion_rate: None,
            treasury_growth_rate: None,
            min_pool_cost: None,
            ada_per_utxo_byte: None,
            cost_models_for_script_languages: None,
            execution_costs: None,
            max_tx_ex_units: None,
            max_block_ex_units: None,
            max_value_size: None,
            collateral_percentage: None,
            max_collateral_inputs: None,
            pool_voting_thresholds: None,
            d_rep_voting_thresholds: None,
            min_committee_size: None,
            committee_term_limit: None,
            governance_action_validity_period: None,
            governance_action_deposit: None,
            d_rep_deposit: None,
            d_rep_inactivity_period: None,
            encodings: None,
        }
    }
}

impl Default for ProtocolParamUpdate {
    fn default() -> Self {
        Self::new()
    }
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
pub struct Rational {
    pub numerator: u64,
    pub denominator: u64,
    #[serde(skip)]
    pub encodings: Option<RationalEncoding>,
}

impl Rational {
    pub fn new(numerator: u64, denominator: u64) -> Self {
        Self {
            numerator,
            denominator,
            encodings: None,
        }
    }
}

pub type RewardAccountList = Vec<RewardAccount>;

#[derive(
    Clone, Debug, derivative::Derivative, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
)]
#[derivative(Hash, PartialEq)]
pub enum Script {
    Native {
        script: NativeScript,
        #[serde(skip)]
        #[derivative(PartialEq = "ignore", Hash = "ignore")]
        len_encoding: LenEncoding,
        #[serde(skip)]
        #[derivative(PartialEq = "ignore", Hash = "ignore")]
        tag_encoding: Option<cbor_event::Sz>,
    },
    PlutusV1 {
        script: PlutusV1Script,
        #[serde(skip)]
        #[derivative(PartialEq = "ignore", Hash = "ignore")]
        len_encoding: LenEncoding,
        #[serde(skip)]
        #[derivative(PartialEq = "ignore", Hash = "ignore")]
        tag_encoding: Option<cbor_event::Sz>,
    },
    PlutusV2 {
        script: PlutusV2Script,
        #[serde(skip)]
        #[derivative(PartialEq = "ignore", Hash = "ignore")]
        len_encoding: LenEncoding,
        #[serde(skip)]
        #[derivative(PartialEq = "ignore", Hash = "ignore")]
        tag_encoding: Option<cbor_event::Sz>,
    },
    PlutusV3 {
        script: PlutusV3Script,
        #[serde(skip)]
        #[derivative(PartialEq = "ignore", Hash = "ignore")]
        len_encoding: LenEncoding,
        #[serde(skip)]
        #[derivative(PartialEq = "ignore", Hash = "ignore")]
        tag_encoding: Option<cbor_event::Sz>,
    },
}

impl Script {
    pub fn new_native(script: NativeScript) -> Self {
        Self::Native {
            script,
            len_encoding: LenEncoding::default(),
            tag_encoding: None,
        }
    }

    pub fn new_plutus_v1(script: PlutusV1Script) -> Self {
        Self::PlutusV1 {
            script,
            len_encoding: LenEncoding::default(),
            tag_encoding: None,
        }
    }

    pub fn new_plutus_v2(script: PlutusV2Script) -> Self {
        Self::PlutusV2 {
            script,
            len_encoding: LenEncoding::default(),
            tag_encoding: None,
        }
    }

    pub fn new_plutus_v3(script: PlutusV3Script) -> Self {
        Self::PlutusV3 {
            script,
            len_encoding: LenEncoding::default(),
            tag_encoding: None,
        }
    }
}

pub type SubCoin = Rational;

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
pub struct UnitInterval {
    pub start: u64,
    pub end: u64,
    #[serde(skip)]
    pub encodings: Option<UnitIntervalEncoding>,
}

impl UnitInterval {
    pub fn new(start: u64, end: u64) -> Self {
        Self {
            start,
            end,
            encodings: None,
        }
    }
}

pub type VoterList = Vec<Voter>;

pub type Withdrawals = OrderedHashMap<RewardAccount, Coin>;