cml_multi_era_wasm/shelley/
mod.rs

1// This file was code-generated using an experimental CDDL to rust tool:
2// https://github.com/dcSpark/cddl-codegen
3
4use crate::{
5    GenesisHashList, MapStakeCredentialToCoin, MapTransactionIndexToMetadata, MultisigScriptList,
6    ShelleyCertificateList, ShelleyRelayList, ShelleyTransactionBodyList,
7    ShelleyTransactionOutputList, ShelleyTransactionWitnessSetList,
8};
9use cml_chain_wasm::address::{Address, RewardAccount};
10use cml_chain_wasm::assets::Coin;
11use cml_chain_wasm::auxdata::Metadata;
12use cml_chain_wasm::block::{OperationalCert, ProtocolVersion};
13use cml_chain_wasm::certs::{
14    Ipv4, Ipv6, PoolMetadata, PoolRetirement, SingleHostAddr, StakeCredential, StakeDelegation,
15    StakeDeregistration, StakeRegistration,
16};
17use cml_chain_wasm::crypto::{KESSignature, Nonce, VRFCert, Vkey};
18use cml_chain_wasm::{
19    BootstrapWitnessList, Ed25519KeyHashList, TransactionInputList, VkeywitnessList,
20};
21use cml_chain_wasm::{Epoch, Port, Rational, UnitInterval, Withdrawals};
22use cml_core::ordered_hash_map::OrderedHashMap;
23use cml_core_wasm::{impl_wasm_cbor_json_api, impl_wasm_conversions};
24use cml_crypto_wasm::{
25    AuxiliaryDataHash, BlockBodyHash, BlockHeaderHash, Ed25519KeyHash, GenesisDelegateHash,
26    GenesisHash, VRFKeyHash, VRFVkey,
27};
28use cml_multi_era::allegra::MIRPot;
29use wasm_bindgen::prelude::wasm_bindgen;
30
31#[derive(Clone, Debug)]
32#[wasm_bindgen]
33pub struct GenesisKeyDelegation(cml_multi_era::shelley::GenesisKeyDelegation);
34
35impl_wasm_cbor_json_api!(GenesisKeyDelegation);
36
37impl_wasm_conversions!(
38    cml_multi_era::shelley::GenesisKeyDelegation,
39    GenesisKeyDelegation
40);
41
42#[wasm_bindgen]
43impl GenesisKeyDelegation {
44    pub fn genesis_hash(&self) -> GenesisHash {
45        self.0.genesis_hash.into()
46    }
47
48    pub fn genesis_delegate_hash(&self) -> GenesisDelegateHash {
49        self.0.genesis_delegate_hash.into()
50    }
51
52    pub fn vrf_key_hash(&self) -> VRFKeyHash {
53        self.0.vrf_key_hash.into()
54    }
55
56    pub fn new(
57        genesis_hash: &GenesisHash,
58        genesis_delegate_hash: &GenesisDelegateHash,
59        vrf_key_hash: &VRFKeyHash,
60    ) -> Self {
61        Self(cml_multi_era::shelley::GenesisKeyDelegation::new(
62            genesis_hash.clone().into(),
63            genesis_delegate_hash.clone().into(),
64            vrf_key_hash.clone().into(),
65        ))
66    }
67}
68
69#[derive(Clone, Debug)]
70#[wasm_bindgen]
71pub struct MultisigAll(cml_multi_era::shelley::MultisigAll);
72
73impl_wasm_cbor_json_api!(MultisigAll);
74
75impl_wasm_conversions!(cml_multi_era::shelley::MultisigAll, MultisigAll);
76
77#[wasm_bindgen]
78impl MultisigAll {
79    pub fn multisig_scripts(&self) -> MultisigScriptList {
80        self.0.multisig_scripts.clone().into()
81    }
82
83    pub fn new(multisig_scripts: &MultisigScriptList) -> Self {
84        Self(cml_multi_era::shelley::MultisigAll::new(
85            multisig_scripts.clone().into(),
86        ))
87    }
88}
89
90#[derive(Clone, Debug)]
91#[wasm_bindgen]
92pub struct MultisigAny(cml_multi_era::shelley::MultisigAny);
93
94impl_wasm_cbor_json_api!(MultisigAny);
95
96impl_wasm_conversions!(cml_multi_era::shelley::MultisigAny, MultisigAny);
97
98#[wasm_bindgen]
99impl MultisigAny {
100    pub fn multisig_scripts(&self) -> MultisigScriptList {
101        self.0.multisig_scripts.clone().into()
102    }
103
104    pub fn new(multisig_scripts: &MultisigScriptList) -> Self {
105        Self(cml_multi_era::shelley::MultisigAny::new(
106            multisig_scripts.clone().into(),
107        ))
108    }
109}
110
111#[derive(Clone, Debug)]
112#[wasm_bindgen]
113pub struct MultisigNOfK(cml_multi_era::shelley::MultisigNOfK);
114
115impl_wasm_cbor_json_api!(MultisigNOfK);
116
117impl_wasm_conversions!(cml_multi_era::shelley::MultisigNOfK, MultisigNOfK);
118
119#[wasm_bindgen]
120impl MultisigNOfK {
121    pub fn n(&self) -> u64 {
122        self.0.n
123    }
124
125    pub fn multisig_scripts(&self) -> MultisigScriptList {
126        self.0.multisig_scripts.clone().into()
127    }
128
129    pub fn new(n: u64, multisig_scripts: &MultisigScriptList) -> Self {
130        Self(cml_multi_era::shelley::MultisigNOfK::new(
131            n,
132            multisig_scripts.clone().into(),
133        ))
134    }
135}
136
137#[derive(Clone, Debug)]
138#[wasm_bindgen]
139pub struct MultisigPubkey(cml_multi_era::shelley::MultisigPubkey);
140
141impl_wasm_cbor_json_api!(MultisigPubkey);
142
143impl_wasm_conversions!(cml_multi_era::shelley::MultisigPubkey, MultisigPubkey);
144
145#[wasm_bindgen]
146impl MultisigPubkey {
147    pub fn ed25519_key_hash(&self) -> Ed25519KeyHash {
148        self.0.ed25519_key_hash.into()
149    }
150
151    pub fn new(ed25519_key_hash: &Ed25519KeyHash) -> Self {
152        Self(cml_multi_era::shelley::MultisigPubkey::new(
153            ed25519_key_hash.clone().into(),
154        ))
155    }
156}
157
158#[derive(Clone, Debug)]
159#[wasm_bindgen]
160pub struct MultisigScript(cml_multi_era::shelley::MultisigScript);
161
162impl_wasm_cbor_json_api!(MultisigScript);
163
164impl_wasm_conversions!(cml_multi_era::shelley::MultisigScript, MultisigScript);
165
166#[wasm_bindgen]
167impl MultisigScript {
168    pub fn new_multisig_pubkey(ed25519_key_hash: &Ed25519KeyHash) -> Self {
169        Self(cml_multi_era::shelley::MultisigScript::new_multisig_pubkey(
170            ed25519_key_hash.clone().into(),
171        ))
172    }
173
174    pub fn new_multisig_all(multisig_scripts: &MultisigScriptList) -> Self {
175        Self(cml_multi_era::shelley::MultisigScript::new_multisig_all(
176            multisig_scripts.clone().into(),
177        ))
178    }
179
180    pub fn new_multisig_any(multisig_scripts: &MultisigScriptList) -> Self {
181        Self(cml_multi_era::shelley::MultisigScript::new_multisig_any(
182            multisig_scripts.clone().into(),
183        ))
184    }
185
186    pub fn new_multisig_n_of_k(n: u64, multisig_scripts: &MultisigScriptList) -> Self {
187        Self(cml_multi_era::shelley::MultisigScript::new_multisig_n_of_k(
188            n,
189            multisig_scripts.clone().into(),
190        ))
191    }
192
193    pub fn kind(&self) -> MultisigScriptKind {
194        match &self.0 {
195            cml_multi_era::shelley::MultisigScript::MultisigPubkey(_) => {
196                MultisigScriptKind::MultisigPubkey
197            }
198            cml_multi_era::shelley::MultisigScript::MultisigAll(_) => {
199                MultisigScriptKind::MultisigAll
200            }
201            cml_multi_era::shelley::MultisigScript::MultisigAny(_) => {
202                MultisigScriptKind::MultisigAny
203            }
204            cml_multi_era::shelley::MultisigScript::MultisigNOfK(_) => {
205                MultisigScriptKind::MultisigNOfK
206            }
207        }
208    }
209
210    pub fn as_multisig_pubkey(&self) -> Option<MultisigPubkey> {
211        match &self.0 {
212            cml_multi_era::shelley::MultisigScript::MultisigPubkey(multisig_pubkey) => {
213                Some(multisig_pubkey.clone().into())
214            }
215            _ => None,
216        }
217    }
218
219    pub fn as_multisig_all(&self) -> Option<MultisigAll> {
220        match &self.0 {
221            cml_multi_era::shelley::MultisigScript::MultisigAll(multisig_all) => {
222                Some(multisig_all.clone().into())
223            }
224            _ => None,
225        }
226    }
227
228    pub fn as_multisig_any(&self) -> Option<MultisigAny> {
229        match &self.0 {
230            cml_multi_era::shelley::MultisigScript::MultisigAny(multisig_any) => {
231                Some(multisig_any.clone().into())
232            }
233            _ => None,
234        }
235    }
236
237    pub fn as_multisig_n_of_k(&self) -> Option<MultisigNOfK> {
238        match &self.0 {
239            cml_multi_era::shelley::MultisigScript::MultisigNOfK(multisig_n_of_k) => {
240                Some(multisig_n_of_k.clone().into())
241            }
242            _ => None,
243        }
244    }
245}
246
247#[wasm_bindgen]
248pub enum MultisigScriptKind {
249    MultisigPubkey,
250    MultisigAll,
251    MultisigAny,
252    MultisigNOfK,
253}
254
255#[derive(Clone, Debug)]
256#[wasm_bindgen]
257pub struct ProtocolVersionStruct(cml_multi_era::shelley::ProtocolVersionStruct);
258
259impl_wasm_cbor_json_api!(ProtocolVersionStruct);
260
261impl_wasm_conversions!(
262    cml_multi_era::shelley::ProtocolVersionStruct,
263    ProtocolVersionStruct
264);
265
266#[wasm_bindgen]
267impl ProtocolVersionStruct {
268    pub fn protocol_version(&self) -> ProtocolVersion {
269        self.0.protocol_version.clone().into()
270    }
271
272    pub fn new(protocol_version: &ProtocolVersion) -> Self {
273        Self(cml_multi_era::shelley::ProtocolVersionStruct::new(
274            protocol_version.clone().into(),
275        ))
276    }
277}
278
279#[derive(Clone, Debug)]
280#[wasm_bindgen]
281pub struct ShelleyBlock(cml_multi_era::shelley::ShelleyBlock);
282
283impl_wasm_cbor_json_api!(ShelleyBlock);
284
285impl_wasm_conversions!(cml_multi_era::shelley::ShelleyBlock, ShelleyBlock);
286
287#[wasm_bindgen]
288impl ShelleyBlock {
289    pub fn header(&self) -> ShelleyHeader {
290        self.0.header.clone().into()
291    }
292
293    pub fn transaction_bodies(&self) -> ShelleyTransactionBodyList {
294        self.0.transaction_bodies.clone().into()
295    }
296
297    pub fn transaction_witness_sets(&self) -> ShelleyTransactionWitnessSetList {
298        self.0.transaction_witness_sets.clone().into()
299    }
300
301    pub fn transaction_metadata_set(&self) -> MapTransactionIndexToMetadata {
302        self.0.transaction_metadata_set.clone().into()
303    }
304
305    pub fn new(
306        header: &ShelleyHeader,
307        transaction_bodies: &ShelleyTransactionBodyList,
308        transaction_witness_sets: &ShelleyTransactionWitnessSetList,
309        transaction_metadata_set: &MapTransactionIndexToMetadata,
310    ) -> Self {
311        Self(cml_multi_era::shelley::ShelleyBlock::new(
312            header.clone().into(),
313            transaction_bodies.clone().into(),
314            transaction_witness_sets.clone().into(),
315            transaction_metadata_set.clone().into(),
316        ))
317    }
318}
319
320#[derive(Clone, Debug)]
321#[wasm_bindgen]
322pub struct ShelleyCertificate(cml_multi_era::shelley::ShelleyCertificate);
323
324impl_wasm_cbor_json_api!(ShelleyCertificate);
325
326impl_wasm_conversions!(
327    cml_multi_era::shelley::ShelleyCertificate,
328    ShelleyCertificate
329);
330
331#[wasm_bindgen]
332impl ShelleyCertificate {
333    pub fn new_stake_registration(stake_credential: &StakeCredential) -> Self {
334        Self(
335            cml_multi_era::shelley::ShelleyCertificate::new_stake_registration(
336                stake_credential.clone().into(),
337            ),
338        )
339    }
340
341    pub fn new_stake_deregistration(stake_credential: &StakeCredential) -> Self {
342        Self(
343            cml_multi_era::shelley::ShelleyCertificate::new_stake_deregistration(
344                stake_credential.clone().into(),
345            ),
346        )
347    }
348
349    pub fn new_stake_delegation(
350        stake_credential: &StakeCredential,
351        ed25519_key_hash: &Ed25519KeyHash,
352    ) -> Self {
353        Self(
354            cml_multi_era::shelley::ShelleyCertificate::new_stake_delegation(
355                stake_credential.clone().into(),
356                ed25519_key_hash.clone().into(),
357            ),
358        )
359    }
360
361    pub fn new_shelley_pool_registration(pool_params: &ShelleyPoolParams) -> Self {
362        Self(
363            cml_multi_era::shelley::ShelleyCertificate::new_shelley_pool_registration(
364                pool_params.clone().into(),
365            ),
366        )
367    }
368
369    pub fn new_pool_retirement(ed25519_key_hash: &Ed25519KeyHash, epoch: Epoch) -> Self {
370        Self(
371            cml_multi_era::shelley::ShelleyCertificate::new_pool_retirement(
372                ed25519_key_hash.clone().into(),
373                epoch,
374            ),
375        )
376    }
377
378    pub fn new_genesis_key_delegation(
379        genesis_hash: &GenesisHash,
380        genesis_delegate_hash: &GenesisDelegateHash,
381        vrf_key_hash: &VRFKeyHash,
382    ) -> Self {
383        Self(
384            cml_multi_era::shelley::ShelleyCertificate::new_genesis_key_delegation(
385                genesis_hash.clone().into(),
386                genesis_delegate_hash.clone().into(),
387                vrf_key_hash.clone().into(),
388            ),
389        )
390    }
391
392    pub fn new_shelley_move_instantaneous_rewards_cert(
393        shelley_move_instantaneous_reward: &ShelleyMoveInstantaneousReward,
394    ) -> Self {
395        Self(
396            cml_multi_era::shelley::ShelleyCertificate::new_shelley_move_instantaneous_rewards_cert(
397                shelley_move_instantaneous_reward.clone().into(),
398            ),
399        )
400    }
401
402    pub fn kind(&self) -> ShelleyCertificateKind {
403        match &self.0 {
404            cml_multi_era::shelley::ShelleyCertificate::StakeRegistration(_) => {
405                ShelleyCertificateKind::StakeRegistration
406            }
407            cml_multi_era::shelley::ShelleyCertificate::StakeDeregistration(_) => {
408                ShelleyCertificateKind::StakeDeregistration
409            }
410            cml_multi_era::shelley::ShelleyCertificate::StakeDelegation(_) => {
411                ShelleyCertificateKind::StakeDelegation
412            }
413            cml_multi_era::shelley::ShelleyCertificate::ShelleyPoolRegistration(_) => {
414                ShelleyCertificateKind::ShelleyPoolRegistration
415            }
416            cml_multi_era::shelley::ShelleyCertificate::PoolRetirement(_) => {
417                ShelleyCertificateKind::PoolRetirement
418            }
419            cml_multi_era::shelley::ShelleyCertificate::GenesisKeyDelegation(_) => {
420                ShelleyCertificateKind::GenesisKeyDelegation
421            }
422            cml_multi_era::shelley::ShelleyCertificate::ShelleyMoveInstantaneousRewardsCert(_) => {
423                ShelleyCertificateKind::ShelleyMoveInstantaneousRewardsCert
424            }
425        }
426    }
427
428    pub fn as_stake_registration(&self) -> Option<StakeRegistration> {
429        match &self.0 {
430            cml_multi_era::shelley::ShelleyCertificate::StakeRegistration(stake_registration) => {
431                Some(stake_registration.clone().into())
432            }
433            _ => None,
434        }
435    }
436
437    pub fn as_stake_deregistration(&self) -> Option<StakeDeregistration> {
438        match &self.0 {
439            cml_multi_era::shelley::ShelleyCertificate::StakeDeregistration(
440                stake_deregistration,
441            ) => Some(stake_deregistration.clone().into()),
442            _ => None,
443        }
444    }
445
446    pub fn as_stake_delegation(&self) -> Option<StakeDelegation> {
447        match &self.0 {
448            cml_multi_era::shelley::ShelleyCertificate::StakeDelegation(stake_delegation) => {
449                Some(stake_delegation.clone().into())
450            }
451            _ => None,
452        }
453    }
454
455    pub fn as_shelley_pool_registration(&self) -> Option<ShelleyPoolRegistration> {
456        match &self.0 {
457            cml_multi_era::shelley::ShelleyCertificate::ShelleyPoolRegistration(
458                shelley_pool_registration,
459            ) => Some(shelley_pool_registration.clone().into()),
460            _ => None,
461        }
462    }
463
464    pub fn as_pool_retirement(&self) -> Option<PoolRetirement> {
465        match &self.0 {
466            cml_multi_era::shelley::ShelleyCertificate::PoolRetirement(pool_retirement) => {
467                Some(pool_retirement.clone().into())
468            }
469            _ => None,
470        }
471    }
472
473    pub fn as_genesis_key_delegation(&self) -> Option<GenesisKeyDelegation> {
474        match &self.0 {
475            cml_multi_era::shelley::ShelleyCertificate::GenesisKeyDelegation(
476                genesis_key_delegation,
477            ) => Some(genesis_key_delegation.clone().into()),
478            _ => None,
479        }
480    }
481
482    pub fn as_shelley_move_instantaneous_rewards_cert(
483        &self,
484    ) -> Option<ShelleyMoveInstantaneousRewardsCert> {
485        match &self.0 {
486            cml_multi_era::shelley::ShelleyCertificate::ShelleyMoveInstantaneousRewardsCert(
487                shelley_move_instantaneous_rewards_cert,
488            ) => Some(shelley_move_instantaneous_rewards_cert.clone().into()),
489            _ => None,
490        }
491    }
492}
493
494#[wasm_bindgen]
495pub enum ShelleyCertificateKind {
496    StakeRegistration,
497    StakeDeregistration,
498    StakeDelegation,
499    ShelleyPoolRegistration,
500    PoolRetirement,
501    GenesisKeyDelegation,
502    ShelleyMoveInstantaneousRewardsCert,
503}
504
505#[derive(Clone, Debug)]
506#[wasm_bindgen]
507pub struct ShelleyDNSName(cml_multi_era::shelley::ShelleyDNSName);
508
509impl_wasm_cbor_json_api!(ShelleyDNSName);
510
511impl_wasm_conversions!(cml_multi_era::shelley::ShelleyDNSName, ShelleyDNSName);
512
513#[wasm_bindgen]
514impl ShelleyDNSName {
515    pub fn get(&self) -> String {
516        self.0.get().clone()
517    }
518}
519
520#[derive(Clone, Debug)]
521#[wasm_bindgen]
522pub struct ShelleyHeader(cml_multi_era::shelley::ShelleyHeader);
523
524impl_wasm_cbor_json_api!(ShelleyHeader);
525
526impl_wasm_conversions!(cml_multi_era::shelley::ShelleyHeader, ShelleyHeader);
527
528#[wasm_bindgen]
529impl ShelleyHeader {
530    pub fn body(&self) -> ShelleyHeaderBody {
531        self.0.body.clone().into()
532    }
533
534    pub fn signature(&self) -> KESSignature {
535        self.0.signature.clone().into()
536    }
537
538    pub fn new(body: &ShelleyHeaderBody, signature: &KESSignature) -> Self {
539        Self(cml_multi_era::shelley::ShelleyHeader::new(
540            body.clone().into(),
541            signature.clone().into(),
542        ))
543    }
544}
545
546#[derive(Clone, Debug)]
547#[wasm_bindgen]
548pub struct ShelleyHeaderBody(cml_multi_era::shelley::ShelleyHeaderBody);
549
550impl_wasm_cbor_json_api!(ShelleyHeaderBody);
551
552impl_wasm_conversions!(cml_multi_era::shelley::ShelleyHeaderBody, ShelleyHeaderBody);
553
554#[wasm_bindgen]
555impl ShelleyHeaderBody {
556    pub fn block_number(&self) -> u64 {
557        self.0.block_number
558    }
559
560    pub fn slot(&self) -> u64 {
561        self.0.slot
562    }
563
564    pub fn prev_hash(&self) -> Option<BlockHeaderHash> {
565        self.0.prev_hash.map(std::convert::Into::into)
566    }
567
568    pub fn issuer_vkey(&self) -> Vkey {
569        self.0.issuer_vkey.clone().into()
570    }
571
572    pub fn vrf_vkey(&self) -> VRFVkey {
573        self.0.vrf_vkey.into()
574    }
575
576    pub fn nonce_vrf(&self) -> VRFCert {
577        self.0.nonce_vrf.clone().into()
578    }
579
580    pub fn leader_vrf(&self) -> VRFCert {
581        self.0.leader_vrf.clone().into()
582    }
583
584    pub fn block_body_size(&self) -> u64 {
585        self.0.block_body_size
586    }
587
588    pub fn block_body_hash(&self) -> BlockBodyHash {
589        self.0.block_body_hash.into()
590    }
591
592    pub fn operational_cert(&self) -> OperationalCert {
593        self.0.operational_cert.clone().into()
594    }
595
596    pub fn protocol_version(&self) -> ProtocolVersion {
597        self.0.protocol_version.clone().into()
598    }
599
600    pub fn new(
601        block_number: u64,
602        slot: u64,
603        prev_hash: Option<BlockHeaderHash>,
604        issuer_vkey: &Vkey,
605        vrf_vkey: &VRFVkey,
606        nonce_vrf: &VRFCert,
607        leader_vrf: &VRFCert,
608        block_body_size: u64,
609        block_body_hash: &BlockBodyHash,
610        operational_cert: &OperationalCert,
611        protocol_version: &ProtocolVersion,
612    ) -> Self {
613        Self(cml_multi_era::shelley::ShelleyHeaderBody::new(
614            block_number,
615            slot,
616            prev_hash.map(Into::into),
617            issuer_vkey.clone().into(),
618            vrf_vkey.clone().into(),
619            nonce_vrf.clone().into(),
620            leader_vrf.clone().into(),
621            block_body_size,
622            block_body_hash.clone().into(),
623            operational_cert.clone().into(),
624            protocol_version.clone().into(),
625        ))
626    }
627}
628
629#[derive(Clone, Debug)]
630#[wasm_bindgen]
631pub struct ShelleyMoveInstantaneousReward(cml_multi_era::shelley::ShelleyMoveInstantaneousReward);
632
633impl_wasm_cbor_json_api!(ShelleyMoveInstantaneousReward);
634
635impl_wasm_conversions!(
636    cml_multi_era::shelley::ShelleyMoveInstantaneousReward,
637    ShelleyMoveInstantaneousReward
638);
639
640#[wasm_bindgen]
641impl ShelleyMoveInstantaneousReward {
642    pub fn pot(&self) -> MIRPot {
643        self.0.pot
644    }
645
646    pub fn to_stake_credentials(&self) -> MapStakeCredentialToCoin {
647        self.0.to_stake_credentials.clone().into()
648    }
649
650    pub fn new(pot: MIRPot, to_stake_credentials: &MapStakeCredentialToCoin) -> Self {
651        Self(cml_multi_era::shelley::ShelleyMoveInstantaneousReward::new(
652            pot,
653            to_stake_credentials.clone().into(),
654        ))
655    }
656}
657
658#[derive(Clone, Debug)]
659#[wasm_bindgen]
660pub struct ShelleyMoveInstantaneousRewardsCert(
661    cml_multi_era::shelley::ShelleyMoveInstantaneousRewardsCert,
662);
663
664impl_wasm_cbor_json_api!(ShelleyMoveInstantaneousRewardsCert);
665
666impl_wasm_conversions!(
667    cml_multi_era::shelley::ShelleyMoveInstantaneousRewardsCert,
668    ShelleyMoveInstantaneousRewardsCert
669);
670
671#[wasm_bindgen]
672impl ShelleyMoveInstantaneousRewardsCert {
673    pub fn shelley_move_instantaneous_reward(&self) -> ShelleyMoveInstantaneousReward {
674        self.0.shelley_move_instantaneous_reward.clone().into()
675    }
676
677    pub fn new(shelley_move_instantaneous_reward: &ShelleyMoveInstantaneousReward) -> Self {
678        Self(
679            cml_multi_era::shelley::ShelleyMoveInstantaneousRewardsCert::new(
680                shelley_move_instantaneous_reward.clone().into(),
681            ),
682        )
683    }
684}
685
686#[derive(Clone, Debug)]
687#[wasm_bindgen]
688pub struct ShelleyMultiHostName(cml_multi_era::shelley::ShelleyMultiHostName);
689
690impl_wasm_cbor_json_api!(ShelleyMultiHostName);
691
692impl_wasm_conversions!(
693    cml_multi_era::shelley::ShelleyMultiHostName,
694    ShelleyMultiHostName
695);
696
697#[wasm_bindgen]
698impl ShelleyMultiHostName {
699    pub fn shelley_dns_name(&self) -> ShelleyDNSName {
700        self.0.shelley_dns_name.clone().into()
701    }
702
703    /// * `shelley_dns_name` - A SRV DNS record
704    pub fn new(shelley_dns_name: &ShelleyDNSName) -> Self {
705        Self(cml_multi_era::shelley::ShelleyMultiHostName::new(
706            shelley_dns_name.clone().into(),
707        ))
708    }
709}
710
711#[derive(Clone, Debug)]
712#[wasm_bindgen]
713pub struct ShelleyPoolParams(cml_multi_era::shelley::ShelleyPoolParams);
714
715impl_wasm_cbor_json_api!(ShelleyPoolParams);
716
717impl_wasm_conversions!(cml_multi_era::shelley::ShelleyPoolParams, ShelleyPoolParams);
718
719#[wasm_bindgen]
720impl ShelleyPoolParams {
721    pub fn operator(&self) -> Ed25519KeyHash {
722        self.0.operator.into()
723    }
724
725    pub fn vrf_keyhash(&self) -> VRFKeyHash {
726        self.0.vrf_keyhash.into()
727    }
728
729    pub fn pledge(&self) -> Coin {
730        self.0.pledge
731    }
732
733    pub fn cost(&self) -> Coin {
734        self.0.cost
735    }
736
737    pub fn margin(&self) -> UnitInterval {
738        self.0.margin.clone().into()
739    }
740
741    pub fn reward_account(&self) -> RewardAccount {
742        self.0.reward_account.clone().into()
743    }
744
745    pub fn pool_owners(&self) -> Ed25519KeyHashList {
746        self.0.pool_owners.clone().into()
747    }
748
749    pub fn relays(&self) -> ShelleyRelayList {
750        self.0.relays.clone().into()
751    }
752
753    pub fn pool_metadata(&self) -> Option<PoolMetadata> {
754        self.0.pool_metadata.clone().map(std::convert::Into::into)
755    }
756
757    pub fn new(
758        operator: &Ed25519KeyHash,
759        vrf_keyhash: &VRFKeyHash,
760        pledge: Coin,
761        cost: Coin,
762        margin: &UnitInterval,
763        reward_account: &RewardAccount,
764        pool_owners: &Ed25519KeyHashList,
765        relays: &ShelleyRelayList,
766        pool_metadata: Option<PoolMetadata>,
767    ) -> Self {
768        Self(cml_multi_era::shelley::ShelleyPoolParams::new(
769            operator.clone().into(),
770            vrf_keyhash.clone().into(),
771            pledge,
772            cost,
773            margin.clone().into(),
774            reward_account.clone().into(),
775            pool_owners.clone().into(),
776            relays.clone().into(),
777            pool_metadata.map(Into::into),
778        ))
779    }
780}
781
782#[derive(Clone, Debug)]
783#[wasm_bindgen]
784pub struct ShelleyPoolRegistration(cml_multi_era::shelley::ShelleyPoolRegistration);
785
786impl_wasm_cbor_json_api!(ShelleyPoolRegistration);
787
788impl_wasm_conversions!(
789    cml_multi_era::shelley::ShelleyPoolRegistration,
790    ShelleyPoolRegistration
791);
792
793#[wasm_bindgen]
794impl ShelleyPoolRegistration {
795    pub fn pool_params(&self) -> ShelleyPoolParams {
796        self.0.pool_params.clone().into()
797    }
798
799    pub fn new(pool_params: &ShelleyPoolParams) -> Self {
800        Self(cml_multi_era::shelley::ShelleyPoolRegistration::new(
801            pool_params.clone().into(),
802        ))
803    }
804}
805
806#[derive(Clone, Debug)]
807#[wasm_bindgen]
808pub struct ShelleyProposedProtocolParameterUpdates(
809    cml_multi_era::shelley::ShelleyProposedProtocolParameterUpdates,
810);
811
812impl_wasm_conversions!(
813    cml_multi_era::shelley::ShelleyProposedProtocolParameterUpdates,
814    ShelleyProposedProtocolParameterUpdates
815);
816
817#[wasm_bindgen]
818impl ShelleyProposedProtocolParameterUpdates {
819    pub fn new() -> Self {
820        Self(OrderedHashMap::new())
821    }
822
823    pub fn len(&self) -> usize {
824        self.0.len()
825    }
826
827    pub fn insert(
828        &mut self,
829        key: &GenesisHash,
830        value: &ShelleyProtocolParamUpdate,
831    ) -> Option<ShelleyProtocolParamUpdate> {
832        self.0
833            .insert(key.clone().into(), value.clone().into())
834            .map(Into::into)
835    }
836
837    pub fn get(&self, key: &GenesisHash) -> Option<ShelleyProtocolParamUpdate> {
838        self.0.get(key.as_ref()).map(|v| v.clone().into())
839    }
840
841    pub fn keys(&self) -> GenesisHashList {
842        self.0.iter().map(|(k, _v)| *k).collect::<Vec<_>>().into()
843    }
844}
845
846#[derive(Clone, Debug)]
847#[wasm_bindgen]
848pub struct ShelleyProtocolParamUpdate(cml_multi_era::shelley::ShelleyProtocolParamUpdate);
849
850impl_wasm_cbor_json_api!(ShelleyProtocolParamUpdate);
851
852impl_wasm_conversions!(
853    cml_multi_era::shelley::ShelleyProtocolParamUpdate,
854    ShelleyProtocolParamUpdate
855);
856
857#[wasm_bindgen]
858impl ShelleyProtocolParamUpdate {
859    pub fn set_minfee_a(&mut self, minfee_a: u64) {
860        self.0.minfee_a = Some(minfee_a)
861    }
862
863    pub fn minfee_a(&self) -> Option<u64> {
864        self.0.minfee_a
865    }
866
867    pub fn set_minfee_b(&mut self, minfee_b: u64) {
868        self.0.minfee_b = Some(minfee_b)
869    }
870
871    pub fn minfee_b(&self) -> Option<u64> {
872        self.0.minfee_b
873    }
874
875    pub fn set_max_block_body_size(&mut self, max_block_body_size: u64) {
876        self.0.max_block_body_size = Some(max_block_body_size)
877    }
878
879    pub fn max_block_body_size(&self) -> Option<u64> {
880        self.0.max_block_body_size
881    }
882
883    pub fn set_max_transaction_size(&mut self, max_transaction_size: u64) {
884        self.0.max_transaction_size = Some(max_transaction_size)
885    }
886
887    pub fn max_transaction_size(&self) -> Option<u64> {
888        self.0.max_transaction_size
889    }
890
891    pub fn set_max_block_header_size(&mut self, max_block_header_size: u64) {
892        self.0.max_block_header_size = Some(max_block_header_size)
893    }
894
895    pub fn max_block_header_size(&self) -> Option<u64> {
896        self.0.max_block_header_size
897    }
898
899    pub fn set_key_deposit(&mut self, key_deposit: Coin) {
900        self.0.key_deposit = Some(key_deposit)
901    }
902
903    pub fn key_deposit(&self) -> Option<Coin> {
904        self.0.key_deposit
905    }
906
907    pub fn set_pool_deposit(&mut self, pool_deposit: Coin) {
908        self.0.pool_deposit = Some(pool_deposit)
909    }
910
911    pub fn pool_deposit(&self) -> Option<Coin> {
912        self.0.pool_deposit
913    }
914
915    pub fn set_maximum_epoch(&mut self, maximum_epoch: Epoch) {
916        self.0.maximum_epoch = Some(maximum_epoch)
917    }
918
919    pub fn maximum_epoch(&self) -> Option<Epoch> {
920        self.0.maximum_epoch
921    }
922
923    pub fn set_n_opt(&mut self, n_opt: u64) {
924        self.0.n_opt = Some(n_opt)
925    }
926
927    pub fn n_opt(&self) -> Option<u64> {
928        self.0.n_opt
929    }
930
931    pub fn set_pool_pledge_influence(&mut self, pool_pledge_influence: &Rational) {
932        self.0.pool_pledge_influence = Some(pool_pledge_influence.clone().into())
933    }
934
935    pub fn pool_pledge_influence(&self) -> Option<Rational> {
936        self.0
937            .pool_pledge_influence
938            .clone()
939            .map(std::convert::Into::into)
940    }
941
942    pub fn set_expansion_rate(&mut self, expansion_rate: &UnitInterval) {
943        self.0.expansion_rate = Some(expansion_rate.clone().into())
944    }
945
946    pub fn expansion_rate(&self) -> Option<UnitInterval> {
947        self.0.expansion_rate.clone().map(std::convert::Into::into)
948    }
949
950    pub fn set_treasury_growth_rate(&mut self, treasury_growth_rate: &UnitInterval) {
951        self.0.treasury_growth_rate = Some(treasury_growth_rate.clone().into())
952    }
953
954    pub fn treasury_growth_rate(&self) -> Option<UnitInterval> {
955        self.0
956            .treasury_growth_rate
957            .clone()
958            .map(std::convert::Into::into)
959    }
960
961    pub fn set_decentralization_constant(&mut self, decentralization_constant: &UnitInterval) {
962        self.0.decentralization_constant = Some(decentralization_constant.clone().into())
963    }
964
965    pub fn decentralization_constant(&self) -> Option<UnitInterval> {
966        self.0
967            .decentralization_constant
968            .clone()
969            .map(std::convert::Into::into)
970    }
971
972    pub fn set_extra_entropy(&mut self, extra_entropy: &Nonce) {
973        self.0.extra_entropy = Some(extra_entropy.clone().into())
974    }
975
976    pub fn extra_entropy(&self) -> Option<Nonce> {
977        self.0.extra_entropy.clone().map(std::convert::Into::into)
978    }
979
980    pub fn set_protocol_version(&mut self, protocol_version: &ProtocolVersionStruct) {
981        self.0.protocol_version = Some(protocol_version.clone().into())
982    }
983
984    pub fn protocol_version(&self) -> Option<ProtocolVersionStruct> {
985        self.0
986            .protocol_version
987            .clone()
988            .map(std::convert::Into::into)
989    }
990
991    pub fn set_min_utxo_value(&mut self, min_utxo_value: Coin) {
992        self.0.min_utxo_value = Some(min_utxo_value)
993    }
994
995    pub fn min_utxo_value(&self) -> Option<Coin> {
996        self.0.min_utxo_value
997    }
998
999    pub fn new() -> Self {
1000        Self(cml_multi_era::shelley::ShelleyProtocolParamUpdate::new())
1001    }
1002}
1003
1004#[derive(Clone, Debug)]
1005#[wasm_bindgen]
1006pub struct ShelleyRelay(cml_multi_era::shelley::ShelleyRelay);
1007
1008impl_wasm_cbor_json_api!(ShelleyRelay);
1009
1010impl_wasm_conversions!(cml_multi_era::shelley::ShelleyRelay, ShelleyRelay);
1011
1012#[wasm_bindgen]
1013impl ShelleyRelay {
1014    pub fn new_single_host_addr(
1015        port: Option<Port>,
1016        ipv4: Option<Ipv4>,
1017        ipv6: Option<Ipv6>,
1018    ) -> Self {
1019        Self(cml_multi_era::shelley::ShelleyRelay::new_single_host_addr(
1020            port,
1021            ipv4.map(Into::into),
1022            ipv6.map(Into::into),
1023        ))
1024    }
1025
1026    pub fn new_shelley_single_host_name(
1027        port: Option<Port>,
1028        shelley_dns_name: &ShelleyDNSName,
1029    ) -> Self {
1030        Self(
1031            cml_multi_era::shelley::ShelleyRelay::new_shelley_single_host_name(
1032                port,
1033                shelley_dns_name.clone().into(),
1034            ),
1035        )
1036    }
1037
1038    pub fn new_shelley_multi_host_name(shelley_dns_name: &ShelleyDNSName) -> Self {
1039        Self(
1040            cml_multi_era::shelley::ShelleyRelay::new_shelley_multi_host_name(
1041                shelley_dns_name.clone().into(),
1042            ),
1043        )
1044    }
1045
1046    pub fn kind(&self) -> ShelleyRelayKind {
1047        match &self.0 {
1048            cml_multi_era::shelley::ShelleyRelay::SingleHostAddr(_) => {
1049                ShelleyRelayKind::SingleHostAddr
1050            }
1051            cml_multi_era::shelley::ShelleyRelay::ShelleySingleHostName(_) => {
1052                ShelleyRelayKind::ShelleySingleHostName
1053            }
1054            cml_multi_era::shelley::ShelleyRelay::ShelleyMultiHostName(_) => {
1055                ShelleyRelayKind::ShelleyMultiHostName
1056            }
1057        }
1058    }
1059
1060    pub fn as_single_host_addr(&self) -> Option<SingleHostAddr> {
1061        match &self.0 {
1062            cml_multi_era::shelley::ShelleyRelay::SingleHostAddr(single_host_addr) => {
1063                Some(single_host_addr.clone().into())
1064            }
1065            _ => None,
1066        }
1067    }
1068
1069    pub fn as_shelley_single_host_name(&self) -> Option<ShelleySingleHostName> {
1070        match &self.0 {
1071            cml_multi_era::shelley::ShelleyRelay::ShelleySingleHostName(
1072                shelley_single_host_name,
1073            ) => Some(shelley_single_host_name.clone().into()),
1074            _ => None,
1075        }
1076    }
1077
1078    pub fn as_shelley_multi_host_name(&self) -> Option<ShelleyMultiHostName> {
1079        match &self.0 {
1080            cml_multi_era::shelley::ShelleyRelay::ShelleyMultiHostName(shelley_multi_host_name) => {
1081                Some(shelley_multi_host_name.clone().into())
1082            }
1083            _ => None,
1084        }
1085    }
1086}
1087
1088#[wasm_bindgen]
1089pub enum ShelleyRelayKind {
1090    SingleHostAddr,
1091    ShelleySingleHostName,
1092    ShelleyMultiHostName,
1093}
1094
1095#[derive(Clone, Debug)]
1096#[wasm_bindgen]
1097pub struct ShelleySingleHostName(cml_multi_era::shelley::ShelleySingleHostName);
1098
1099impl_wasm_cbor_json_api!(ShelleySingleHostName);
1100
1101impl_wasm_conversions!(
1102    cml_multi_era::shelley::ShelleySingleHostName,
1103    ShelleySingleHostName
1104);
1105
1106#[wasm_bindgen]
1107impl ShelleySingleHostName {
1108    pub fn port(&self) -> Option<Port> {
1109        self.0.port
1110    }
1111
1112    pub fn shelley_dns_name(&self) -> ShelleyDNSName {
1113        self.0.shelley_dns_name.clone().into()
1114    }
1115
1116    /// * `shelley_dns_name` - An A or AAAA DNS record
1117    pub fn new(port: Option<Port>, shelley_dns_name: &ShelleyDNSName) -> Self {
1118        Self(cml_multi_era::shelley::ShelleySingleHostName::new(
1119            port,
1120            shelley_dns_name.clone().into(),
1121        ))
1122    }
1123}
1124
1125#[derive(Clone, Debug)]
1126#[wasm_bindgen]
1127pub struct ShelleyTransaction(cml_multi_era::shelley::ShelleyTransaction);
1128
1129impl_wasm_cbor_json_api!(ShelleyTransaction);
1130
1131impl_wasm_conversions!(
1132    cml_multi_era::shelley::ShelleyTransaction,
1133    ShelleyTransaction
1134);
1135
1136#[wasm_bindgen]
1137impl ShelleyTransaction {
1138    pub fn body(&self) -> ShelleyTransactionBody {
1139        self.0.body.clone().into()
1140    }
1141
1142    pub fn witness_set(&self) -> ShelleyTransactionWitnessSet {
1143        self.0.witness_set.clone().into()
1144    }
1145
1146    pub fn metadata(&self) -> Option<Metadata> {
1147        self.0.metadata.clone().map(std::convert::Into::into)
1148    }
1149
1150    pub fn new(
1151        body: &ShelleyTransactionBody,
1152        witness_set: &ShelleyTransactionWitnessSet,
1153        metadata: Option<Metadata>,
1154    ) -> Self {
1155        Self(cml_multi_era::shelley::ShelleyTransaction::new(
1156            body.clone().into(),
1157            witness_set.clone().into(),
1158            metadata.map(Into::into),
1159        ))
1160    }
1161}
1162
1163#[derive(Clone, Debug)]
1164#[wasm_bindgen]
1165pub struct ShelleyTransactionBody(cml_multi_era::shelley::ShelleyTransactionBody);
1166
1167impl_wasm_cbor_json_api!(ShelleyTransactionBody);
1168
1169impl_wasm_conversions!(
1170    cml_multi_era::shelley::ShelleyTransactionBody,
1171    ShelleyTransactionBody
1172);
1173
1174#[wasm_bindgen]
1175impl ShelleyTransactionBody {
1176    pub fn inputs(&self) -> TransactionInputList {
1177        self.0.inputs.clone().into()
1178    }
1179
1180    pub fn outputs(&self) -> ShelleyTransactionOutputList {
1181        self.0.outputs.clone().into()
1182    }
1183
1184    pub fn fee(&self) -> Coin {
1185        self.0.fee
1186    }
1187
1188    pub fn ttl(&self) -> u64 {
1189        self.0.ttl
1190    }
1191
1192    pub fn set_certs(&mut self, certs: &ShelleyCertificateList) {
1193        self.0.certs = Some(certs.clone().into())
1194    }
1195
1196    pub fn certs(&self) -> Option<ShelleyCertificateList> {
1197        self.0.certs.clone().map(std::convert::Into::into)
1198    }
1199
1200    pub fn set_withdrawals(&mut self, withdrawals: &Withdrawals) {
1201        self.0.withdrawals = Some(withdrawals.clone().into())
1202    }
1203
1204    pub fn withdrawals(&self) -> Option<Withdrawals> {
1205        self.0.withdrawals.clone().map(std::convert::Into::into)
1206    }
1207
1208    pub fn set_update(&mut self, update: &ShelleyUpdate) {
1209        self.0.update = Some(update.clone().into())
1210    }
1211
1212    pub fn update(&self) -> Option<ShelleyUpdate> {
1213        self.0.update.clone().map(std::convert::Into::into)
1214    }
1215
1216    pub fn set_auxiliary_data_hash(&mut self, auxiliary_data_hash: &AuxiliaryDataHash) {
1217        self.0.auxiliary_data_hash = Some(auxiliary_data_hash.clone().into())
1218    }
1219
1220    pub fn auxiliary_data_hash(&self) -> Option<AuxiliaryDataHash> {
1221        self.0.auxiliary_data_hash.map(std::convert::Into::into)
1222    }
1223
1224    pub fn new(
1225        inputs: &TransactionInputList,
1226        outputs: &ShelleyTransactionOutputList,
1227        fee: Coin,
1228        ttl: u64,
1229    ) -> Self {
1230        Self(cml_multi_era::shelley::ShelleyTransactionBody::new(
1231            inputs.clone().into(),
1232            outputs.clone().into(),
1233            fee,
1234            ttl,
1235        ))
1236    }
1237}
1238
1239pub type ShelleyTransactionIndex = u16;
1240
1241#[derive(Clone, Debug)]
1242#[wasm_bindgen]
1243pub struct ShelleyTransactionOutput(cml_multi_era::shelley::ShelleyTransactionOutput);
1244
1245impl_wasm_cbor_json_api!(ShelleyTransactionOutput);
1246
1247impl_wasm_conversions!(
1248    cml_multi_era::shelley::ShelleyTransactionOutput,
1249    ShelleyTransactionOutput
1250);
1251
1252#[wasm_bindgen]
1253impl ShelleyTransactionOutput {
1254    pub fn address(&self) -> Address {
1255        self.0.address.clone().into()
1256    }
1257
1258    pub fn amount(&self) -> Coin {
1259        self.0.amount
1260    }
1261
1262    pub fn new(address: &Address, amount: Coin) -> Self {
1263        Self(cml_multi_era::shelley::ShelleyTransactionOutput::new(
1264            address.clone().into(),
1265            amount,
1266        ))
1267    }
1268}
1269
1270#[derive(Clone, Debug)]
1271#[wasm_bindgen]
1272pub struct ShelleyTransactionWitnessSet(cml_multi_era::shelley::ShelleyTransactionWitnessSet);
1273
1274impl_wasm_cbor_json_api!(ShelleyTransactionWitnessSet);
1275
1276impl_wasm_conversions!(
1277    cml_multi_era::shelley::ShelleyTransactionWitnessSet,
1278    ShelleyTransactionWitnessSet
1279);
1280
1281#[wasm_bindgen]
1282impl ShelleyTransactionWitnessSet {
1283    pub fn set_vkeywitnesses(&mut self, vkeywitnesses: &VkeywitnessList) {
1284        self.0.vkeywitnesses = Some(vkeywitnesses.clone().into())
1285    }
1286
1287    pub fn vkeywitnesses(&self) -> Option<VkeywitnessList> {
1288        self.0.vkeywitnesses.clone().map(std::convert::Into::into)
1289    }
1290
1291    pub fn set_native_scripts(&mut self, native_scripts: &MultisigScriptList) {
1292        self.0.native_scripts = Some(native_scripts.clone().into())
1293    }
1294
1295    pub fn native_scripts(&self) -> Option<MultisigScriptList> {
1296        self.0.native_scripts.clone().map(std::convert::Into::into)
1297    }
1298
1299    pub fn set_bootstrap_witnesses(&mut self, bootstrap_witnesses: &BootstrapWitnessList) {
1300        self.0.bootstrap_witnesses = Some(bootstrap_witnesses.clone().into())
1301    }
1302
1303    pub fn bootstrap_witnesses(&self) -> Option<BootstrapWitnessList> {
1304        self.0
1305            .bootstrap_witnesses
1306            .clone()
1307            .map(std::convert::Into::into)
1308    }
1309
1310    pub fn new() -> Self {
1311        Self(cml_multi_era::shelley::ShelleyTransactionWitnessSet::new())
1312    }
1313}
1314
1315#[derive(Clone, Debug)]
1316#[wasm_bindgen]
1317pub struct ShelleyUpdate(cml_multi_era::shelley::ShelleyUpdate);
1318
1319impl_wasm_cbor_json_api!(ShelleyUpdate);
1320
1321impl_wasm_conversions!(cml_multi_era::shelley::ShelleyUpdate, ShelleyUpdate);
1322
1323#[wasm_bindgen]
1324impl ShelleyUpdate {
1325    pub fn shelley_proposed_protocol_parameter_updates(
1326        &self,
1327    ) -> ShelleyProposedProtocolParameterUpdates {
1328        self.0
1329            .shelley_proposed_protocol_parameter_updates
1330            .clone()
1331            .into()
1332    }
1333
1334    pub fn epoch(&self) -> Epoch {
1335        self.0.epoch
1336    }
1337
1338    pub fn new(
1339        shelley_proposed_protocol_parameter_updates: &ShelleyProposedProtocolParameterUpdates,
1340        epoch: Epoch,
1341    ) -> Self {
1342        Self(cml_multi_era::shelley::ShelleyUpdate::new(
1343            shelley_proposed_protocol_parameter_updates.clone().into(),
1344            epoch,
1345        ))
1346    }
1347}