cml_chain_wasm/certs/
mod.rs

1// This file was code-generated using an experimental CDDL to rust tool:
2// https://github.com/dcSpark/cddl-codegen
3
4use super::{Coin, Epoch, Port, RelayList, SetEd25519KeyHash, UnitInterval};
5use crate::address::RewardAccount;
6use crate::governance::Anchor;
7
8use cml_core_wasm::{impl_wasm_cbor_json_api, impl_wasm_conversions};
9use cml_crypto_wasm::{Ed25519KeyHash, PoolMetadataHash, ScriptHash, VRFKeyHash};
10use wasm_bindgen::prelude::wasm_bindgen;
11
12#[derive(Clone, Debug)]
13#[wasm_bindgen]
14pub struct AuthCommitteeHotCert(cml_chain::certs::AuthCommitteeHotCert);
15
16impl_wasm_cbor_json_api!(AuthCommitteeHotCert);
17
18impl_wasm_conversions!(cml_chain::certs::AuthCommitteeHotCert, AuthCommitteeHotCert);
19
20#[wasm_bindgen]
21impl AuthCommitteeHotCert {
22    pub fn committee_cold_credential(&self) -> CommitteeColdCredential {
23        self.0.committee_cold_credential.clone().into()
24    }
25
26    pub fn committee_hot_credential(&self) -> CommitteeHotCredential {
27        self.0.committee_hot_credential.clone().into()
28    }
29
30    pub fn new(
31        committee_cold_credential: &CommitteeColdCredential,
32        committee_hot_credential: &CommitteeHotCredential,
33    ) -> Self {
34        Self(cml_chain::certs::AuthCommitteeHotCert::new(
35            committee_cold_credential.clone().into(),
36            committee_hot_credential.clone().into(),
37        ))
38    }
39}
40
41#[derive(Clone, Debug)]
42#[wasm_bindgen]
43pub struct Certificate(cml_chain::certs::Certificate);
44
45impl_wasm_cbor_json_api!(Certificate);
46
47impl_wasm_conversions!(cml_chain::certs::Certificate, Certificate);
48
49#[wasm_bindgen]
50impl Certificate {
51    /// Will be deprecated in the next era. Use RegCert instead which takes an explicit deposit amount, as that can change.
52    pub fn new_stake_registration(stake_credential: &StakeCredential) -> Self {
53        Self(cml_chain::certs::Certificate::new_stake_registration(
54            stake_credential.clone().into(),
55        ))
56    }
57
58    /// Will be deprecated in the next era. Use UnregCert instead which takes an explicit deposit amount, as that can change.
59    pub fn new_stake_deregistration(stake_credential: &StakeCredential) -> Self {
60        Self(cml_chain::certs::Certificate::new_stake_deregistration(
61            stake_credential.clone().into(),
62        ))
63    }
64
65    /// Delegate to a take pool only
66    pub fn new_stake_delegation(stake_credential: &StakeCredential, pool: &Ed25519KeyHash) -> Self {
67        Self(cml_chain::certs::Certificate::new_stake_delegation(
68            stake_credential.clone().into(),
69            pool.clone().into(),
70        ))
71    }
72
73    pub fn new_pool_registration(pool_params: &PoolParams) -> Self {
74        Self(cml_chain::certs::Certificate::new_pool_registration(
75            pool_params.clone().into(),
76        ))
77    }
78
79    pub fn new_pool_retirement(pool: &Ed25519KeyHash, epoch: Epoch) -> Self {
80        Self(cml_chain::certs::Certificate::new_pool_retirement(
81            pool.clone().into(),
82            epoch,
83        ))
84    }
85
86    /// Registers a stake credential.
87    pub fn new_reg_cert(stake_credential: &StakeCredential, deposit: Coin) -> Self {
88        Self(cml_chain::certs::Certificate::new_reg_cert(
89            stake_credential.clone().into(),
90            deposit,
91        ))
92    }
93
94    /// Unregisters a stake credential.
95    pub fn new_unreg_cert(stake_credential: &StakeCredential, deposit: Coin) -> Self {
96        Self(cml_chain::certs::Certificate::new_unreg_cert(
97            stake_credential.clone().into(),
98            deposit,
99        ))
100    }
101
102    /// Delegate to a DRep for voting only
103    pub fn new_vote_deleg_cert(stake_credential: &StakeCredential, d_rep: &DRep) -> Self {
104        Self(cml_chain::certs::Certificate::new_vote_deleg_cert(
105            stake_credential.clone().into(),
106            d_rep.clone().into(),
107        ))
108    }
109
110    /// Delegate to a stake pool and a DRep
111    pub fn new_stake_vote_deleg_cert(
112        stake_credential: &StakeCredential,
113        pool: &Ed25519KeyHash,
114        d_rep: &DRep,
115    ) -> Self {
116        Self(cml_chain::certs::Certificate::new_stake_vote_deleg_cert(
117            stake_credential.clone().into(),
118            pool.clone().into(),
119            d_rep.clone().into(),
120        ))
121    }
122
123    /// Register a stake credential and delegate to a pool in a single cert
124    pub fn new_stake_reg_deleg_cert(
125        stake_credential: &StakeCredential,
126        pool: &Ed25519KeyHash,
127        deposit: Coin,
128    ) -> Self {
129        Self(cml_chain::certs::Certificate::new_stake_reg_deleg_cert(
130            stake_credential.clone().into(),
131            pool.clone().into(),
132            deposit,
133        ))
134    }
135
136    /// Register a stake credential and delegate to a DRep in a single cert
137    pub fn new_vote_reg_deleg_cert(
138        stake_credential: &StakeCredential,
139        d_rep: &DRep,
140        deposit: Coin,
141    ) -> Self {
142        Self(cml_chain::certs::Certificate::new_vote_reg_deleg_cert(
143            stake_credential.clone().into(),
144            d_rep.clone().into(),
145            deposit,
146        ))
147    }
148
149    /// Register a stake credential and delegate to a pool and a DRep in a single cert
150    pub fn new_stake_vote_reg_deleg_cert(
151        stake_credential: &StakeCredential,
152        pool: &Ed25519KeyHash,
153        d_rep: &DRep,
154        deposit: Coin,
155    ) -> Self {
156        Self(
157            cml_chain::certs::Certificate::new_stake_vote_reg_deleg_cert(
158                stake_credential.clone().into(),
159                pool.clone().into(),
160                d_rep.clone().into(),
161                deposit,
162            ),
163        )
164    }
165
166    pub fn new_auth_committee_hot_cert(
167        committee_cold_credential: &CommitteeColdCredential,
168        committee_hot_credential: &CommitteeHotCredential,
169    ) -> Self {
170        Self(cml_chain::certs::Certificate::new_auth_committee_hot_cert(
171            committee_cold_credential.clone().into(),
172            committee_hot_credential.clone().into(),
173        ))
174    }
175
176    pub fn new_resign_committee_cold_cert(
177        committee_cold_credential: &CommitteeColdCredential,
178        anchor: Option<Anchor>,
179    ) -> Self {
180        Self(
181            cml_chain::certs::Certificate::new_resign_committee_cold_cert(
182                committee_cold_credential.clone().into(),
183                anchor.map(Into::into),
184            ),
185        )
186    }
187
188    pub fn new_reg_drep_cert(
189        drep_credential: &DrepCredential,
190        deposit: Coin,
191        anchor: Option<Anchor>,
192    ) -> Self {
193        Self(cml_chain::certs::Certificate::new_reg_drep_cert(
194            drep_credential.clone().into(),
195            deposit,
196            anchor.map(Into::into),
197        ))
198    }
199
200    pub fn new_unreg_drep_cert(drep_credential: &DrepCredential, deposit: Coin) -> Self {
201        Self(cml_chain::certs::Certificate::new_unreg_drep_cert(
202            drep_credential.clone().into(),
203            deposit,
204        ))
205    }
206
207    pub fn new_update_drep_cert(drep_credential: &DrepCredential, anchor: Option<Anchor>) -> Self {
208        Self(cml_chain::certs::Certificate::new_update_drep_cert(
209            drep_credential.clone().into(),
210            anchor.map(Into::into),
211        ))
212    }
213
214    pub fn kind(&self) -> CertificateKind {
215        match &self.0 {
216            cml_chain::certs::Certificate::StakeRegistration(_) => {
217                CertificateKind::StakeRegistration
218            }
219            cml_chain::certs::Certificate::StakeDeregistration(_) => {
220                CertificateKind::StakeDeregistration
221            }
222            cml_chain::certs::Certificate::StakeDelegation(_) => CertificateKind::StakeDelegation,
223            cml_chain::certs::Certificate::PoolRegistration(_) => CertificateKind::PoolRegistration,
224            cml_chain::certs::Certificate::PoolRetirement(_) => CertificateKind::PoolRetirement,
225            cml_chain::certs::Certificate::RegCert(_) => CertificateKind::RegCert,
226            cml_chain::certs::Certificate::UnregCert(_) => CertificateKind::UnregCert,
227            cml_chain::certs::Certificate::VoteDelegCert(_) => CertificateKind::VoteDelegCert,
228            cml_chain::certs::Certificate::StakeVoteDelegCert(_) => {
229                CertificateKind::StakeVoteDelegCert
230            }
231            cml_chain::certs::Certificate::StakeRegDelegCert(_) => {
232                CertificateKind::StakeRegDelegCert
233            }
234            cml_chain::certs::Certificate::VoteRegDelegCert(_) => CertificateKind::VoteRegDelegCert,
235            cml_chain::certs::Certificate::StakeVoteRegDelegCert(_) => {
236                CertificateKind::StakeVoteRegDelegCert
237            }
238            cml_chain::certs::Certificate::AuthCommitteeHotCert(_) => {
239                CertificateKind::AuthCommitteeHotCert
240            }
241            cml_chain::certs::Certificate::ResignCommitteeColdCert(_) => {
242                CertificateKind::ResignCommitteeColdCert
243            }
244            cml_chain::certs::Certificate::RegDrepCert(_) => CertificateKind::RegDrepCert,
245            cml_chain::certs::Certificate::UnregDrepCert(_) => CertificateKind::UnregDrepCert,
246            cml_chain::certs::Certificate::UpdateDrepCert(_) => CertificateKind::UpdateDrepCert,
247        }
248    }
249
250    pub fn as_stake_registration(&self) -> Option<StakeRegistration> {
251        match &self.0 {
252            cml_chain::certs::Certificate::StakeRegistration(stake_registration) => {
253                Some(stake_registration.clone().into())
254            }
255            _ => None,
256        }
257    }
258
259    pub fn as_stake_deregistration(&self) -> Option<StakeDeregistration> {
260        match &self.0 {
261            cml_chain::certs::Certificate::StakeDeregistration(stake_deregistration) => {
262                Some(stake_deregistration.clone().into())
263            }
264            _ => None,
265        }
266    }
267
268    pub fn as_stake_delegation(&self) -> Option<StakeDelegation> {
269        match &self.0 {
270            cml_chain::certs::Certificate::StakeDelegation(stake_delegation) => {
271                Some(stake_delegation.clone().into())
272            }
273            _ => None,
274        }
275    }
276
277    pub fn as_pool_registration(&self) -> Option<PoolRegistration> {
278        match &self.0 {
279            cml_chain::certs::Certificate::PoolRegistration(pool_registration) => {
280                Some(pool_registration.clone().into())
281            }
282            _ => None,
283        }
284    }
285
286    pub fn as_pool_retirement(&self) -> Option<PoolRetirement> {
287        match &self.0 {
288            cml_chain::certs::Certificate::PoolRetirement(pool_retirement) => {
289                Some(pool_retirement.clone().into())
290            }
291            _ => None,
292        }
293    }
294
295    pub fn as_reg_cert(&self) -> Option<RegCert> {
296        match &self.0 {
297            cml_chain::certs::Certificate::RegCert(reg_cert) => Some(reg_cert.clone().into()),
298            _ => None,
299        }
300    }
301
302    pub fn as_unreg_cert(&self) -> Option<UnregCert> {
303        match &self.0 {
304            cml_chain::certs::Certificate::UnregCert(unreg_cert) => Some(unreg_cert.clone().into()),
305            _ => None,
306        }
307    }
308
309    pub fn as_vote_deleg_cert(&self) -> Option<VoteDelegCert> {
310        match &self.0 {
311            cml_chain::certs::Certificate::VoteDelegCert(vote_deleg_cert) => {
312                Some(vote_deleg_cert.clone().into())
313            }
314            _ => None,
315        }
316    }
317
318    pub fn as_stake_vote_deleg_cert(&self) -> Option<StakeVoteDelegCert> {
319        match &self.0 {
320            cml_chain::certs::Certificate::StakeVoteDelegCert(stake_vote_deleg_cert) => {
321                Some(stake_vote_deleg_cert.clone().into())
322            }
323            _ => None,
324        }
325    }
326
327    pub fn as_stake_reg_deleg_cert(&self) -> Option<StakeRegDelegCert> {
328        match &self.0 {
329            cml_chain::certs::Certificate::StakeRegDelegCert(stake_reg_deleg_cert) => {
330                Some(stake_reg_deleg_cert.clone().into())
331            }
332            _ => None,
333        }
334    }
335
336    pub fn as_vote_reg_deleg_cert(&self) -> Option<VoteRegDelegCert> {
337        match &self.0 {
338            cml_chain::certs::Certificate::VoteRegDelegCert(vote_reg_deleg_cert) => {
339                Some(vote_reg_deleg_cert.clone().into())
340            }
341            _ => None,
342        }
343    }
344
345    pub fn as_stake_vote_reg_deleg_cert(&self) -> Option<StakeVoteRegDelegCert> {
346        match &self.0 {
347            cml_chain::certs::Certificate::StakeVoteRegDelegCert(stake_vote_reg_deleg_cert) => {
348                Some(stake_vote_reg_deleg_cert.clone().into())
349            }
350            _ => None,
351        }
352    }
353
354    pub fn as_auth_committee_hot_cert(&self) -> Option<AuthCommitteeHotCert> {
355        match &self.0 {
356            cml_chain::certs::Certificate::AuthCommitteeHotCert(auth_committee_hot_cert) => {
357                Some(auth_committee_hot_cert.clone().into())
358            }
359            _ => None,
360        }
361    }
362
363    pub fn as_resign_committee_cold_cert(&self) -> Option<ResignCommitteeColdCert> {
364        match &self.0 {
365            cml_chain::certs::Certificate::ResignCommitteeColdCert(resign_committee_cold_cert) => {
366                Some(resign_committee_cold_cert.clone().into())
367            }
368            _ => None,
369        }
370    }
371
372    pub fn as_reg_drep_cert(&self) -> Option<RegDrepCert> {
373        match &self.0 {
374            cml_chain::certs::Certificate::RegDrepCert(reg_drep_cert) => {
375                Some(reg_drep_cert.clone().into())
376            }
377            _ => None,
378        }
379    }
380
381    pub fn as_unreg_drep_cert(&self) -> Option<UnregDrepCert> {
382        match &self.0 {
383            cml_chain::certs::Certificate::UnregDrepCert(unreg_drep_cert) => {
384                Some(unreg_drep_cert.clone().into())
385            }
386            _ => None,
387        }
388    }
389
390    pub fn as_update_drep_cert(&self) -> Option<UpdateDrepCert> {
391        match &self.0 {
392            cml_chain::certs::Certificate::UpdateDrepCert(update_drep_cert) => {
393                Some(update_drep_cert.clone().into())
394            }
395            _ => None,
396        }
397    }
398}
399
400#[wasm_bindgen]
401pub enum CertificateKind {
402    StakeRegistration,
403    StakeDeregistration,
404    StakeDelegation,
405    PoolRegistration,
406    PoolRetirement,
407    RegCert,
408    UnregCert,
409    VoteDelegCert,
410    StakeVoteDelegCert,
411    StakeRegDelegCert,
412    VoteRegDelegCert,
413    StakeVoteRegDelegCert,
414    AuthCommitteeHotCert,
415    ResignCommitteeColdCert,
416    RegDrepCert,
417    UnregDrepCert,
418    UpdateDrepCert,
419}
420
421pub type CommitteeColdCredential = Credential;
422
423pub type CommitteeHotCredential = Credential;
424
425#[derive(Clone, Debug)]
426#[wasm_bindgen]
427pub struct Credential(cml_chain::certs::Credential);
428
429impl_wasm_cbor_json_api!(Credential);
430
431impl_wasm_conversions!(cml_chain::certs::Credential, Credential);
432
433#[wasm_bindgen]
434impl Credential {
435    pub fn new_pub_key(hash: &Ed25519KeyHash) -> Self {
436        Self(cml_chain::certs::Credential::new_pub_key(
437            hash.clone().into(),
438        ))
439    }
440
441    pub fn new_script(hash: &ScriptHash) -> Self {
442        Self(cml_chain::certs::Credential::new_script(
443            hash.clone().into(),
444        ))
445    }
446
447    pub fn kind(&self) -> CredentialKind {
448        match &self.0 {
449            cml_chain::certs::Credential::PubKey { .. } => CredentialKind::PubKey,
450            cml_chain::certs::Credential::Script { .. } => CredentialKind::Script,
451        }
452    }
453
454    pub fn as_pub_key(&self) -> Option<Ed25519KeyHash> {
455        match &self.0 {
456            cml_chain::certs::Credential::PubKey { hash, .. } => Some((*hash).into()),
457            _ => None,
458        }
459    }
460
461    pub fn as_script(&self) -> Option<ScriptHash> {
462        match &self.0 {
463            cml_chain::certs::Credential::Script { hash, .. } => Some((*hash).into()),
464            _ => None,
465        }
466    }
467}
468
469#[wasm_bindgen]
470pub enum CredentialKind {
471    PubKey,
472    Script,
473}
474
475#[derive(Clone, Debug)]
476#[wasm_bindgen]
477pub struct DNSName(cml_chain::certs::DNSName);
478
479impl_wasm_cbor_json_api!(DNSName);
480
481impl_wasm_conversions!(cml_chain::certs::DNSName, DNSName);
482
483#[wasm_bindgen]
484impl DNSName {
485    pub fn get(&self) -> String {
486        self.0.get().clone()
487    }
488}
489
490#[derive(Clone, Debug)]
491#[wasm_bindgen]
492pub struct DRep(cml_chain::certs::DRep);
493
494impl_wasm_cbor_json_api!(DRep);
495
496impl_wasm_conversions!(cml_chain::certs::DRep, DRep);
497
498#[wasm_bindgen]
499impl DRep {
500    pub fn new_key(pool: &Ed25519KeyHash) -> Self {
501        Self(cml_chain::certs::DRep::new_key(pool.clone().into()))
502    }
503
504    pub fn new_script(script_hash: &ScriptHash) -> Self {
505        Self(cml_chain::certs::DRep::new_script(
506            script_hash.clone().into(),
507        ))
508    }
509
510    pub fn new_always_abstain() -> Self {
511        Self(cml_chain::certs::DRep::new_always_abstain())
512    }
513
514    pub fn new_always_no_confidence() -> Self {
515        Self(cml_chain::certs::DRep::new_always_no_confidence())
516    }
517
518    pub fn kind(&self) -> DRepKind {
519        match &self.0 {
520            cml_chain::certs::DRep::Key { .. } => DRepKind::Key,
521            cml_chain::certs::DRep::Script { .. } => DRepKind::Script,
522            cml_chain::certs::DRep::AlwaysAbstain { .. } => DRepKind::AlwaysAbstain,
523            cml_chain::certs::DRep::AlwaysNoConfidence { .. } => DRepKind::AlwaysNoConfidence,
524        }
525    }
526
527    pub fn as_key(&self) -> Option<Ed25519KeyHash> {
528        match &self.0 {
529            cml_chain::certs::DRep::Key { pool, .. } => Some((*pool).into()),
530            _ => None,
531        }
532    }
533
534    pub fn as_script(&self) -> Option<ScriptHash> {
535        match &self.0 {
536            cml_chain::certs::DRep::Script { script_hash, .. } => Some((*script_hash).into()),
537            _ => None,
538        }
539    }
540}
541
542#[wasm_bindgen]
543pub enum DRepKind {
544    Key,
545    Script,
546    AlwaysAbstain,
547    AlwaysNoConfidence,
548}
549
550pub type DrepCredential = Credential;
551
552#[derive(Clone, Debug)]
553#[wasm_bindgen]
554pub struct Ipv4(cml_chain::certs::Ipv4);
555
556impl_wasm_cbor_json_api!(Ipv4);
557
558impl_wasm_conversions!(cml_chain::certs::Ipv4, Ipv4);
559
560#[wasm_bindgen]
561impl Ipv4 {
562    pub fn get(&self) -> Vec<u8> {
563        self.0.get().clone()
564    }
565}
566
567#[derive(Clone, Debug)]
568#[wasm_bindgen]
569pub struct Ipv6(cml_chain::certs::Ipv6);
570
571impl_wasm_cbor_json_api!(Ipv6);
572
573impl_wasm_conversions!(cml_chain::certs::Ipv6, Ipv6);
574
575#[wasm_bindgen]
576impl Ipv6 {
577    pub fn get(&self) -> Vec<u8> {
578        self.0.get().clone()
579    }
580}
581
582#[derive(Clone, Debug)]
583#[wasm_bindgen]
584pub struct MultiHostName(cml_chain::certs::MultiHostName);
585
586impl_wasm_cbor_json_api!(MultiHostName);
587
588impl_wasm_conversions!(cml_chain::certs::MultiHostName, MultiHostName);
589
590#[wasm_bindgen]
591impl MultiHostName {
592    pub fn dns_name(&self) -> DNSName {
593        self.0.dns_name.clone().into()
594    }
595
596    /// * `dns_name` - A SRV DNS record
597    pub fn new(dns_name: &DNSName) -> Self {
598        Self(cml_chain::certs::MultiHostName::new(
599            dns_name.clone().into(),
600        ))
601    }
602}
603
604#[derive(Clone, Debug)]
605#[wasm_bindgen]
606pub struct PoolMetadata(cml_chain::certs::PoolMetadata);
607
608impl_wasm_cbor_json_api!(PoolMetadata);
609
610impl_wasm_conversions!(cml_chain::certs::PoolMetadata, PoolMetadata);
611
612#[wasm_bindgen]
613impl PoolMetadata {
614    pub fn url(&self) -> Url {
615        self.0.url.clone().into()
616    }
617
618    pub fn pool_metadata_hash(&self) -> PoolMetadataHash {
619        self.0.pool_metadata_hash.into()
620    }
621
622    pub fn new(url: &Url, pool_metadata_hash: &PoolMetadataHash) -> Self {
623        Self(cml_chain::certs::PoolMetadata::new(
624            url.clone().into(),
625            pool_metadata_hash.clone().into(),
626        ))
627    }
628}
629
630#[derive(Clone, Debug)]
631#[wasm_bindgen]
632pub struct PoolParams(cml_chain::certs::PoolParams);
633
634impl_wasm_cbor_json_api!(PoolParams);
635
636impl_wasm_conversions!(cml_chain::certs::PoolParams, PoolParams);
637
638#[wasm_bindgen]
639impl PoolParams {
640    pub fn operator(&self) -> Ed25519KeyHash {
641        self.0.operator.into()
642    }
643
644    pub fn vrf_keyhash(&self) -> VRFKeyHash {
645        self.0.vrf_keyhash.into()
646    }
647
648    pub fn pledge(&self) -> Coin {
649        self.0.pledge
650    }
651
652    pub fn cost(&self) -> Coin {
653        self.0.cost
654    }
655
656    pub fn margin(&self) -> UnitInterval {
657        self.0.margin.clone().into()
658    }
659
660    pub fn reward_account(&self) -> RewardAccount {
661        self.0.reward_account.clone().into()
662    }
663
664    pub fn pool_owners(&self) -> SetEd25519KeyHash {
665        self.0.pool_owners.clone().into()
666    }
667
668    pub fn relays(&self) -> RelayList {
669        self.0.relays.clone().into()
670    }
671
672    pub fn pool_metadata(&self) -> Option<PoolMetadata> {
673        self.0.pool_metadata.clone().map(std::convert::Into::into)
674    }
675
676    pub fn new(
677        operator: &Ed25519KeyHash,
678        vrf_keyhash: &VRFKeyHash,
679        pledge: Coin,
680        cost: Coin,
681        margin: &UnitInterval,
682        reward_account: &RewardAccount,
683        pool_owners: &SetEd25519KeyHash,
684        relays: &RelayList,
685        pool_metadata: Option<PoolMetadata>,
686    ) -> Self {
687        Self(cml_chain::certs::PoolParams::new(
688            operator.clone().into(),
689            vrf_keyhash.clone().into(),
690            pledge,
691            cost,
692            margin.clone().into(),
693            reward_account.clone().into(),
694            pool_owners.clone().into(),
695            relays.clone().into(),
696            pool_metadata.map(Into::into),
697        ))
698    }
699}
700
701#[derive(Clone, Debug)]
702#[wasm_bindgen]
703pub struct PoolRegistration(cml_chain::certs::PoolRegistration);
704
705impl_wasm_cbor_json_api!(PoolRegistration);
706
707impl_wasm_conversions!(cml_chain::certs::PoolRegistration, PoolRegistration);
708
709#[wasm_bindgen]
710impl PoolRegistration {
711    pub fn pool_params(&self) -> PoolParams {
712        self.0.pool_params.clone().into()
713    }
714
715    pub fn new(pool_params: &PoolParams) -> Self {
716        Self(cml_chain::certs::PoolRegistration::new(
717            pool_params.clone().into(),
718        ))
719    }
720}
721
722#[derive(Clone, Debug)]
723#[wasm_bindgen]
724pub struct PoolRetirement(cml_chain::certs::PoolRetirement);
725
726impl_wasm_cbor_json_api!(PoolRetirement);
727
728impl_wasm_conversions!(cml_chain::certs::PoolRetirement, PoolRetirement);
729
730#[wasm_bindgen]
731impl PoolRetirement {
732    pub fn pool(&self) -> Ed25519KeyHash {
733        self.0.pool.into()
734    }
735
736    pub fn epoch(&self) -> Epoch {
737        self.0.epoch
738    }
739
740    pub fn new(pool: &Ed25519KeyHash, epoch: Epoch) -> Self {
741        Self(cml_chain::certs::PoolRetirement::new(
742            pool.clone().into(),
743            epoch,
744        ))
745    }
746}
747
748#[derive(Clone, Debug)]
749#[wasm_bindgen]
750pub struct RegCert(cml_chain::certs::RegCert);
751
752impl_wasm_cbor_json_api!(RegCert);
753
754impl_wasm_conversions!(cml_chain::certs::RegCert, RegCert);
755
756#[wasm_bindgen]
757impl RegCert {
758    pub fn stake_credential(&self) -> StakeCredential {
759        self.0.stake_credential.clone().into()
760    }
761
762    pub fn deposit(&self) -> Coin {
763        self.0.deposit
764    }
765
766    pub fn new(stake_credential: &StakeCredential, deposit: Coin) -> Self {
767        Self(cml_chain::certs::RegCert::new(
768            stake_credential.clone().into(),
769            deposit,
770        ))
771    }
772}
773
774#[derive(Clone, Debug)]
775#[wasm_bindgen]
776pub struct RegDrepCert(cml_chain::certs::RegDrepCert);
777
778impl_wasm_cbor_json_api!(RegDrepCert);
779
780impl_wasm_conversions!(cml_chain::certs::RegDrepCert, RegDrepCert);
781
782#[wasm_bindgen]
783impl RegDrepCert {
784    pub fn drep_credential(&self) -> DrepCredential {
785        self.0.drep_credential.clone().into()
786    }
787
788    pub fn deposit(&self) -> Coin {
789        self.0.deposit
790    }
791
792    pub fn anchor(&self) -> Option<Anchor> {
793        self.0.anchor.clone().map(std::convert::Into::into)
794    }
795
796    pub fn new(drep_credential: &DrepCredential, deposit: Coin, anchor: Option<Anchor>) -> Self {
797        Self(cml_chain::certs::RegDrepCert::new(
798            drep_credential.clone().into(),
799            deposit,
800            anchor.map(Into::into),
801        ))
802    }
803}
804
805#[derive(Clone, Debug)]
806#[wasm_bindgen]
807pub struct Relay(cml_chain::certs::Relay);
808
809impl_wasm_cbor_json_api!(Relay);
810
811impl_wasm_conversions!(cml_chain::certs::Relay, Relay);
812
813#[wasm_bindgen]
814impl Relay {
815    pub fn new_single_host_addr(
816        port: Option<Port>,
817        ipv4: Option<Ipv4>,
818        ipv6: Option<Ipv6>,
819    ) -> Self {
820        Self(cml_chain::certs::Relay::new_single_host_addr(
821            port,
822            ipv4.map(Into::into),
823            ipv6.map(Into::into),
824        ))
825    }
826
827    pub fn new_single_host_name(port: Option<Port>, dns_name: &DNSName) -> Self {
828        Self(cml_chain::certs::Relay::new_single_host_name(
829            port,
830            dns_name.clone().into(),
831        ))
832    }
833
834    pub fn new_multi_host_name(dns_name: &DNSName) -> Self {
835        Self(cml_chain::certs::Relay::new_multi_host_name(
836            dns_name.clone().into(),
837        ))
838    }
839
840    pub fn kind(&self) -> RelayKind {
841        match &self.0 {
842            cml_chain::certs::Relay::SingleHostAddr(_) => RelayKind::SingleHostAddr,
843            cml_chain::certs::Relay::SingleHostName(_) => RelayKind::SingleHostName,
844            cml_chain::certs::Relay::MultiHostName(_) => RelayKind::MultiHostName,
845        }
846    }
847
848    pub fn as_single_host_addr(&self) -> Option<SingleHostAddr> {
849        match &self.0 {
850            cml_chain::certs::Relay::SingleHostAddr(single_host_addr) => {
851                Some(single_host_addr.clone().into())
852            }
853            _ => None,
854        }
855    }
856
857    pub fn as_single_host_name(&self) -> Option<SingleHostName> {
858        match &self.0 {
859            cml_chain::certs::Relay::SingleHostName(single_host_name) => {
860                Some(single_host_name.clone().into())
861            }
862            _ => None,
863        }
864    }
865
866    pub fn as_multi_host_name(&self) -> Option<MultiHostName> {
867        match &self.0 {
868            cml_chain::certs::Relay::MultiHostName(multi_host_name) => {
869                Some(multi_host_name.clone().into())
870            }
871            _ => None,
872        }
873    }
874}
875
876#[wasm_bindgen]
877pub enum RelayKind {
878    SingleHostAddr,
879    SingleHostName,
880    MultiHostName,
881}
882
883#[derive(Clone, Debug)]
884#[wasm_bindgen]
885pub struct ResignCommitteeColdCert(cml_chain::certs::ResignCommitteeColdCert);
886
887impl_wasm_cbor_json_api!(ResignCommitteeColdCert);
888
889impl_wasm_conversions!(
890    cml_chain::certs::ResignCommitteeColdCert,
891    ResignCommitteeColdCert
892);
893
894#[wasm_bindgen]
895impl ResignCommitteeColdCert {
896    pub fn committee_cold_credential(&self) -> CommitteeColdCredential {
897        self.0.committee_cold_credential.clone().into()
898    }
899
900    pub fn anchor(&self) -> Option<Anchor> {
901        self.0.anchor.clone().map(std::convert::Into::into)
902    }
903
904    pub fn new(
905        committee_cold_credential: &CommitteeColdCredential,
906        anchor: Option<Anchor>,
907    ) -> Self {
908        Self(cml_chain::certs::ResignCommitteeColdCert::new(
909            committee_cold_credential.clone().into(),
910            anchor.map(Into::into),
911        ))
912    }
913}
914
915#[derive(Clone, Debug)]
916#[wasm_bindgen]
917pub struct SingleHostAddr(cml_chain::certs::SingleHostAddr);
918
919impl_wasm_cbor_json_api!(SingleHostAddr);
920
921impl_wasm_conversions!(cml_chain::certs::SingleHostAddr, SingleHostAddr);
922
923#[wasm_bindgen]
924impl SingleHostAddr {
925    pub fn port(&self) -> Option<Port> {
926        self.0.port
927    }
928
929    pub fn ipv4(&self) -> Option<Ipv4> {
930        self.0.ipv4.clone().map(std::convert::Into::into)
931    }
932
933    pub fn ipv6(&self) -> Option<Ipv6> {
934        self.0.ipv6.clone().map(std::convert::Into::into)
935    }
936
937    pub fn new(port: Option<Port>, ipv4: Option<Ipv4>, ipv6: Option<Ipv6>) -> Self {
938        Self(cml_chain::certs::SingleHostAddr::new(
939            port,
940            ipv4.map(Into::into),
941            ipv6.map(Into::into),
942        ))
943    }
944}
945
946#[derive(Clone, Debug)]
947#[wasm_bindgen]
948pub struct SingleHostName(cml_chain::certs::SingleHostName);
949
950impl_wasm_cbor_json_api!(SingleHostName);
951
952impl_wasm_conversions!(cml_chain::certs::SingleHostName, SingleHostName);
953
954#[wasm_bindgen]
955impl SingleHostName {
956    pub fn port(&self) -> Option<Port> {
957        self.0.port
958    }
959
960    pub fn dns_name(&self) -> DNSName {
961        self.0.dns_name.clone().into()
962    }
963
964    /// * `dns_name` - An A or AAAA DNS record
965    pub fn new(port: Option<Port>, dns_name: &DNSName) -> Self {
966        Self(cml_chain::certs::SingleHostName::new(
967            port,
968            dns_name.clone().into(),
969        ))
970    }
971}
972
973pub type StakeCredential = Credential;
974
975#[derive(Clone, Debug)]
976#[wasm_bindgen]
977pub struct StakeDelegation(cml_chain::certs::StakeDelegation);
978
979impl_wasm_cbor_json_api!(StakeDelegation);
980
981impl_wasm_conversions!(cml_chain::certs::StakeDelegation, StakeDelegation);
982
983#[wasm_bindgen]
984impl StakeDelegation {
985    pub fn stake_credential(&self) -> StakeCredential {
986        self.0.stake_credential.clone().into()
987    }
988
989    pub fn pool(&self) -> Ed25519KeyHash {
990        self.0.pool.into()
991    }
992
993    pub fn new(stake_credential: &StakeCredential, pool: &Ed25519KeyHash) -> Self {
994        Self(cml_chain::certs::StakeDelegation::new(
995            stake_credential.clone().into(),
996            pool.clone().into(),
997        ))
998    }
999}
1000
1001#[derive(Clone, Debug)]
1002#[wasm_bindgen]
1003pub struct StakeDeregistration(cml_chain::certs::StakeDeregistration);
1004
1005impl_wasm_cbor_json_api!(StakeDeregistration);
1006
1007impl_wasm_conversions!(cml_chain::certs::StakeDeregistration, StakeDeregistration);
1008
1009#[wasm_bindgen]
1010impl StakeDeregistration {
1011    pub fn stake_credential(&self) -> StakeCredential {
1012        self.0.stake_credential.clone().into()
1013    }
1014
1015    pub fn new(stake_credential: &StakeCredential) -> Self {
1016        Self(cml_chain::certs::StakeDeregistration::new(
1017            stake_credential.clone().into(),
1018        ))
1019    }
1020}
1021
1022#[derive(Clone, Debug)]
1023#[wasm_bindgen]
1024pub struct StakeRegDelegCert(cml_chain::certs::StakeRegDelegCert);
1025
1026impl_wasm_cbor_json_api!(StakeRegDelegCert);
1027
1028impl_wasm_conversions!(cml_chain::certs::StakeRegDelegCert, StakeRegDelegCert);
1029
1030#[wasm_bindgen]
1031impl StakeRegDelegCert {
1032    pub fn stake_credential(&self) -> StakeCredential {
1033        self.0.stake_credential.clone().into()
1034    }
1035
1036    pub fn pool(&self) -> Ed25519KeyHash {
1037        self.0.pool.into()
1038    }
1039
1040    pub fn deposit(&self) -> Coin {
1041        self.0.deposit
1042    }
1043
1044    pub fn new(stake_credential: &StakeCredential, pool: &Ed25519KeyHash, deposit: Coin) -> Self {
1045        Self(cml_chain::certs::StakeRegDelegCert::new(
1046            stake_credential.clone().into(),
1047            pool.clone().into(),
1048            deposit,
1049        ))
1050    }
1051}
1052
1053#[derive(Clone, Debug)]
1054#[wasm_bindgen]
1055pub struct StakeRegistration(cml_chain::certs::StakeRegistration);
1056
1057impl_wasm_cbor_json_api!(StakeRegistration);
1058
1059impl_wasm_conversions!(cml_chain::certs::StakeRegistration, StakeRegistration);
1060
1061#[wasm_bindgen]
1062impl StakeRegistration {
1063    pub fn stake_credential(&self) -> StakeCredential {
1064        self.0.stake_credential.clone().into()
1065    }
1066
1067    pub fn new(stake_credential: &StakeCredential) -> Self {
1068        Self(cml_chain::certs::StakeRegistration::new(
1069            stake_credential.clone().into(),
1070        ))
1071    }
1072}
1073
1074#[derive(Clone, Debug)]
1075#[wasm_bindgen]
1076pub struct StakeVoteDelegCert(cml_chain::certs::StakeVoteDelegCert);
1077
1078impl_wasm_cbor_json_api!(StakeVoteDelegCert);
1079
1080impl_wasm_conversions!(cml_chain::certs::StakeVoteDelegCert, StakeVoteDelegCert);
1081
1082#[wasm_bindgen]
1083impl StakeVoteDelegCert {
1084    pub fn stake_credential(&self) -> StakeCredential {
1085        self.0.stake_credential.clone().into()
1086    }
1087
1088    pub fn pool(&self) -> Ed25519KeyHash {
1089        self.0.pool.into()
1090    }
1091
1092    pub fn d_rep(&self) -> DRep {
1093        self.0.d_rep.clone().into()
1094    }
1095
1096    pub fn new(stake_credential: &StakeCredential, pool: &Ed25519KeyHash, d_rep: &DRep) -> Self {
1097        Self(cml_chain::certs::StakeVoteDelegCert::new(
1098            stake_credential.clone().into(),
1099            pool.clone().into(),
1100            d_rep.clone().into(),
1101        ))
1102    }
1103}
1104
1105#[derive(Clone, Debug)]
1106#[wasm_bindgen]
1107pub struct StakeVoteRegDelegCert(cml_chain::certs::StakeVoteRegDelegCert);
1108
1109impl_wasm_cbor_json_api!(StakeVoteRegDelegCert);
1110
1111impl_wasm_conversions!(
1112    cml_chain::certs::StakeVoteRegDelegCert,
1113    StakeVoteRegDelegCert
1114);
1115
1116#[wasm_bindgen]
1117impl StakeVoteRegDelegCert {
1118    pub fn stake_credential(&self) -> StakeCredential {
1119        self.0.stake_credential.clone().into()
1120    }
1121
1122    pub fn pool(&self) -> Ed25519KeyHash {
1123        self.0.pool.into()
1124    }
1125
1126    pub fn d_rep(&self) -> DRep {
1127        self.0.d_rep.clone().into()
1128    }
1129
1130    pub fn deposit(&self) -> Coin {
1131        self.0.deposit
1132    }
1133
1134    pub fn new(
1135        stake_credential: &StakeCredential,
1136        pool: &Ed25519KeyHash,
1137        d_rep: &DRep,
1138        deposit: Coin,
1139    ) -> Self {
1140        Self(cml_chain::certs::StakeVoteRegDelegCert::new(
1141            stake_credential.clone().into(),
1142            pool.clone().into(),
1143            d_rep.clone().into(),
1144            deposit,
1145        ))
1146    }
1147}
1148
1149#[derive(Clone, Debug)]
1150#[wasm_bindgen]
1151pub struct UnregCert(cml_chain::certs::UnregCert);
1152
1153impl_wasm_cbor_json_api!(UnregCert);
1154
1155impl_wasm_conversions!(cml_chain::certs::UnregCert, UnregCert);
1156
1157#[wasm_bindgen]
1158impl UnregCert {
1159    pub fn stake_credential(&self) -> StakeCredential {
1160        self.0.stake_credential.clone().into()
1161    }
1162
1163    pub fn deposit(&self) -> Coin {
1164        self.0.deposit
1165    }
1166
1167    pub fn new(stake_credential: &StakeCredential, deposit: Coin) -> Self {
1168        Self(cml_chain::certs::UnregCert::new(
1169            stake_credential.clone().into(),
1170            deposit,
1171        ))
1172    }
1173}
1174
1175#[derive(Clone, Debug)]
1176#[wasm_bindgen]
1177pub struct UnregDrepCert(cml_chain::certs::UnregDrepCert);
1178
1179impl_wasm_cbor_json_api!(UnregDrepCert);
1180
1181impl_wasm_conversions!(cml_chain::certs::UnregDrepCert, UnregDrepCert);
1182
1183#[wasm_bindgen]
1184impl UnregDrepCert {
1185    pub fn drep_credential(&self) -> DrepCredential {
1186        self.0.drep_credential.clone().into()
1187    }
1188
1189    pub fn deposit(&self) -> Coin {
1190        self.0.deposit
1191    }
1192
1193    pub fn new(drep_credential: &DrepCredential, deposit: Coin) -> Self {
1194        Self(cml_chain::certs::UnregDrepCert::new(
1195            drep_credential.clone().into(),
1196            deposit,
1197        ))
1198    }
1199}
1200
1201#[derive(Clone, Debug)]
1202#[wasm_bindgen]
1203pub struct UpdateDrepCert(cml_chain::certs::UpdateDrepCert);
1204
1205impl_wasm_cbor_json_api!(UpdateDrepCert);
1206
1207impl_wasm_conversions!(cml_chain::certs::UpdateDrepCert, UpdateDrepCert);
1208
1209#[wasm_bindgen]
1210impl UpdateDrepCert {
1211    pub fn drep_credential(&self) -> DrepCredential {
1212        self.0.drep_credential.clone().into()
1213    }
1214
1215    pub fn anchor(&self) -> Option<Anchor> {
1216        self.0.anchor.clone().map(std::convert::Into::into)
1217    }
1218
1219    pub fn new(drep_credential: &DrepCredential, anchor: Option<Anchor>) -> Self {
1220        Self(cml_chain::certs::UpdateDrepCert::new(
1221            drep_credential.clone().into(),
1222            anchor.map(Into::into),
1223        ))
1224    }
1225}
1226
1227#[derive(Clone, Debug)]
1228#[wasm_bindgen]
1229pub struct Url(cml_chain::certs::Url);
1230
1231impl_wasm_cbor_json_api!(Url);
1232
1233impl_wasm_conversions!(cml_chain::certs::Url, Url);
1234
1235#[wasm_bindgen]
1236impl Url {
1237    pub fn get(&self) -> String {
1238        self.0.get().clone()
1239    }
1240}
1241
1242#[derive(Clone, Debug)]
1243#[wasm_bindgen]
1244pub struct VoteDelegCert(cml_chain::certs::VoteDelegCert);
1245
1246impl_wasm_cbor_json_api!(VoteDelegCert);
1247
1248impl_wasm_conversions!(cml_chain::certs::VoteDelegCert, VoteDelegCert);
1249
1250#[wasm_bindgen]
1251impl VoteDelegCert {
1252    pub fn stake_credential(&self) -> StakeCredential {
1253        self.0.stake_credential.clone().into()
1254    }
1255
1256    pub fn d_rep(&self) -> DRep {
1257        self.0.d_rep.clone().into()
1258    }
1259
1260    pub fn new(stake_credential: &StakeCredential, d_rep: &DRep) -> Self {
1261        Self(cml_chain::certs::VoteDelegCert::new(
1262            stake_credential.clone().into(),
1263            d_rep.clone().into(),
1264        ))
1265    }
1266}
1267
1268#[derive(Clone, Debug)]
1269#[wasm_bindgen]
1270pub struct VoteRegDelegCert(cml_chain::certs::VoteRegDelegCert);
1271
1272impl_wasm_cbor_json_api!(VoteRegDelegCert);
1273
1274impl_wasm_conversions!(cml_chain::certs::VoteRegDelegCert, VoteRegDelegCert);
1275
1276#[wasm_bindgen]
1277impl VoteRegDelegCert {
1278    pub fn stake_credential(&self) -> StakeCredential {
1279        self.0.stake_credential.clone().into()
1280    }
1281
1282    pub fn d_rep(&self) -> DRep {
1283        self.0.d_rep.clone().into()
1284    }
1285
1286    pub fn deposit(&self) -> Coin {
1287        self.0.deposit
1288    }
1289
1290    pub fn new(stake_credential: &StakeCredential, d_rep: &DRep, deposit: Coin) -> Self {
1291        Self(cml_chain::certs::VoteRegDelegCert::new(
1292            stake_credential.clone().into(),
1293            d_rep.clone().into(),
1294            deposit,
1295        ))
1296    }
1297}