1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crate::*;

#[derive(
    Clone,
    Debug,
    Hash,
    Eq,
    Ord,
    PartialEq,
    PartialOrd,
    serde::Serialize,
    serde::Deserialize,
    JsonSchema,
)]
#[wasm_bindgen]
pub struct DRepUpdate {
    pub(crate) voting_credential: Credential,
    pub(crate) anchor: Option<Anchor>,
}

impl_to_from!(DRepUpdate);

#[wasm_bindgen]
impl DRepUpdate {
    pub fn voting_credential(&self) -> Credential {
        self.voting_credential.clone()
    }

    pub fn anchor(&self) -> Option<Anchor> {
        self.anchor.clone()
    }

    pub fn new(voting_credential: &Credential) -> Self {
        Self {
            voting_credential: voting_credential.clone(),
            anchor: None,
        }
    }

    pub fn new_with_anchor(voting_credential: &Credential, anchor: &Anchor) -> Self {
        Self {
            voting_credential: voting_credential.clone(),
            anchor: Some(anchor.clone()),
        }
    }

    pub fn has_script_credentials(&self) -> bool {
        self.voting_credential.has_script_hash()
    }
}