cml_chain/
lib.rs

1// This recently introduced lint does not play well with the derivative crate.
2// We have both Ord and PartialOrd derive automatically by derivative's proc macros
3// but clippy sees these as hand implementations.
4// Putting this allow locally where it's found did not seem to supress it,
5// likely due to the structure of how the proc macro derives the code.
6// Doing what is suggested by this lint would just result in us actually doing
7// hand implementations of the PartialOrd (an maybe PartialEq) when there's no need,
8// possibly impacting PartialOrd performance on top of being unnecessary and occuring in generated code.
9// Possibly the derivative crate could get updated to suppress this lint
10// from within their proc macros itself. Issue: https://github.com/mcarton/rust-derivative/issues/115
11#![allow(clippy::non_canonical_partial_ord_impl)]
12
13pub mod address;
14pub mod assets;
15pub mod auxdata;
16pub mod block;
17pub mod builders;
18pub mod byron;
19pub mod certs;
20pub mod crypto;
21pub mod deposit;
22pub mod fees;
23pub mod genesis;
24pub mod governance;
25pub mod json;
26pub mod min_ada;
27pub mod plutus;
28pub mod serialization;
29pub mod transaction;
30pub mod utils;
31
32pub use assets::{Coin, Value};
33use certs::{Certificate, CommitteeColdCredential};
34use cml_crypto::Ed25519KeyHash;
35use crypto::{BootstrapWitness, Vkeywitness};
36use utils::NonemptySetRawBytes;
37pub use utils::{NetworkId, NonemptySet, Set};
38
39//pub mod legacy_address;
40
41pub use cml_core::{
42    error::{DeserializeError, DeserializeFailure},
43    ordered_hash_map::OrderedHashMap,
44    serialization::{Deserialize, LenEncoding, Serialize, StringEncoding},
45    CertificateIndex, Epoch, Int, Slot, TransactionIndex,
46};
47
48pub mod cbor_encodings;
49
50extern crate derivative;
51
52// This file was code-generated using an experimental CDDL to rust tool:
53// https://github.com/dcSpark/cddl-codegen
54
55use address::RewardAccount;
56use cbor_encodings::{
57    DRepVotingThresholdsEncoding, PoolVotingThresholdsEncoding, ProtocolParamUpdateEncoding,
58    RationalEncoding, UnitIntervalEncoding,
59};
60use governance::{ProposalProcedure, Voter};
61use plutus::{
62    CostModels, ExUnitPrices, ExUnits, PlutusData, PlutusV1Script, PlutusV2Script, PlutusV3Script,
63};
64use transaction::{NativeScript, TransactionInput};
65
66#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
67pub struct DRepVotingThresholds {
68    pub motion_no_confidence: UnitInterval,
69    pub committee_normal: UnitInterval,
70    pub committee_no_confidence: UnitInterval,
71    pub update_constitution: UnitInterval,
72    pub hard_fork_initiation: UnitInterval,
73    pub pp_network_group: UnitInterval,
74    pub pp_economic_group: UnitInterval,
75    pub pp_technical_group: UnitInterval,
76    pub pp_governance_group: UnitInterval,
77    pub treasury_withdrawal: UnitInterval,
78    #[serde(skip)]
79    pub encodings: Option<DRepVotingThresholdsEncoding>,
80}
81
82impl DRepVotingThresholds {
83    #[allow(clippy::too_many_arguments)]
84    pub fn new(
85        motion_no_confidence: UnitInterval,
86        committee_normal: UnitInterval,
87        committee_no_confidence: UnitInterval,
88        update_constitution: UnitInterval,
89        hard_fork_initiation: UnitInterval,
90        pp_network_group: UnitInterval,
91        pp_economic_group: UnitInterval,
92        pp_technical_group: UnitInterval,
93        pp_governance_group: UnitInterval,
94        treasury_withdrawal: UnitInterval,
95    ) -> Self {
96        Self {
97            motion_no_confidence,
98            committee_normal,
99            committee_no_confidence,
100            update_constitution,
101            hard_fork_initiation,
102            pp_network_group,
103            pp_economic_group,
104            pp_technical_group,
105            pp_governance_group,
106            treasury_withdrawal,
107            encodings: None,
108        }
109    }
110}
111
112pub type DeltaCoin = Int;
113
114pub type NonemptySetBootstrapWitness = NonemptySet<BootstrapWitness>;
115
116pub type NonemptySetCertificate = NonemptySet<Certificate>;
117
118pub type NonemptySetNativeScript = NonemptySet<NativeScript>;
119
120pub type NonemptySetPlutusData = NonemptySet<PlutusData>;
121
122pub type NonemptySetPlutusV1Script = NonemptySet<PlutusV1Script>;
123
124pub type NonemptySetPlutusV2Script = NonemptySet<PlutusV2Script>;
125
126pub type NonemptySetPlutusV3Script = NonemptySet<PlutusV3Script>;
127
128pub type NonemptySetProposalProcedure = NonemptySet<ProposalProcedure>;
129
130pub type NonemptySetTransactionInput = NonemptySet<TransactionInput>;
131
132pub type NonemptySetVkeywitness = NonemptySet<Vkeywitness>;
133
134pub type PolicyId = cml_crypto::ScriptHash;
135
136pub type PolicyIdList = Vec<PolicyId>;
137
138pub type RequiredSigners = NonemptySetRawBytes<Ed25519KeyHash>;
139
140#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
141pub struct PoolVotingThresholds {
142    pub motion_no_confidence: UnitInterval,
143    pub committee_normal: UnitInterval,
144    pub committee_no_confidence: UnitInterval,
145    pub hard_fork_initiation: UnitInterval,
146    pub security_relevant_parameter_voting_threshold: UnitInterval,
147    #[serde(skip)]
148    pub encodings: Option<PoolVotingThresholdsEncoding>,
149}
150
151impl PoolVotingThresholds {
152    pub fn new(
153        motion_no_confidence: UnitInterval,
154        committee_normal: UnitInterval,
155        committee_no_confidence: UnitInterval,
156        hard_fork_initiation: UnitInterval,
157        security_relevant_parameter_voting_threshold: UnitInterval,
158    ) -> Self {
159        Self {
160            motion_no_confidence,
161            committee_normal,
162            committee_no_confidence,
163            hard_fork_initiation,
164            security_relevant_parameter_voting_threshold,
165            encodings: None,
166        }
167    }
168}
169
170pub type Port = u16;
171
172#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
173pub struct ProtocolParamUpdate {
174    pub minfee_a: Option<Coin>,
175    pub minfee_b: Option<Coin>,
176    pub max_block_body_size: Option<u64>,
177    pub max_transaction_size: Option<u64>,
178    pub max_block_header_size: Option<u64>,
179    pub key_deposit: Option<Coin>,
180    pub pool_deposit: Option<Coin>,
181    pub maximum_epoch: Option<Epoch>,
182    pub n_opt: Option<u64>,
183    pub pool_pledge_influence: Option<Rational>,
184    pub expansion_rate: Option<UnitInterval>,
185    pub treasury_growth_rate: Option<UnitInterval>,
186    pub min_pool_cost: Option<Coin>,
187    pub ada_per_utxo_byte: Option<Coin>,
188    pub cost_models_for_script_languages: Option<CostModels>,
189    pub execution_costs: Option<ExUnitPrices>,
190    pub max_tx_ex_units: Option<ExUnits>,
191    pub max_block_ex_units: Option<ExUnits>,
192    pub max_value_size: Option<u64>,
193    pub collateral_percentage: Option<u64>,
194    pub max_collateral_inputs: Option<u64>,
195    pub pool_voting_thresholds: Option<PoolVotingThresholds>,
196    pub d_rep_voting_thresholds: Option<DRepVotingThresholds>,
197    pub min_committee_size: Option<u64>,
198    pub committee_term_limit: Option<Epoch>,
199    pub governance_action_validity_period: Option<Epoch>,
200    pub governance_action_deposit: Option<Coin>,
201    pub d_rep_deposit: Option<Coin>,
202    pub d_rep_inactivity_period: Option<Epoch>,
203    pub min_fee_ref_script_cost_per_byte: Option<Rational>,
204    #[serde(skip)]
205    pub encodings: Option<ProtocolParamUpdateEncoding>,
206}
207
208impl ProtocolParamUpdate {
209    pub fn new() -> Self {
210        Self {
211            minfee_a: None,
212            minfee_b: None,
213            max_block_body_size: None,
214            max_transaction_size: None,
215            max_block_header_size: None,
216            key_deposit: None,
217            pool_deposit: None,
218            maximum_epoch: None,
219            n_opt: None,
220            pool_pledge_influence: None,
221            expansion_rate: None,
222            treasury_growth_rate: None,
223            min_pool_cost: None,
224            ada_per_utxo_byte: None,
225            cost_models_for_script_languages: None,
226            execution_costs: None,
227            max_tx_ex_units: None,
228            max_block_ex_units: None,
229            max_value_size: None,
230            collateral_percentage: None,
231            max_collateral_inputs: None,
232            pool_voting_thresholds: None,
233            d_rep_voting_thresholds: None,
234            min_committee_size: None,
235            committee_term_limit: None,
236            governance_action_validity_period: None,
237            governance_action_deposit: None,
238            d_rep_deposit: None,
239            d_rep_inactivity_period: None,
240            min_fee_ref_script_cost_per_byte: None,
241            encodings: None,
242        }
243    }
244}
245
246impl Default for ProtocolParamUpdate {
247    fn default() -> Self {
248        Self::new()
249    }
250}
251
252#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
253pub struct Rational {
254    pub numerator: u64,
255    pub denominator: u64,
256    #[serde(skip)]
257    pub encodings: Option<RationalEncoding>,
258}
259
260impl Rational {
261    pub fn new(numerator: u64, denominator: u64) -> Self {
262        Self {
263            numerator,
264            denominator,
265            encodings: None,
266        }
267    }
268}
269
270pub type RewardAccountList = Vec<RewardAccount>;
271
272#[derive(
273    Clone, Debug, derivative::Derivative, serde::Deserialize, serde::Serialize, schemars::JsonSchema,
274)]
275#[derivative(Hash, PartialEq)]
276pub enum Script {
277    Native {
278        script: NativeScript,
279        #[serde(skip)]
280        #[derivative(PartialEq = "ignore", Hash = "ignore")]
281        len_encoding: LenEncoding,
282        #[serde(skip)]
283        #[derivative(PartialEq = "ignore", Hash = "ignore")]
284        tag_encoding: Option<cbor_event::Sz>,
285    },
286    PlutusV1 {
287        script: PlutusV1Script,
288        #[serde(skip)]
289        #[derivative(PartialEq = "ignore", Hash = "ignore")]
290        len_encoding: LenEncoding,
291        #[serde(skip)]
292        #[derivative(PartialEq = "ignore", Hash = "ignore")]
293        tag_encoding: Option<cbor_event::Sz>,
294    },
295    PlutusV2 {
296        script: PlutusV2Script,
297        #[serde(skip)]
298        #[derivative(PartialEq = "ignore", Hash = "ignore")]
299        len_encoding: LenEncoding,
300        #[serde(skip)]
301        #[derivative(PartialEq = "ignore", Hash = "ignore")]
302        tag_encoding: Option<cbor_event::Sz>,
303    },
304    PlutusV3 {
305        script: PlutusV3Script,
306        #[serde(skip)]
307        #[derivative(PartialEq = "ignore", Hash = "ignore")]
308        len_encoding: LenEncoding,
309        #[serde(skip)]
310        #[derivative(PartialEq = "ignore", Hash = "ignore")]
311        tag_encoding: Option<cbor_event::Sz>,
312    },
313}
314
315impl Script {
316    pub fn new_native(script: NativeScript) -> Self {
317        Self::Native {
318            script,
319            len_encoding: LenEncoding::default(),
320            tag_encoding: None,
321        }
322    }
323
324    pub fn new_plutus_v1(script: PlutusV1Script) -> Self {
325        Self::PlutusV1 {
326            script,
327            len_encoding: LenEncoding::default(),
328            tag_encoding: None,
329        }
330    }
331
332    pub fn new_plutus_v2(script: PlutusV2Script) -> Self {
333        Self::PlutusV2 {
334            script,
335            len_encoding: LenEncoding::default(),
336            tag_encoding: None,
337        }
338    }
339
340    pub fn new_plutus_v3(script: PlutusV3Script) -> Self {
341        Self::PlutusV3 {
342            script,
343            len_encoding: LenEncoding::default(),
344            tag_encoding: None,
345        }
346    }
347}
348
349pub type SetCommitteeColdCredential = Set<CommitteeColdCredential>;
350pub type SetEd25519KeyHash = NonemptySetRawBytes<Ed25519KeyHash>;
351
352pub type SetTransactionInput = Set<TransactionInput>;
353
354pub type SubCoin = Rational;
355
356#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
357pub struct UnitInterval {
358    pub start: u64,
359    pub end: u64,
360    #[serde(skip)]
361    pub encodings: Option<UnitIntervalEncoding>,
362}
363
364impl UnitInterval {
365    pub fn new(start: u64, end: u64) -> Self {
366        Self {
367            start,
368            end,
369            encodings: None,
370        }
371    }
372}
373
374pub type VoterList = Vec<Voter>;
375
376pub type Withdrawals = OrderedHashMap<RewardAccount, Coin>;