cml_chain/certs/
mod.rs

1// This file was code-generated using an experimental CDDL to rust tool:
2// https://github.com/dcSpark/cddl-codegen
3
4pub mod cbor_encodings;
5pub mod serialization;
6pub mod utils;
7
8use super::{Coin, Epoch, Port, SetEd25519KeyHash, UnitInterval};
9use crate::address::RewardAccount;
10use crate::crypto::{Ed25519KeyHash, PoolMetadataHash, ScriptHash, VRFKeyHash};
11use crate::governance::Anchor;
12use cbor_encodings::{
13    AuthCommitteeHotCertEncoding, DNSNameEncoding, Ipv4Encoding, Ipv6Encoding,
14    MultiHostNameEncoding, PoolMetadataEncoding, PoolParamsEncoding, PoolRegistrationEncoding,
15    PoolRetirementEncoding, RegCertEncoding, RegDrepCertEncoding, ResignCommitteeColdCertEncoding,
16    SingleHostAddrEncoding, SingleHostNameEncoding, StakeDelegationEncoding,
17    StakeDeregistrationEncoding, StakeRegDelegCertEncoding, StakeRegistrationEncoding,
18    StakeVoteDelegCertEncoding, StakeVoteRegDelegCertEncoding, UnregCertEncoding,
19    UnregDrepCertEncoding, UpdateDrepCertEncoding, UrlEncoding, VoteDelegCertEncoding,
20    VoteRegDelegCertEncoding,
21};
22use cml_core::error::*;
23
24use cml_core::serialization::{LenEncoding, StringEncoding};
25
26use std::convert::TryFrom;
27
28#[allow(clippy::large_enum_variant)]
29#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
30pub struct AuthCommitteeHotCert {
31    pub committee_cold_credential: CommitteeColdCredential,
32    pub committee_hot_credential: CommitteeHotCredential,
33    #[serde(skip)]
34    pub encodings: Option<AuthCommitteeHotCertEncoding>,
35}
36
37impl AuthCommitteeHotCert {
38    pub fn new(
39        committee_cold_credential: CommitteeColdCredential,
40        committee_hot_credential: CommitteeHotCredential,
41    ) -> Self {
42        Self {
43            committee_cold_credential,
44            committee_hot_credential,
45            encodings: None,
46        }
47    }
48}
49
50#[allow(clippy::large_enum_variant)]
51#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
52pub enum Certificate {
53    /// Will be deprecated in the next era. Use RegCert instead which takes an explicit deposit amount, as that can change.
54    StakeRegistration(StakeRegistration),
55    /// Will be deprecated in the next era. Use UnregCert instead which takes an explicit deposit amount, as that can change.
56    StakeDeregistration(StakeDeregistration),
57    /// Delegate to a take pool only
58    StakeDelegation(StakeDelegation),
59    PoolRegistration(PoolRegistration),
60    PoolRetirement(PoolRetirement),
61    /// Registers a stake credential.
62    RegCert(RegCert),
63    /// Unregisters a stake credential.
64    UnregCert(UnregCert),
65    /// Delegate to a DRep for voting only
66    VoteDelegCert(VoteDelegCert),
67    /// Delegate to a stake pool and a DRep
68    StakeVoteDelegCert(StakeVoteDelegCert),
69    /// Register a stake credential and delegate to a pool in a single cert
70    StakeRegDelegCert(StakeRegDelegCert),
71    /// Register a stake credential and delegate to a DRep in a single cert
72    VoteRegDelegCert(VoteRegDelegCert),
73    /// Register a stake credential and delegate to a pool and a DRep in a single cert
74    StakeVoteRegDelegCert(StakeVoteRegDelegCert),
75    AuthCommitteeHotCert(AuthCommitteeHotCert),
76    ResignCommitteeColdCert(ResignCommitteeColdCert),
77    RegDrepCert(RegDrepCert),
78    UnregDrepCert(UnregDrepCert),
79    UpdateDrepCert(UpdateDrepCert),
80}
81
82impl Certificate {
83    /// Will be deprecated in the next era. Use RegCert instead which takes an explicit deposit amount, as that can change.
84    pub fn new_stake_registration(stake_credential: StakeCredential) -> Self {
85        Self::StakeRegistration(StakeRegistration::new(stake_credential))
86    }
87
88    /// Will be deprecated in the next era. Use UnregCert instead which takes an explicit deposit amount, as that can change.
89    pub fn new_stake_deregistration(stake_credential: StakeCredential) -> Self {
90        Self::StakeDeregistration(StakeDeregistration::new(stake_credential))
91    }
92
93    /// Delegate to a take pool only
94    pub fn new_stake_delegation(stake_credential: StakeCredential, pool: Ed25519KeyHash) -> Self {
95        Self::StakeDelegation(StakeDelegation::new(stake_credential, pool))
96    }
97
98    pub fn new_pool_registration(pool_params: PoolParams) -> Self {
99        Self::PoolRegistration(PoolRegistration::new(pool_params))
100    }
101
102    pub fn new_pool_retirement(pool: Ed25519KeyHash, epoch: Epoch) -> Self {
103        Self::PoolRetirement(PoolRetirement::new(pool, epoch))
104    }
105
106    /// Registers a stake credential.
107    pub fn new_reg_cert(stake_credential: StakeCredential, deposit: Coin) -> Self {
108        Self::RegCert(RegCert::new(stake_credential, deposit))
109    }
110
111    /// Unregisters a stake credential.
112    pub fn new_unreg_cert(stake_credential: StakeCredential, deposit: Coin) -> Self {
113        Self::UnregCert(UnregCert::new(stake_credential, deposit))
114    }
115
116    /// Delegate to a DRep for voting only
117    pub fn new_vote_deleg_cert(stake_credential: StakeCredential, d_rep: DRep) -> Self {
118        Self::VoteDelegCert(VoteDelegCert::new(stake_credential, d_rep))
119    }
120
121    /// Delegate to a stake pool and a DRep
122    pub fn new_stake_vote_deleg_cert(
123        stake_credential: StakeCredential,
124        pool: Ed25519KeyHash,
125        d_rep: DRep,
126    ) -> Self {
127        Self::StakeVoteDelegCert(StakeVoteDelegCert::new(stake_credential, pool, d_rep))
128    }
129
130    /// Register a stake credential and delegate to a pool in a single cert
131    pub fn new_stake_reg_deleg_cert(
132        stake_credential: StakeCredential,
133        pool: Ed25519KeyHash,
134        deposit: Coin,
135    ) -> Self {
136        Self::StakeRegDelegCert(StakeRegDelegCert::new(stake_credential, pool, deposit))
137    }
138
139    /// Register a stake credential and delegate to a DRep in a single cert
140    pub fn new_vote_reg_deleg_cert(
141        stake_credential: StakeCredential,
142        d_rep: DRep,
143        deposit: Coin,
144    ) -> Self {
145        Self::VoteRegDelegCert(VoteRegDelegCert::new(stake_credential, d_rep, deposit))
146    }
147
148    /// Register a stake credential and delegate to a pool and a DRep in a single cert
149    pub fn new_stake_vote_reg_deleg_cert(
150        stake_credential: StakeCredential,
151        pool: Ed25519KeyHash,
152        d_rep: DRep,
153        deposit: Coin,
154    ) -> Self {
155        Self::StakeVoteRegDelegCert(StakeVoteRegDelegCert::new(
156            stake_credential,
157            pool,
158            d_rep,
159            deposit,
160        ))
161    }
162
163    pub fn new_auth_committee_hot_cert(
164        committee_cold_credential: CommitteeColdCredential,
165        committee_hot_credential: CommitteeHotCredential,
166    ) -> Self {
167        Self::AuthCommitteeHotCert(AuthCommitteeHotCert::new(
168            committee_cold_credential,
169            committee_hot_credential,
170        ))
171    }
172
173    pub fn new_resign_committee_cold_cert(
174        committee_cold_credential: CommitteeColdCredential,
175        anchor: Option<Anchor>,
176    ) -> Self {
177        Self::ResignCommitteeColdCert(ResignCommitteeColdCert::new(
178            committee_cold_credential,
179            anchor,
180        ))
181    }
182
183    pub fn new_reg_drep_cert(
184        drep_credential: DrepCredential,
185        deposit: Coin,
186        anchor: Option<Anchor>,
187    ) -> Self {
188        Self::RegDrepCert(RegDrepCert::new(drep_credential, deposit, anchor))
189    }
190
191    pub fn new_unreg_drep_cert(drep_credential: DrepCredential, deposit: Coin) -> Self {
192        Self::UnregDrepCert(UnregDrepCert::new(drep_credential, deposit))
193    }
194
195    pub fn new_update_drep_cert(drep_credential: DrepCredential, anchor: Option<Anchor>) -> Self {
196        Self::UpdateDrepCert(UpdateDrepCert::new(drep_credential, anchor))
197    }
198}
199
200pub type CommitteeColdCredential = Credential;
201
202pub type CommitteeHotCredential = Credential;
203
204#[derive(
205    Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema, derivative::Derivative,
206)]
207#[derivative(
208    Eq,
209    PartialEq,
210    Ord = "feature_allow_slow_enum",
211    PartialOrd = "feature_allow_slow_enum",
212    Hash
213)]
214pub enum Credential {
215    PubKey {
216        hash: Ed25519KeyHash,
217        #[derivative(
218            PartialEq = "ignore",
219            Ord = "ignore",
220            PartialOrd = "ignore",
221            Hash = "ignore"
222        )]
223        #[serde(skip)]
224        len_encoding: LenEncoding,
225        #[derivative(
226            PartialEq = "ignore",
227            Ord = "ignore",
228            PartialOrd = "ignore",
229            Hash = "ignore"
230        )]
231        #[serde(skip)]
232        tag_encoding: Option<cbor_event::Sz>,
233        #[derivative(
234            PartialEq = "ignore",
235            Ord = "ignore",
236            PartialOrd = "ignore",
237            Hash = "ignore"
238        )]
239        #[serde(skip)]
240        hash_encoding: StringEncoding,
241    },
242    Script {
243        hash: ScriptHash,
244        #[derivative(
245            PartialEq = "ignore",
246            Ord = "ignore",
247            PartialOrd = "ignore",
248            Hash = "ignore"
249        )]
250        #[serde(skip)]
251        len_encoding: LenEncoding,
252        #[derivative(
253            PartialEq = "ignore",
254            Ord = "ignore",
255            PartialOrd = "ignore",
256            Hash = "ignore"
257        )]
258        #[serde(skip)]
259        tag_encoding: Option<cbor_event::Sz>,
260        #[derivative(
261            PartialEq = "ignore",
262            Ord = "ignore",
263            PartialOrd = "ignore",
264            Hash = "ignore"
265        )]
266        #[serde(skip)]
267        hash_encoding: StringEncoding,
268    },
269}
270
271impl Credential {
272    pub fn new_pub_key(hash: Ed25519KeyHash) -> Self {
273        Self::PubKey {
274            hash,
275            len_encoding: LenEncoding::default(),
276            tag_encoding: None,
277            hash_encoding: StringEncoding::default(),
278        }
279    }
280
281    pub fn new_script(hash: ScriptHash) -> Self {
282        Self::Script {
283            hash,
284            len_encoding: LenEncoding::default(),
285            tag_encoding: None,
286            hash_encoding: StringEncoding::default(),
287        }
288    }
289}
290
291#[derive(Clone, Debug)]
292pub struct DNSName {
293    pub inner: String,
294    pub encodings: Option<DNSNameEncoding>,
295}
296
297impl DNSName {
298    pub fn get(&self) -> &String {
299        &self.inner
300    }
301
302    pub fn new(inner: String) -> Result<Self, DeserializeError> {
303        if inner.len() > 128 {
304            return Err(DeserializeError::new(
305                "DNSName",
306                DeserializeFailure::RangeCheck {
307                    found: inner.len() as isize,
308                    min: Some(0),
309                    max: Some(128),
310                },
311            ));
312        }
313        Ok(Self {
314            inner,
315            encodings: None,
316        })
317    }
318}
319
320impl TryFrom<String> for DNSName {
321    type Error = DeserializeError;
322
323    fn try_from(inner: String) -> Result<Self, Self::Error> {
324        DNSName::new(inner)
325    }
326}
327
328impl serde::Serialize for DNSName {
329    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
330    where
331        S: serde::Serializer,
332    {
333        self.inner.serialize(serializer)
334    }
335}
336
337impl<'de> serde::de::Deserialize<'de> for DNSName {
338    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
339    where
340        D: serde::de::Deserializer<'de>,
341    {
342        let inner = <String as serde::de::Deserialize>::deserialize(deserializer)?;
343        Self::new(inner.clone()).map_err(|_e| {
344            serde::de::Error::invalid_value(serde::de::Unexpected::Str(&inner), &"invalid DNSName")
345        })
346    }
347}
348
349impl schemars::JsonSchema for DNSName {
350    fn schema_name() -> String {
351        String::from("DNSName")
352    }
353
354    fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
355        String::json_schema(gen)
356    }
357
358    fn is_referenceable() -> bool {
359        String::is_referenceable()
360    }
361}
362
363#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
364pub enum DRep {
365    Key {
366        pool: Ed25519KeyHash,
367        #[serde(skip)]
368        len_encoding: LenEncoding,
369        #[serde(skip)]
370        index_0_encoding: Option<cbor_event::Sz>,
371        #[serde(skip)]
372        pool_encoding: StringEncoding,
373    },
374    Script {
375        script_hash: ScriptHash,
376        #[serde(skip)]
377        len_encoding: LenEncoding,
378        #[serde(skip)]
379        index_0_encoding: Option<cbor_event::Sz>,
380        #[serde(skip)]
381        script_hash_encoding: StringEncoding,
382    },
383    AlwaysAbstain {
384        #[serde(skip)]
385        always_abstain_encoding: Option<cbor_event::Sz>,
386        #[serde(skip)]
387        len_encoding: LenEncoding,
388    },
389    AlwaysNoConfidence {
390        #[serde(skip)]
391        always_no_confidence_encoding: Option<cbor_event::Sz>,
392        #[serde(skip)]
393        len_encoding: LenEncoding,
394    },
395}
396
397impl DRep {
398    pub fn new_key(pool: Ed25519KeyHash) -> Self {
399        Self::Key {
400            pool,
401            len_encoding: LenEncoding::default(),
402            index_0_encoding: None,
403            pool_encoding: StringEncoding::default(),
404        }
405    }
406
407    pub fn new_script(script_hash: ScriptHash) -> Self {
408        Self::Script {
409            script_hash,
410            len_encoding: LenEncoding::default(),
411            index_0_encoding: None,
412            script_hash_encoding: StringEncoding::default(),
413        }
414    }
415
416    pub fn new_always_abstain() -> Self {
417        Self::AlwaysAbstain {
418            always_abstain_encoding: None,
419            len_encoding: LenEncoding::default(),
420        }
421    }
422
423    pub fn new_always_no_confidence() -> Self {
424        Self::AlwaysNoConfidence {
425            always_no_confidence_encoding: None,
426            len_encoding: LenEncoding::default(),
427        }
428    }
429}
430
431pub type DrepCredential = Credential;
432
433#[derive(Clone, Debug)]
434pub struct Ipv4 {
435    pub inner: Vec<u8>,
436    pub encodings: Option<Ipv4Encoding>,
437}
438
439impl Ipv4 {
440    pub fn get(&self) -> &Vec<u8> {
441        &self.inner
442    }
443
444    pub fn new(inner: Vec<u8>) -> Result<Self, DeserializeError> {
445        if inner.len() != 4 {
446            return Err(DeserializeError::new(
447                "Ipv4",
448                DeserializeFailure::RangeCheck {
449                    found: inner.len() as isize,
450                    min: Some(4),
451                    max: Some(4),
452                },
453            ));
454        }
455        Ok(Self {
456            inner,
457            encodings: None,
458        })
459    }
460}
461
462impl TryFrom<Vec<u8>> for Ipv4 {
463    type Error = DeserializeError;
464
465    fn try_from(inner: Vec<u8>) -> Result<Self, Self::Error> {
466        Ipv4::new(inner)
467    }
468}
469
470impl From<Ipv4> for Vec<u8> {
471    fn from(wrapper: Ipv4) -> Self {
472        wrapper.inner
473    }
474}
475
476#[derive(Clone, Debug)]
477pub struct Ipv6 {
478    pub inner: Vec<u8>,
479    pub encodings: Option<Ipv6Encoding>,
480}
481
482impl Ipv6 {
483    pub fn get(&self) -> &Vec<u8> {
484        &self.inner
485    }
486
487    pub fn new(inner: Vec<u8>) -> Result<Self, DeserializeError> {
488        if inner.len() != 16 {
489            return Err(DeserializeError::new(
490                "Ipv6",
491                DeserializeFailure::RangeCheck {
492                    found: inner.len() as isize,
493                    min: Some(16),
494                    max: Some(16),
495                },
496            ));
497        }
498        Ok(Self {
499            inner,
500            encodings: None,
501        })
502    }
503}
504
505impl TryFrom<Vec<u8>> for Ipv6 {
506    type Error = DeserializeError;
507
508    fn try_from(inner: Vec<u8>) -> Result<Self, Self::Error> {
509        Ipv6::new(inner)
510    }
511}
512
513impl From<Ipv6> for Vec<u8> {
514    fn from(wrapper: Ipv6) -> Self {
515        wrapper.inner
516    }
517}
518
519#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
520pub struct MultiHostName {
521    /// A SRV DNS record
522    pub dns_name: DNSName,
523    #[serde(skip)]
524    pub encodings: Option<MultiHostNameEncoding>,
525}
526
527impl MultiHostName {
528    /// * `dns_name` - A SRV DNS record
529    pub fn new(dns_name: DNSName) -> Self {
530        Self {
531            dns_name,
532            encodings: None,
533        }
534    }
535}
536
537#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
538pub struct PoolMetadata {
539    pub url: Url,
540    pub pool_metadata_hash: PoolMetadataHash,
541    #[serde(skip)]
542    pub encodings: Option<PoolMetadataEncoding>,
543}
544
545impl PoolMetadata {
546    pub fn new(url: Url, pool_metadata_hash: PoolMetadataHash) -> Self {
547        Self {
548            url,
549            pool_metadata_hash,
550            encodings: None,
551        }
552    }
553}
554
555#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
556pub struct PoolParams {
557    pub operator: Ed25519KeyHash,
558    pub vrf_keyhash: VRFKeyHash,
559    pub pledge: Coin,
560    pub cost: Coin,
561    pub margin: UnitInterval,
562    pub reward_account: RewardAccount,
563    pub pool_owners: SetEd25519KeyHash,
564    pub relays: Vec<Relay>,
565    pub pool_metadata: Option<PoolMetadata>,
566    #[serde(skip)]
567    pub encodings: Option<PoolParamsEncoding>,
568}
569
570impl PoolParams {
571    #[allow(clippy::too_many_arguments)]
572    pub fn new(
573        operator: Ed25519KeyHash,
574        vrf_keyhash: VRFKeyHash,
575        pledge: Coin,
576        cost: Coin,
577        margin: UnitInterval,
578        reward_account: RewardAccount,
579        pool_owners: SetEd25519KeyHash,
580        relays: Vec<Relay>,
581        pool_metadata: Option<PoolMetadata>,
582    ) -> Self {
583        Self {
584            operator,
585            vrf_keyhash,
586            pledge,
587            cost,
588            margin,
589            reward_account,
590            pool_owners,
591            relays,
592            pool_metadata,
593            encodings: None,
594        }
595    }
596}
597
598#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
599pub struct PoolRegistration {
600    pub pool_params: PoolParams,
601    #[serde(skip)]
602    pub encodings: Option<PoolRegistrationEncoding>,
603}
604
605impl PoolRegistration {
606    pub fn new(pool_params: PoolParams) -> Self {
607        Self {
608            pool_params,
609            encodings: None,
610        }
611    }
612}
613
614#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
615pub struct PoolRetirement {
616    pub pool: Ed25519KeyHash,
617    pub epoch: Epoch,
618    #[serde(skip)]
619    pub encodings: Option<PoolRetirementEncoding>,
620}
621
622impl PoolRetirement {
623    pub fn new(pool: Ed25519KeyHash, epoch: Epoch) -> Self {
624        Self {
625            pool,
626            epoch,
627            encodings: None,
628        }
629    }
630}
631
632#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
633pub struct RegCert {
634    pub stake_credential: StakeCredential,
635    pub deposit: Coin,
636    #[serde(skip)]
637    pub encodings: Option<RegCertEncoding>,
638}
639
640impl RegCert {
641    pub fn new(stake_credential: StakeCredential, deposit: Coin) -> Self {
642        Self {
643            stake_credential,
644            deposit,
645            encodings: None,
646        }
647    }
648}
649
650#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
651pub struct RegDrepCert {
652    pub drep_credential: DrepCredential,
653    pub deposit: Coin,
654    pub anchor: Option<Anchor>,
655    #[serde(skip)]
656    pub encodings: Option<RegDrepCertEncoding>,
657}
658
659impl RegDrepCert {
660    pub fn new(drep_credential: DrepCredential, deposit: Coin, anchor: Option<Anchor>) -> Self {
661        Self {
662            drep_credential,
663            deposit,
664            anchor,
665            encodings: None,
666        }
667    }
668}
669
670#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
671pub enum Relay {
672    SingleHostAddr(SingleHostAddr),
673    SingleHostName(SingleHostName),
674    MultiHostName(MultiHostName),
675}
676
677impl Relay {
678    pub fn new_single_host_addr(
679        port: Option<Port>,
680        ipv4: Option<Ipv4>,
681        ipv6: Option<Ipv6>,
682    ) -> Self {
683        Self::SingleHostAddr(SingleHostAddr::new(port, ipv4, ipv6))
684    }
685
686    pub fn new_single_host_name(port: Option<Port>, dns_name: DNSName) -> Self {
687        Self::SingleHostName(SingleHostName::new(port, dns_name))
688    }
689
690    pub fn new_multi_host_name(dns_name: DNSName) -> Self {
691        Self::MultiHostName(MultiHostName::new(dns_name))
692    }
693}
694
695#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
696pub struct ResignCommitteeColdCert {
697    pub committee_cold_credential: CommitteeColdCredential,
698    pub anchor: Option<Anchor>,
699    #[serde(skip)]
700    pub encodings: Option<ResignCommitteeColdCertEncoding>,
701}
702
703impl ResignCommitteeColdCert {
704    pub fn new(committee_cold_credential: CommitteeColdCredential, anchor: Option<Anchor>) -> Self {
705        Self {
706            committee_cold_credential,
707            anchor,
708            encodings: None,
709        }
710    }
711}
712
713#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
714pub struct SingleHostAddr {
715    pub port: Option<Port>,
716    pub ipv4: Option<Ipv4>,
717    pub ipv6: Option<Ipv6>,
718    #[serde(skip)]
719    pub encodings: Option<SingleHostAddrEncoding>,
720}
721
722impl SingleHostAddr {
723    pub fn new(port: Option<Port>, ipv4: Option<Ipv4>, ipv6: Option<Ipv6>) -> Self {
724        Self {
725            port,
726            ipv4,
727            ipv6,
728            encodings: None,
729        }
730    }
731}
732
733#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
734pub struct SingleHostName {
735    pub port: Option<Port>,
736    /// An A or AAAA DNS record
737    pub dns_name: DNSName,
738    #[serde(skip)]
739    pub encodings: Option<SingleHostNameEncoding>,
740}
741
742impl SingleHostName {
743    /// * `dns_name` - An A or AAAA DNS record
744    pub fn new(port: Option<Port>, dns_name: DNSName) -> Self {
745        Self {
746            port,
747            dns_name,
748            encodings: None,
749        }
750    }
751}
752
753pub type StakeCredential = Credential;
754
755#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
756pub struct StakeDelegation {
757    pub stake_credential: StakeCredential,
758    pub pool: Ed25519KeyHash,
759    #[serde(skip)]
760    pub encodings: Option<StakeDelegationEncoding>,
761}
762
763impl StakeDelegation {
764    pub fn new(stake_credential: StakeCredential, pool: Ed25519KeyHash) -> Self {
765        Self {
766            stake_credential,
767            pool,
768            encodings: None,
769        }
770    }
771}
772
773#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
774pub struct StakeDeregistration {
775    pub stake_credential: StakeCredential,
776    #[serde(skip)]
777    pub encodings: Option<StakeDeregistrationEncoding>,
778}
779
780impl StakeDeregistration {
781    pub fn new(stake_credential: StakeCredential) -> Self {
782        Self {
783            stake_credential,
784            encodings: None,
785        }
786    }
787}
788
789#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
790pub struct StakeRegDelegCert {
791    pub stake_credential: StakeCredential,
792    pub pool: Ed25519KeyHash,
793    pub deposit: Coin,
794    #[serde(skip)]
795    pub encodings: Option<StakeRegDelegCertEncoding>,
796}
797
798impl StakeRegDelegCert {
799    pub fn new(stake_credential: StakeCredential, pool: Ed25519KeyHash, deposit: Coin) -> Self {
800        Self {
801            stake_credential,
802            pool,
803            deposit,
804            encodings: None,
805        }
806    }
807}
808
809#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
810pub struct StakeRegistration {
811    pub stake_credential: StakeCredential,
812    #[serde(skip)]
813    pub encodings: Option<StakeRegistrationEncoding>,
814}
815
816impl StakeRegistration {
817    pub fn new(stake_credential: StakeCredential) -> Self {
818        Self {
819            stake_credential,
820            encodings: None,
821        }
822    }
823}
824
825#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
826pub struct StakeVoteDelegCert {
827    pub stake_credential: StakeCredential,
828    pub pool: Ed25519KeyHash,
829    pub d_rep: DRep,
830    #[serde(skip)]
831    pub encodings: Option<StakeVoteDelegCertEncoding>,
832}
833
834impl StakeVoteDelegCert {
835    pub fn new(stake_credential: StakeCredential, pool: Ed25519KeyHash, d_rep: DRep) -> Self {
836        Self {
837            stake_credential,
838            pool,
839            d_rep,
840            encodings: None,
841        }
842    }
843}
844
845#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
846pub struct StakeVoteRegDelegCert {
847    pub stake_credential: StakeCredential,
848    pub pool: Ed25519KeyHash,
849    pub d_rep: DRep,
850    pub deposit: Coin,
851    #[serde(skip)]
852    pub encodings: Option<StakeVoteRegDelegCertEncoding>,
853}
854
855impl StakeVoteRegDelegCert {
856    pub fn new(
857        stake_credential: StakeCredential,
858        pool: Ed25519KeyHash,
859        d_rep: DRep,
860        deposit: Coin,
861    ) -> Self {
862        Self {
863            stake_credential,
864            pool,
865            d_rep,
866            deposit,
867            encodings: None,
868        }
869    }
870}
871
872impl From<DNSName> for String {
873    fn from(wrapper: DNSName) -> Self {
874        wrapper.inner
875    }
876}
877
878impl From<Url> for String {
879    fn from(wrapper: Url) -> Self {
880        wrapper.inner
881    }
882}
883
884#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
885pub struct UnregCert {
886    pub stake_credential: StakeCredential,
887    pub deposit: Coin,
888    #[serde(skip)]
889    pub encodings: Option<UnregCertEncoding>,
890}
891
892impl UnregCert {
893    pub fn new(stake_credential: StakeCredential, deposit: Coin) -> Self {
894        Self {
895            stake_credential,
896            deposit,
897            encodings: None,
898        }
899    }
900}
901
902#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
903pub struct UnregDrepCert {
904    pub drep_credential: DrepCredential,
905    pub deposit: Coin,
906    #[serde(skip)]
907    pub encodings: Option<UnregDrepCertEncoding>,
908}
909
910impl UnregDrepCert {
911    pub fn new(drep_credential: DrepCredential, deposit: Coin) -> Self {
912        Self {
913            drep_credential,
914            deposit,
915            encodings: None,
916        }
917    }
918}
919
920#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
921pub struct UpdateDrepCert {
922    pub drep_credential: DrepCredential,
923    pub anchor: Option<Anchor>,
924    #[serde(skip)]
925    pub encodings: Option<UpdateDrepCertEncoding>,
926}
927
928impl UpdateDrepCert {
929    pub fn new(drep_credential: DrepCredential, anchor: Option<Anchor>) -> Self {
930        Self {
931            drep_credential,
932            anchor,
933            encodings: None,
934        }
935    }
936}
937
938#[derive(Clone, Debug)]
939pub struct Url {
940    pub inner: String,
941    pub encodings: Option<UrlEncoding>,
942}
943
944impl Url {
945    pub fn get(&self) -> &String {
946        &self.inner
947    }
948
949    pub fn new(inner: String) -> Result<Self, DeserializeError> {
950        if inner.len() > 128 {
951            return Err(DeserializeError::new(
952                "Url",
953                DeserializeFailure::RangeCheck {
954                    found: inner.len() as isize,
955                    min: Some(0),
956                    max: Some(128),
957                },
958            ));
959        }
960        Ok(Self {
961            inner,
962            encodings: None,
963        })
964    }
965}
966
967impl TryFrom<String> for Url {
968    type Error = DeserializeError;
969
970    fn try_from(inner: String) -> Result<Self, Self::Error> {
971        Url::new(inner)
972    }
973}
974
975impl serde::Serialize for Url {
976    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
977    where
978        S: serde::Serializer,
979    {
980        self.inner.serialize(serializer)
981    }
982}
983
984impl<'de> serde::de::Deserialize<'de> for Url {
985    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
986    where
987        D: serde::de::Deserializer<'de>,
988    {
989        let inner = <String as serde::de::Deserialize>::deserialize(deserializer)?;
990        Self::new(inner.clone()).map_err(|_e| {
991            serde::de::Error::invalid_value(serde::de::Unexpected::Str(&inner), &"invalid Url")
992        })
993    }
994}
995
996impl schemars::JsonSchema for Url {
997    fn schema_name() -> String {
998        String::from("Url")
999    }
1000
1001    fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
1002        String::json_schema(gen)
1003    }
1004
1005    fn is_referenceable() -> bool {
1006        String::is_referenceable()
1007    }
1008}
1009
1010#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
1011pub struct VoteDelegCert {
1012    pub stake_credential: StakeCredential,
1013    pub d_rep: DRep,
1014    #[serde(skip)]
1015    pub encodings: Option<VoteDelegCertEncoding>,
1016}
1017
1018impl VoteDelegCert {
1019    pub fn new(stake_credential: StakeCredential, d_rep: DRep) -> Self {
1020        Self {
1021            stake_credential,
1022            d_rep,
1023            encodings: None,
1024        }
1025    }
1026}
1027
1028#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
1029pub struct VoteRegDelegCert {
1030    pub stake_credential: StakeCredential,
1031    pub d_rep: DRep,
1032    pub deposit: Coin,
1033    #[serde(skip)]
1034    pub encodings: Option<VoteRegDelegCertEncoding>,
1035}
1036
1037impl VoteRegDelegCert {
1038    pub fn new(stake_credential: StakeCredential, d_rep: DRep, deposit: Coin) -> Self {
1039        Self {
1040            stake_credential,
1041            d_rep,
1042            deposit,
1043            encodings: None,
1044        }
1045    }
1046}