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
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
use crate::client::client_types::{terra_decimal_format, terra_opt_decimal_format};
use crate::core_types::{Coin, MsgInternal};

use crate::messages::Message;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Debug)]
/// Description of the validator which appears in public
/// on MsgEditValidator messages for fields that don't change you should put "[do-not-modify]"
///
pub struct ValidatorDescription {
    pub details: String,
    pub identity: String,
    pub moniker: String,
    pub security_contact: String,
    pub website: String,
}
impl ValidatorDescription {
    pub fn create_create(
        details: Option<String>,
        identity: Option<String>,
        moniker: String,
        security_contact: Option<String>,
        website: Option<String>,
    ) -> ValidatorDescription {
        ValidatorDescription {
            details: details.unwrap_or_else(|| "".into()),
            identity: identity.unwrap_or_else(|| "".into()),
            moniker,
            security_contact: security_contact.unwrap_or_else(|| "".into()),
            website: website.unwrap_or_else(|| "".into()),
        }
    }
    pub fn create_edit(
        details: Option<String>,
        identity: Option<String>,
        moniker: Option<String>,
        security_contact: Option<String>,
        website: Option<String>,
    ) -> ValidatorDescription {
        ValidatorDescription {
            details: details.unwrap_or_else(|| "[do-not-modify]".into()),
            identity: identity.unwrap_or_else(|| "[do-not-modify]".into()),
            moniker: moniker.unwrap_or_else(|| "[do-not-modify]".into()),
            security_contact: security_contact.unwrap_or_else(|| "[do-not-modify]".into()),
            website: website.unwrap_or_else(|| "[do-not-modify]".into()),
        }
    }
}
/// Description of the validator commission structure
#[derive(Deserialize, Serialize, Debug)]
pub struct ValidatorCommission {
    #[serde(with = "terra_decimal_format")]
    pub max_change_rate: Decimal,
    #[serde(with = "terra_decimal_format")]
    pub max_rate: Decimal,
    #[serde(with = "terra_decimal_format")]
    pub rate: Decimal,
}
/// create validator message
#[derive(Serialize, Debug)]
pub struct MsgCreateValidator {
    pub commission: ValidatorCommission,
    pub delegator_address: String,
    pub description: ValidatorDescription,
    #[serde(with = "terra_decimal_format")]
    pub min_self_delegation: Decimal,
    pub pubkey: String,
    pub value: Coin,
    pub validator_address: String,
}
impl MsgInternal for MsgCreateValidator {}
impl MsgCreateValidator {
    pub fn create(
        description: ValidatorDescription,
        commission: ValidatorCommission,
        min_self_delegation: Decimal,
        delegator_address: String,
        validator_address: String,
        pubkey: String,
        value: Coin,
    ) -> Message {
        let internal = MsgCreateValidator {
            commission,
            delegator_address,
            description,
            min_self_delegation,
            pubkey,
            value,
            validator_address,
        };
        Message {
            s_type: "staking/MsgCreateValidator".into(),
            value: Box::new(internal),
        }
    }
}
/// edit validator message
#[derive(Serialize, Debug)]
pub struct MsgEditValidator {
    pub address: String,
    #[serde(with = "terra_opt_decimal_format")]
    pub commission_rate: Option<Decimal>,
    pub description: ValidatorDescription,
    #[serde(with = "terra_opt_decimal_format")]
    pub min_self_delegation: Option<Decimal>,
}
impl MsgInternal for MsgEditValidator {}
impl MsgEditValidator {
    pub fn create(
        description: ValidatorDescription,
        address: String,
        commission_rate: Option<Decimal>,
        min_self_delegation: Option<Decimal>,
    ) -> Message {
        let internal = MsgEditValidator {
            address,
            commission_rate,
            description,
            min_self_delegation,
        };
        Message {
            s_type: "staking/MsgEditValidator".into(),
            value: Box::new(internal),
        }
    }
}

/// edit undelegate message
#[derive(Serialize, Debug)]
pub struct MsgUndelegate {
    pub amount: Coin,
    pub delegator_address: String,
    pub validator_address: String,
}
impl MsgInternal for MsgUndelegate {}
impl MsgUndelegate {
    pub fn create(delegator_address: String, validator_address: String, amount: Coin) -> Message {
        let internal = MsgUndelegate {
            amount,
            delegator_address,
            validator_address,
        };
        Message {
            s_type: "staking/MsgUndelegate".into(),
            value: Box::new(internal),
        }
    }
}
/// edit undelegate message
#[derive(Serialize, Debug)]
pub struct MsgDelegate {
    pub amount: Coin,
    pub delegator_address: String,
    pub validator_address: String,
}
impl MsgInternal for MsgDelegate {}
impl MsgDelegate {
    pub fn create(delegator_address: String, validator_address: String, amount: Coin) -> Message {
        let internal = MsgDelegate {
            amount,
            delegator_address,
            validator_address,
        };
        Message {
            s_type: "staking/MsgDelegate".into(),
            value: Box::new(internal),
        }
    }
}
/// edit undelegate message
#[derive(Serialize, Debug)]
pub struct MsgBeginRedelegate {
    pub amount: Coin,
    pub delegator_address: String,
    pub validator_dst_address: String,
    pub validator_src_address: String,
}
impl MsgInternal for MsgBeginRedelegate {}
impl MsgBeginRedelegate {
    pub fn create(
        delegator_address: String,
        validator_dst_address: String,
        validator_src_address: String,
        amount: Coin,
    ) -> Message {
        let internal = MsgBeginRedelegate {
            amount,
            delegator_address,
            validator_src_address,
            validator_dst_address,
        };
        Message {
            s_type: "staking/MsgBeginRedelegate".into(),
            value: Box::new(internal),
        }
    }
}