cml_chain_wasm/
lib.rs

1#![allow(
2    clippy::len_without_is_empty,
3    clippy::too_many_arguments,
4    clippy::new_without_default
5)]
6
7use ::wasm_bindgen::prelude::{wasm_bindgen, JsError};
8use auxdata::TransactionMetadatumList;
9use cml_core_wasm::{impl_wasm_cbor_json_api, impl_wasm_conversions, impl_wasm_list};
10
11pub use cml_core_wasm::Int;
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 transaction;
29pub mod utils;
30
31use address::RewardAccount;
32use assets::AssetName;
33pub use assets::Value;
34use auxdata::{AuxiliaryData, TransactionMetadatum};
35
36use certs::{Certificate, Relay, StakeCredential};
37use cml_chain::assets::NonZeroInt64;
38pub use cml_chain::{assets::Coin, Epoch};
39use cml_core::ordered_hash_map::OrderedHashMap;
40use cml_crypto_wasm::{Ed25519KeyHash, ScriptHash};
41use crypto::{BootstrapWitness, Vkeywitness};
42use governance::{GovActionId, Voter};
43use plutus::{
44    CostModels, ExUnitPrices, ExUnits, LegacyRedeemer, PlutusData, PlutusV1Script, PlutusV2Script,
45    PlutusV3Script,
46};
47use transaction::{
48    NativeScript, TransactionBody, TransactionInput, TransactionOutput, TransactionWitnessSet,
49};
50pub use utils::NetworkId;
51
52use crate::certs::CommitteeColdCredential;
53use crate::governance::{ProposalProcedure, VotingProcedure};
54use crate::plutus::{RedeemerKey, RedeemerVal};
55
56pub type SetTransactionInput = TransactionInputList;
57
58pub type NonemptySetBootstrapWitness = BootstrapWitnessList;
59
60pub type NonemptySetCertificate = CertificateList;
61
62pub type NonemptySetNativeScript = NativeScriptList;
63
64pub type NonemptySetPlutusData = PlutusDataList;
65
66pub type NonemptySetPlutusV1Script = PlutusV1ScriptList;
67
68pub type NonemptySetPlutusV2Script = PlutusV2ScriptList;
69
70pub type NonemptySetPlutusV3Script = PlutusV3ScriptList;
71
72pub type NonemptySetProposalProcedure = ProposalProcedureList;
73
74pub type NonemptySetTransactionInput = TransactionInputList;
75
76pub type NonemptySetVkeywitness = VkeywitnessList;
77
78pub type RequiredSigners = Ed25519KeyHashList;
79
80//extern crate serde_wasm_bindgen;
81// Code below here was code-generated using an experimental CDDL to rust tool:
82// https://github.com/dcSpark/cddl-codegen
83
84impl_wasm_list!(cml_chain::assets::AssetName, AssetName, AssetNameList);
85
86impl_wasm_list!(
87    cml_chain::crypto::BootstrapWitness,
88    BootstrapWitness,
89    BootstrapWitnessList
90);
91
92impl_wasm_list!(cml_chain::certs::Certificate, Certificate, CertificateList);
93
94impl_wasm_list!(
95    cml_chain::certs::CommitteeColdCredential,
96    CommitteeColdCredential,
97    CommitteeColdCredentialList
98);
99
100#[derive(Clone, Debug)]
101#[wasm_bindgen]
102pub struct DRepVotingThresholds(cml_chain::DRepVotingThresholds);
103
104impl_wasm_cbor_json_api!(DRepVotingThresholds);
105
106impl_wasm_conversions!(cml_chain::DRepVotingThresholds, DRepVotingThresholds);
107
108#[wasm_bindgen]
109impl DRepVotingThresholds {
110    pub fn motion_no_confidence(&self) -> UnitInterval {
111        self.0.motion_no_confidence.clone().into()
112    }
113
114    pub fn committee_normal(&self) -> UnitInterval {
115        self.0.committee_normal.clone().into()
116    }
117
118    pub fn committee_no_confidence(&self) -> UnitInterval {
119        self.0.committee_no_confidence.clone().into()
120    }
121
122    pub fn update_constitution(&self) -> UnitInterval {
123        self.0.update_constitution.clone().into()
124    }
125
126    pub fn hard_fork_initiation(&self) -> UnitInterval {
127        self.0.hard_fork_initiation.clone().into()
128    }
129
130    pub fn pp_network_group(&self) -> UnitInterval {
131        self.0.pp_network_group.clone().into()
132    }
133
134    pub fn pp_economic_group(&self) -> UnitInterval {
135        self.0.pp_economic_group.clone().into()
136    }
137
138    pub fn pp_technical_group(&self) -> UnitInterval {
139        self.0.pp_technical_group.clone().into()
140    }
141
142    pub fn pp_governance_group(&self) -> UnitInterval {
143        self.0.pp_governance_group.clone().into()
144    }
145
146    pub fn treasury_withdrawal(&self) -> UnitInterval {
147        self.0.treasury_withdrawal.clone().into()
148    }
149
150    pub fn new(
151        motion_no_confidence: &UnitInterval,
152        committee_normal: &UnitInterval,
153        committee_no_confidence: &UnitInterval,
154        update_constitution: &UnitInterval,
155        hard_fork_initiation: &UnitInterval,
156        pp_network_group: &UnitInterval,
157        pp_economic_group: &UnitInterval,
158        pp_technical_group: &UnitInterval,
159        pp_governance_group: &UnitInterval,
160        treasury_withdrawal: &UnitInterval,
161    ) -> Self {
162        Self(cml_chain::DRepVotingThresholds::new(
163            motion_no_confidence.clone().into(),
164            committee_normal.clone().into(),
165            committee_no_confidence.clone().into(),
166            update_constitution.clone().into(),
167            hard_fork_initiation.clone().into(),
168            pp_network_group.clone().into(),
169            pp_economic_group.clone().into(),
170            pp_technical_group.clone().into(),
171            pp_governance_group.clone().into(),
172            treasury_withdrawal.clone().into(),
173        ))
174    }
175}
176
177pub type DeltaCoin = Int;
178
179impl_wasm_list!(
180    cml_chain::crypto::Ed25519KeyHash,
181    Ed25519KeyHash,
182    Ed25519KeyHashList
183);
184
185pub type SetCommitteeColdCredential = CommitteeColdCredentialList;
186
187pub type SetEd25519KeyHash = Ed25519KeyHashList;
188
189impl_wasm_list!(
190    cml_chain::governance::GovActionId,
191    GovActionId,
192    GovActionIdList
193);
194
195impl_wasm_list!(cml_chain::Int, Int, IntList);
196
197impl_wasm_list!(
198    cml_chain::plutus::LegacyRedeemer,
199    LegacyRedeemer,
200    LegacyRedeemerList
201);
202
203#[derive(Clone, Debug)]
204#[wasm_bindgen]
205pub struct MapAssetNameToNonZeroInt64(
206    OrderedHashMap<cml_chain::assets::AssetName, cml_chain::assets::NonZeroInt64>,
207);
208
209impl_wasm_conversions!(OrderedHashMap<cml_chain::assets::AssetName, cml_chain::assets::NonZeroInt64>, MapAssetNameToNonZeroInt64);
210
211#[wasm_bindgen]
212impl MapAssetNameToNonZeroInt64 {
213    pub fn new() -> Self {
214        Self(OrderedHashMap::new())
215    }
216
217    pub fn len(&self) -> usize {
218        self.0.len()
219    }
220
221    pub fn insert(&mut self, key: &AssetName, value: NonZeroInt64) -> Option<NonZeroInt64> {
222        self.0.insert(key.clone().into(), value)
223    }
224
225    pub fn get(&self, key: &AssetName) -> Option<NonZeroInt64> {
226        self.0.get(key.as_ref()).copied()
227    }
228
229    pub fn keys(&self) -> AssetNameList {
230        AssetNameList(self.0.iter().map(|(k, _v)| k.clone()).collect::<Vec<_>>())
231    }
232}
233
234#[derive(Clone, Debug)]
235#[wasm_bindgen]
236pub struct MapAssetNameToU64(OrderedHashMap<cml_chain::assets::AssetName, u64>);
237
238impl_wasm_conversions!(OrderedHashMap<cml_chain::assets::AssetName, u64>, MapAssetNameToU64);
239
240#[wasm_bindgen]
241impl MapAssetNameToU64 {
242    pub fn new() -> Self {
243        Self(OrderedHashMap::new())
244    }
245
246    pub fn len(&self) -> usize {
247        self.0.len()
248    }
249
250    pub fn insert(&mut self, key: &AssetName, value: u64) -> Option<u64> {
251        self.0.insert(key.clone().into(), value)
252    }
253
254    pub fn get(&self, key: &AssetName) -> Option<u64> {
255        self.0.get(key.as_ref()).copied()
256    }
257
258    pub fn keys(&self) -> AssetNameList {
259        AssetNameList(self.0.iter().map(|(k, _v)| k.clone()).collect::<Vec<_>>())
260    }
261}
262
263#[derive(Clone, Debug)]
264#[wasm_bindgen]
265pub struct MapCommitteeColdCredentialToEpoch(
266    OrderedHashMap<cml_chain::certs::CommitteeColdCredential, cml_chain::Epoch>,
267);
268
269impl_wasm_conversions!(OrderedHashMap<cml_chain::certs::CommitteeColdCredential, cml_chain::Epoch>, MapCommitteeColdCredentialToEpoch);
270
271#[wasm_bindgen]
272impl MapCommitteeColdCredentialToEpoch {
273    pub fn new() -> Self {
274        Self(OrderedHashMap::new())
275    }
276
277    pub fn len(&self) -> usize {
278        self.0.len()
279    }
280
281    pub fn insert(&mut self, key: &CommitteeColdCredential, value: Epoch) -> Option<Epoch> {
282        self.0.insert(key.clone().into(), value)
283    }
284
285    pub fn get(&self, key: &CommitteeColdCredential) -> Option<Epoch> {
286        self.0.get(key.as_ref()).copied()
287    }
288
289    pub fn keys(&self) -> CommitteeColdCredentialList {
290        CommitteeColdCredentialList(self.0.iter().map(|(k, _v)| k.clone()).collect::<Vec<_>>())
291    }
292}
293
294#[derive(Clone, Debug)]
295#[wasm_bindgen]
296pub struct MapGovActionIdToVotingProcedure(
297    OrderedHashMap<cml_chain::governance::GovActionId, cml_chain::governance::VotingProcedure>,
298);
299
300impl_wasm_conversions!(OrderedHashMap<cml_chain::governance::GovActionId, cml_chain::governance::VotingProcedure>, MapGovActionIdToVotingProcedure);
301
302#[wasm_bindgen]
303impl MapGovActionIdToVotingProcedure {
304    pub fn new() -> Self {
305        Self(OrderedHashMap::new())
306    }
307
308    pub fn len(&self) -> usize {
309        self.0.len()
310    }
311
312    pub fn insert(
313        &mut self,
314        key: &GovActionId,
315        value: &VotingProcedure,
316    ) -> Option<VotingProcedure> {
317        self.0
318            .insert(key.clone().into(), value.clone().into())
319            .map(Into::into)
320    }
321
322    pub fn get(&self, key: &GovActionId) -> Option<VotingProcedure> {
323        self.0.get(key.as_ref()).map(|v| v.clone().into())
324    }
325
326    pub fn keys(&self) -> GovActionIdList {
327        GovActionIdList(self.0.iter().map(|(k, _v)| k.clone()).collect::<Vec<_>>())
328    }
329}
330
331#[derive(Clone, Debug)]
332#[wasm_bindgen]
333pub struct MapPlutusDataToPlutusData(
334    OrderedHashMap<cml_chain::plutus::PlutusData, cml_chain::plutus::PlutusData>,
335);
336
337impl_wasm_conversions!(OrderedHashMap<cml_chain::plutus::PlutusData, cml_chain::plutus::PlutusData>, MapPlutusDataToPlutusData);
338
339#[wasm_bindgen]
340impl MapPlutusDataToPlutusData {
341    pub fn new() -> Self {
342        Self(OrderedHashMap::new())
343    }
344
345    pub fn len(&self) -> usize {
346        self.0.len()
347    }
348
349    pub fn insert(&mut self, key: &PlutusData, value: &PlutusData) -> Option<PlutusData> {
350        self.0
351            .insert(key.clone().into(), value.clone().into())
352            .map(Into::into)
353    }
354
355    pub fn get(&self, key: &PlutusData) -> Option<PlutusData> {
356        self.0.get(key.as_ref()).map(|v| v.clone().into())
357    }
358
359    pub fn keys(&self) -> PlutusDataList {
360        PlutusDataList(self.0.iter().map(|(k, _v)| k.clone()).collect::<Vec<_>>())
361    }
362}
363
364#[derive(Clone, Debug)]
365#[wasm_bindgen]
366pub struct MapRedeemerKeyToRedeemerVal(
367    OrderedHashMap<cml_chain::plutus::RedeemerKey, cml_chain::plutus::RedeemerVal>,
368);
369
370impl_wasm_conversions!(OrderedHashMap<cml_chain::plutus::RedeemerKey, cml_chain::plutus::RedeemerVal>, MapRedeemerKeyToRedeemerVal);
371
372#[wasm_bindgen]
373impl MapRedeemerKeyToRedeemerVal {
374    pub fn new() -> Self {
375        Self(OrderedHashMap::new())
376    }
377
378    pub fn len(&self) -> usize {
379        self.0.len()
380    }
381
382    pub fn insert(&mut self, key: &RedeemerKey, value: &RedeemerVal) -> Option<RedeemerVal> {
383        self.0
384            .insert(key.clone().into(), value.clone().into())
385            .map(Into::into)
386    }
387
388    pub fn get(&self, key: &RedeemerKey) -> Option<RedeemerVal> {
389        self.0.get(key.as_ref()).map(|v| v.clone().into())
390    }
391
392    pub fn keys(&self) -> RedeemerKeyList {
393        RedeemerKeyList(self.0.iter().map(|(k, _v)| k.clone()).collect::<Vec<_>>())
394    }
395}
396
397#[derive(Clone, Debug)]
398#[wasm_bindgen]
399pub struct MapRewardAccountToCoin(
400    OrderedHashMap<cml_chain::address::RewardAccount, cml_chain::assets::Coin>,
401);
402
403impl_wasm_conversions!(OrderedHashMap<cml_chain::address::RewardAccount, cml_chain::assets::Coin>, MapRewardAccountToCoin);
404
405#[wasm_bindgen]
406impl MapRewardAccountToCoin {
407    pub fn new() -> Self {
408        Self(OrderedHashMap::new())
409    }
410
411    pub fn len(&self) -> usize {
412        self.0.len()
413    }
414
415    pub fn insert(&mut self, key: &RewardAccount, value: Coin) -> Option<Coin> {
416        self.0.insert(key.clone().into(), value)
417    }
418
419    pub fn get(&self, key: &RewardAccount) -> Option<Coin> {
420        self.0.get(key.as_ref()).copied()
421    }
422
423    pub fn keys(&self) -> RewardAccountList {
424        RewardAccountList(self.0.iter().map(|(k, _v)| k.clone()).collect::<Vec<_>>())
425    }
426}
427
428#[derive(Clone, Debug)]
429#[wasm_bindgen]
430pub struct MapStakeCredentialToDeltaCoin(
431    OrderedHashMap<cml_chain::certs::StakeCredential, cml_chain::DeltaCoin>,
432);
433
434impl_wasm_conversions!(OrderedHashMap<cml_chain::certs::StakeCredential, cml_chain::DeltaCoin>, MapStakeCredentialToDeltaCoin);
435
436#[wasm_bindgen]
437impl MapStakeCredentialToDeltaCoin {
438    pub fn new() -> Self {
439        Self(OrderedHashMap::new())
440    }
441
442    pub fn len(&self) -> usize {
443        self.0.len()
444    }
445
446    pub fn insert(&mut self, key: &StakeCredential, value: &DeltaCoin) -> Option<DeltaCoin> {
447        self.0
448            .insert(key.clone().into(), value.clone().into())
449            .map(Into::into)
450    }
451
452    pub fn get(&self, key: &StakeCredential) -> Option<DeltaCoin> {
453        self.0.get(key.as_ref()).map(|v| v.clone().into())
454    }
455
456    pub fn keys(&self) -> StakeCredentialList {
457        StakeCredentialList(self.0.iter().map(|(k, _v)| k.clone()).collect::<Vec<_>>())
458    }
459}
460
461#[derive(Clone, Debug)]
462#[wasm_bindgen]
463pub struct MapTransactionIndexToAuxiliaryData(
464    OrderedHashMap<cml_chain::TransactionIndex, cml_chain::auxdata::AuxiliaryData>,
465);
466
467impl_wasm_conversions!(OrderedHashMap<cml_chain::TransactionIndex, cml_chain::auxdata::AuxiliaryData>, MapTransactionIndexToAuxiliaryData);
468
469#[wasm_bindgen]
470impl MapTransactionIndexToAuxiliaryData {
471    pub fn new() -> Self {
472        Self(OrderedHashMap::new())
473    }
474
475    pub fn len(&self) -> usize {
476        self.0.len()
477    }
478
479    pub fn insert(
480        &mut self,
481        key: TransactionIndex,
482        value: &AuxiliaryData,
483    ) -> Option<AuxiliaryData> {
484        self.0.insert(key, value.clone().into()).map(Into::into)
485    }
486
487    pub fn get(&self, key: TransactionIndex) -> Option<AuxiliaryData> {
488        self.0.get(&key).map(|v| v.clone().into())
489    }
490
491    pub fn keys(&self) -> Vec<TransactionIndex> {
492        self.0.keys().copied().collect::<Vec<_>>()
493    }
494}
495
496#[derive(Clone, Debug)]
497#[wasm_bindgen]
498pub struct MapTransactionMetadatumToTransactionMetadatum(
499    OrderedHashMap<
500        cml_chain::auxdata::TransactionMetadatum,
501        cml_chain::auxdata::TransactionMetadatum,
502    >,
503);
504
505impl_wasm_conversions!(OrderedHashMap<cml_chain::auxdata::TransactionMetadatum, cml_chain::auxdata::TransactionMetadatum>, MapTransactionMetadatumToTransactionMetadatum);
506
507#[wasm_bindgen]
508impl MapTransactionMetadatumToTransactionMetadatum {
509    pub fn new() -> Self {
510        Self(OrderedHashMap::new())
511    }
512
513    pub fn len(&self) -> usize {
514        self.0.len()
515    }
516
517    pub fn insert(
518        &mut self,
519        key: &TransactionMetadatum,
520        value: &TransactionMetadatum,
521    ) -> Option<TransactionMetadatum> {
522        self.0
523            .insert(key.clone().into(), value.clone().into())
524            .map(Into::into)
525    }
526
527    pub fn get(&self, key: &TransactionMetadatum) -> Option<TransactionMetadatum> {
528        self.0.get(key.as_ref()).map(|v| v.clone().into())
529    }
530
531    pub fn keys(&self) -> TransactionMetadatumList {
532        self.0
533            .iter()
534            .map(|(k, _v)| k.clone())
535            .collect::<Vec<_>>()
536            .into()
537    }
538}
539
540impl_wasm_list!(
541    cml_chain::transaction::NativeScript,
542    NativeScript,
543    NativeScriptList
544);
545
546impl_wasm_list!(cml_chain::plutus::PlutusData, PlutusData, PlutusDataList);
547
548impl_wasm_list!(
549    cml_chain::plutus::PlutusV1Script,
550    PlutusV1Script,
551    PlutusV1ScriptList
552);
553
554impl_wasm_list!(
555    cml_chain::plutus::PlutusV2Script,
556    PlutusV2Script,
557    PlutusV2ScriptList
558);
559
560impl_wasm_list!(
561    cml_chain::plutus::PlutusV3Script,
562    PlutusV3Script,
563    PlutusV3ScriptList
564);
565
566pub type PolicyId = ScriptHash;
567
568impl_wasm_list!(cml_chain::PolicyId, PolicyId, PolicyIdList);
569
570#[derive(Clone, Debug)]
571#[wasm_bindgen]
572pub struct PoolVotingThresholds(cml_chain::PoolVotingThresholds);
573
574impl_wasm_cbor_json_api!(PoolVotingThresholds);
575
576impl_wasm_conversions!(cml_chain::PoolVotingThresholds, PoolVotingThresholds);
577
578#[wasm_bindgen]
579impl PoolVotingThresholds {
580    pub fn motion_no_confidence(&self) -> UnitInterval {
581        self.0.motion_no_confidence.clone().into()
582    }
583
584    pub fn committee_normal(&self) -> UnitInterval {
585        self.0.committee_normal.clone().into()
586    }
587
588    pub fn committee_no_confidence(&self) -> UnitInterval {
589        self.0.committee_no_confidence.clone().into()
590    }
591
592    pub fn hard_fork_initiation(&self) -> UnitInterval {
593        self.0.hard_fork_initiation.clone().into()
594    }
595
596    pub fn security_relevant_parameter_voting_threshold(&self) -> UnitInterval {
597        self.0
598            .security_relevant_parameter_voting_threshold
599            .clone()
600            .into()
601    }
602
603    pub fn new(
604        motion_no_confidence: &UnitInterval,
605        committee_normal: &UnitInterval,
606        committee_no_confidence: &UnitInterval,
607        hard_fork_initiation: &UnitInterval,
608        security_relevant_parameter_voting_threshold: &UnitInterval,
609    ) -> Self {
610        Self(cml_chain::PoolVotingThresholds::new(
611            motion_no_confidence.clone().into(),
612            committee_normal.clone().into(),
613            committee_no_confidence.clone().into(),
614            hard_fork_initiation.clone().into(),
615            security_relevant_parameter_voting_threshold.clone().into(),
616        ))
617    }
618}
619
620pub type Port = u16;
621
622impl_wasm_list!(
623    cml_chain::governance::ProposalProcedure,
624    ProposalProcedure,
625    ProposalProcedureList
626);
627
628#[derive(Clone, Debug)]
629#[wasm_bindgen]
630pub struct ProtocolParamUpdate(cml_chain::ProtocolParamUpdate);
631
632impl_wasm_cbor_json_api!(ProtocolParamUpdate);
633
634impl_wasm_conversions!(cml_chain::ProtocolParamUpdate, ProtocolParamUpdate);
635
636#[wasm_bindgen]
637impl ProtocolParamUpdate {
638    pub fn set_minfee_a(&mut self, minfee_a: Coin) {
639        self.0.minfee_a = Some(minfee_a)
640    }
641
642    pub fn minfee_a(&self) -> Option<Coin> {
643        self.0.minfee_a
644    }
645
646    pub fn set_minfee_b(&mut self, minfee_b: Coin) {
647        self.0.minfee_b = Some(minfee_b)
648    }
649
650    pub fn minfee_b(&self) -> Option<Coin> {
651        self.0.minfee_b
652    }
653
654    pub fn set_max_block_body_size(&mut self, max_block_body_size: u64) {
655        self.0.max_block_body_size = Some(max_block_body_size)
656    }
657
658    pub fn max_block_body_size(&self) -> Option<u64> {
659        self.0.max_block_body_size
660    }
661
662    pub fn set_max_transaction_size(&mut self, max_transaction_size: u64) {
663        self.0.max_transaction_size = Some(max_transaction_size)
664    }
665
666    pub fn max_transaction_size(&self) -> Option<u64> {
667        self.0.max_transaction_size
668    }
669
670    pub fn set_max_block_header_size(&mut self, max_block_header_size: u64) {
671        self.0.max_block_header_size = Some(max_block_header_size)
672    }
673
674    pub fn max_block_header_size(&self) -> Option<u64> {
675        self.0.max_block_header_size
676    }
677
678    pub fn set_key_deposit(&mut self, key_deposit: Coin) {
679        self.0.key_deposit = Some(key_deposit)
680    }
681
682    pub fn key_deposit(&self) -> Option<Coin> {
683        self.0.key_deposit
684    }
685
686    pub fn set_pool_deposit(&mut self, pool_deposit: Coin) {
687        self.0.pool_deposit = Some(pool_deposit)
688    }
689
690    pub fn pool_deposit(&self) -> Option<Coin> {
691        self.0.pool_deposit
692    }
693
694    pub fn set_maximum_epoch(&mut self, maximum_epoch: Epoch) {
695        self.0.maximum_epoch = Some(maximum_epoch)
696    }
697
698    pub fn maximum_epoch(&self) -> Option<Epoch> {
699        self.0.maximum_epoch
700    }
701
702    pub fn set_n_opt(&mut self, n_opt: u64) {
703        self.0.n_opt = Some(n_opt)
704    }
705
706    pub fn n_opt(&self) -> Option<u64> {
707        self.0.n_opt
708    }
709
710    pub fn set_pool_pledge_influence(&mut self, pool_pledge_influence: &Rational) {
711        self.0.pool_pledge_influence = Some(pool_pledge_influence.clone().into())
712    }
713
714    pub fn pool_pledge_influence(&self) -> Option<Rational> {
715        self.0
716            .pool_pledge_influence
717            .clone()
718            .map(std::convert::Into::into)
719    }
720
721    pub fn set_expansion_rate(&mut self, expansion_rate: &UnitInterval) {
722        self.0.expansion_rate = Some(expansion_rate.clone().into())
723    }
724
725    pub fn expansion_rate(&self) -> Option<UnitInterval> {
726        self.0.expansion_rate.clone().map(std::convert::Into::into)
727    }
728
729    pub fn set_treasury_growth_rate(&mut self, treasury_growth_rate: &UnitInterval) {
730        self.0.treasury_growth_rate = Some(treasury_growth_rate.clone().into())
731    }
732
733    pub fn treasury_growth_rate(&self) -> Option<UnitInterval> {
734        self.0
735            .treasury_growth_rate
736            .clone()
737            .map(std::convert::Into::into)
738    }
739
740    pub fn set_min_pool_cost(&mut self, min_pool_cost: Coin) {
741        self.0.min_pool_cost = Some(min_pool_cost)
742    }
743
744    pub fn min_pool_cost(&self) -> Option<Coin> {
745        self.0.min_pool_cost
746    }
747
748    pub fn set_ada_per_utxo_byte(&mut self, ada_per_utxo_byte: Coin) {
749        self.0.ada_per_utxo_byte = Some(ada_per_utxo_byte)
750    }
751
752    pub fn ada_per_utxo_byte(&self) -> Option<Coin> {
753        self.0.ada_per_utxo_byte
754    }
755
756    pub fn set_cost_models_for_script_languages(
757        &mut self,
758        cost_models_for_script_languages: &CostModels,
759    ) {
760        self.0.cost_models_for_script_languages =
761            Some(cost_models_for_script_languages.clone().into())
762    }
763
764    pub fn cost_models_for_script_languages(&self) -> Option<CostModels> {
765        self.0
766            .cost_models_for_script_languages
767            .clone()
768            .map(std::convert::Into::into)
769    }
770
771    pub fn set_execution_costs(&mut self, execution_costs: &ExUnitPrices) {
772        self.0.execution_costs = Some(execution_costs.clone().into())
773    }
774
775    pub fn execution_costs(&self) -> Option<ExUnitPrices> {
776        self.0.execution_costs.clone().map(std::convert::Into::into)
777    }
778
779    pub fn set_max_tx_ex_units(&mut self, max_tx_ex_units: &ExUnits) {
780        self.0.max_tx_ex_units = Some(max_tx_ex_units.clone().into())
781    }
782
783    pub fn max_tx_ex_units(&self) -> Option<ExUnits> {
784        self.0.max_tx_ex_units.clone().map(std::convert::Into::into)
785    }
786
787    pub fn set_max_block_ex_units(&mut self, max_block_ex_units: &ExUnits) {
788        self.0.max_block_ex_units = Some(max_block_ex_units.clone().into())
789    }
790
791    pub fn max_block_ex_units(&self) -> Option<ExUnits> {
792        self.0
793            .max_block_ex_units
794            .clone()
795            .map(std::convert::Into::into)
796    }
797
798    pub fn set_max_value_size(&mut self, max_value_size: u64) {
799        self.0.max_value_size = Some(max_value_size)
800    }
801
802    pub fn max_value_size(&self) -> Option<u64> {
803        self.0.max_value_size
804    }
805
806    pub fn set_collateral_percentage(&mut self, collateral_percentage: u64) {
807        self.0.collateral_percentage = Some(collateral_percentage)
808    }
809
810    pub fn collateral_percentage(&self) -> Option<u64> {
811        self.0.collateral_percentage
812    }
813
814    pub fn set_max_collateral_inputs(&mut self, max_collateral_inputs: u64) {
815        self.0.max_collateral_inputs = Some(max_collateral_inputs)
816    }
817
818    pub fn max_collateral_inputs(&self) -> Option<u64> {
819        self.0.max_collateral_inputs
820    }
821
822    pub fn set_pool_voting_thresholds(&mut self, pool_voting_thresholds: &PoolVotingThresholds) {
823        self.0.pool_voting_thresholds = Some(pool_voting_thresholds.clone().into())
824    }
825
826    pub fn pool_voting_thresholds(&self) -> Option<PoolVotingThresholds> {
827        self.0
828            .pool_voting_thresholds
829            .clone()
830            .map(std::convert::Into::into)
831    }
832
833    pub fn set_d_rep_voting_thresholds(&mut self, d_rep_voting_thresholds: &DRepVotingThresholds) {
834        self.0.d_rep_voting_thresholds = Some(d_rep_voting_thresholds.clone().into())
835    }
836
837    pub fn d_rep_voting_thresholds(&self) -> Option<DRepVotingThresholds> {
838        self.0
839            .d_rep_voting_thresholds
840            .clone()
841            .map(std::convert::Into::into)
842    }
843
844    pub fn set_min_committee_size(&mut self, min_committee_size: u64) {
845        self.0.min_committee_size = Some(min_committee_size)
846    }
847
848    pub fn min_committee_size(&self) -> Option<u64> {
849        self.0.min_committee_size
850    }
851
852    pub fn set_committee_term_limit(&mut self, committee_term_limit: Epoch) {
853        self.0.committee_term_limit = Some(committee_term_limit)
854    }
855
856    pub fn committee_term_limit(&self) -> Option<Epoch> {
857        self.0.committee_term_limit
858    }
859
860    pub fn set_governance_action_validity_period(
861        &mut self,
862        governance_action_validity_period: Epoch,
863    ) {
864        self.0.governance_action_validity_period = Some(governance_action_validity_period)
865    }
866
867    pub fn governance_action_validity_period(&self) -> Option<Epoch> {
868        self.0.governance_action_validity_period
869    }
870
871    pub fn set_governance_action_deposit(&mut self, governance_action_deposit: Coin) {
872        self.0.governance_action_deposit = Some(governance_action_deposit)
873    }
874
875    pub fn governance_action_deposit(&self) -> Option<Coin> {
876        self.0.governance_action_deposit
877    }
878
879    pub fn set_d_rep_deposit(&mut self, d_rep_deposit: Coin) {
880        self.0.d_rep_deposit = Some(d_rep_deposit)
881    }
882
883    pub fn d_rep_deposit(&self) -> Option<Coin> {
884        self.0.d_rep_deposit
885    }
886
887    pub fn set_d_rep_inactivity_period(&mut self, d_rep_inactivity_period: Epoch) {
888        self.0.d_rep_inactivity_period = Some(d_rep_inactivity_period)
889    }
890
891    pub fn d_rep_inactivity_period(&self) -> Option<Epoch> {
892        self.0.d_rep_inactivity_period
893    }
894
895    pub fn set_min_fee_ref_script_cost_per_byte(
896        &mut self,
897        min_fee_ref_script_cost_per_byte: &Rational,
898    ) {
899        self.0.min_fee_ref_script_cost_per_byte =
900            Some(min_fee_ref_script_cost_per_byte.clone().into())
901    }
902
903    pub fn min_fee_ref_script_cost_per_byte(&self) -> Option<Rational> {
904        self.0
905            .min_fee_ref_script_cost_per_byte
906            .clone()
907            .map(std::convert::Into::into)
908    }
909
910    pub fn new() -> Self {
911        Self(cml_chain::ProtocolParamUpdate::new())
912    }
913}
914
915#[derive(Clone, Debug)]
916#[wasm_bindgen]
917pub struct Rational(cml_chain::Rational);
918
919impl_wasm_cbor_json_api!(Rational);
920
921impl_wasm_conversions!(cml_chain::Rational, Rational);
922
923#[wasm_bindgen]
924impl Rational {
925    pub fn numerator(&self) -> u64 {
926        self.0.numerator
927    }
928
929    pub fn denominator(&self) -> u64 {
930        self.0.denominator
931    }
932
933    pub fn new(numerator: u64, denominator: u64) -> Self {
934        Self(cml_chain::Rational::new(numerator, denominator))
935    }
936}
937
938impl_wasm_list!(cml_chain::plutus::RedeemerKey, RedeemerKey, RedeemerKeyList);
939
940impl_wasm_list!(cml_chain::certs::Relay, Relay, RelayList);
941
942impl_wasm_list!(
943    cml_chain::address::RewardAccount,
944    RewardAccount,
945    RewardAccountList
946);
947
948#[derive(Clone, Debug)]
949#[wasm_bindgen]
950pub struct Script(cml_chain::Script);
951
952impl_wasm_cbor_json_api!(Script);
953
954impl_wasm_conversions!(cml_chain::Script, Script);
955
956#[wasm_bindgen]
957impl Script {
958    pub fn new_native(script: &NativeScript) -> Self {
959        Self(cml_chain::Script::new_native(script.clone().into()))
960    }
961
962    pub fn new_plutus_v1(script: &PlutusV1Script) -> Self {
963        Self(cml_chain::Script::new_plutus_v1(script.clone().into()))
964    }
965
966    pub fn new_plutus_v2(script: &PlutusV2Script) -> Self {
967        Self(cml_chain::Script::new_plutus_v2(script.clone().into()))
968    }
969
970    pub fn new_plutus_v3(script: &PlutusV3Script) -> Self {
971        Self(cml_chain::Script::new_plutus_v3(script.clone().into()))
972    }
973
974    pub fn kind(&self) -> ScriptKind {
975        match &self.0 {
976            cml_chain::Script::Native { .. } => ScriptKind::Native,
977            cml_chain::Script::PlutusV1 { .. } => ScriptKind::PlutusV1,
978            cml_chain::Script::PlutusV2 { .. } => ScriptKind::PlutusV2,
979            cml_chain::Script::PlutusV3 { .. } => ScriptKind::PlutusV3,
980        }
981    }
982
983    pub fn as_native(&self) -> Option<NativeScript> {
984        match &self.0 {
985            cml_chain::Script::Native { script, .. } => Some(script.clone().into()),
986            _ => None,
987        }
988    }
989
990    pub fn as_plutus_v1(&self) -> Option<PlutusV1Script> {
991        match &self.0 {
992            cml_chain::Script::PlutusV1 { script, .. } => Some(script.clone().into()),
993            _ => None,
994        }
995    }
996
997    pub fn as_plutus_v2(&self) -> Option<PlutusV2Script> {
998        match &self.0 {
999            cml_chain::Script::PlutusV2 { script, .. } => Some(script.clone().into()),
1000            _ => None,
1001        }
1002    }
1003
1004    pub fn as_plutus_v3(&self) -> Option<PlutusV3Script> {
1005        match &self.0 {
1006            cml_chain::Script::PlutusV3 { script, .. } => Some(script.clone().into()),
1007            _ => None,
1008        }
1009    }
1010}
1011
1012#[wasm_bindgen]
1013pub enum ScriptKind {
1014    Native,
1015    PlutusV1,
1016    PlutusV2,
1017    PlutusV3,
1018}
1019
1020pub type Slot = u64;
1021
1022impl_wasm_list!(
1023    cml_chain::certs::StakeCredential,
1024    StakeCredential,
1025    StakeCredentialList
1026);
1027
1028pub type SubCoin = Rational;
1029
1030impl_wasm_list!(
1031    cml_chain::transaction::TransactionBody,
1032    TransactionBody,
1033    TransactionBodyList
1034);
1035
1036pub type TransactionIndex = u16;
1037
1038impl_wasm_list!(
1039    cml_chain::transaction::TransactionInput,
1040    TransactionInput,
1041    TransactionInputList
1042);
1043
1044impl_wasm_list!(
1045    cml_chain::transaction::TransactionOutput,
1046    TransactionOutput,
1047    TransactionOutputList
1048);
1049
1050impl_wasm_list!(
1051    cml_chain::transaction::TransactionWitnessSet,
1052    TransactionWitnessSet,
1053    TransactionWitnessSetList
1054);
1055
1056#[derive(Clone, Debug)]
1057#[wasm_bindgen]
1058pub struct UnitInterval(cml_chain::UnitInterval);
1059
1060impl_wasm_cbor_json_api!(UnitInterval);
1061
1062impl_wasm_conversions!(cml_chain::UnitInterval, UnitInterval);
1063
1064#[wasm_bindgen]
1065impl UnitInterval {
1066    pub fn start(&self) -> u64 {
1067        self.0.start
1068    }
1069
1070    pub fn end(&self) -> u64 {
1071        self.0.end
1072    }
1073
1074    pub fn new(start: u64, end: u64) -> Self {
1075        Self(cml_chain::UnitInterval::new(start, end))
1076    }
1077}
1078
1079impl_wasm_list!(cml_chain::crypto::Vkeywitness, Vkeywitness, VkeywitnessList);
1080
1081impl_wasm_list!(cml_chain::governance::Voter, Voter, VoterList);
1082
1083pub type Withdrawals = MapRewardAccountToCoin;