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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
use std::collections::HashMap;

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RequestError {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub errors: Option<String>,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Meta {
    pub limit: Option<u32>,
    pub offset: Option<u32>,
    pub count: Option<u64>,
    pub from_timestamp: Option<u64>,
    pub to_timestamp: Option<u64>,
    pub last_block: Option<u64>,
    pub last_block_slot: Option<u64>,
    pub current_slot: Option<u64>,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Response<T> {
    pub data: T,
    pub meta: Meta,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ParamErrorMessage {
    pub code: String,
    pub message: String,
    pub description: String,
    pub path: Vec<HashMap<String, String>>,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ParamError {
    pub code: String,
    pub name: String,
    pub message: String,
    pub errors: Vec<HashMap<String, String>>,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ParamErrorResponse {
    pub message: String,
    pub errors: Vec<HashMap<String, String>>,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
pub struct TransactionsInPool {
    pub confirmed: u64,
    pub unconfirmed: u16,
    pub unprocessed: u16,
    pub unsigned: u16,
    pub total: u64,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Account {
    pub address: String,
    pub public_key: String,
    pub balance: Option<String>,
    pub unconfirmed_balance: Option<String>,
    pub second_public_key: Option<String>,
    pub min: Option<u8>,
    pub lifetime: Option<u32>,
    pub delegate: Option<DelegateWithAccount>,
    pub members: Option<Vec<Member>>,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Member {
    pub address: String,
    pub public_key: String,
    pub second_public_key: String,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Block {
    pub id: String,
    pub version: u64,
    pub timestamp: u64,
    pub height: u64,
    pub number_of_transactions: u64,
    pub total_amount: String,
    pub total_fee: String,
    pub reward: String,
    pub payload_length: u64,
    pub payload_hash: String,
    pub generator_public_key: String,
    pub block_signature: String,
    pub confirmations: u64,
    pub total_forged: String,
    pub generator_address: String,
    pub previous_block_id: String,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(default)]
#[serde(rename_all = "camelCase")]
pub struct Transaction {
    pub id: String,
    pub height: u64,
    pub block_id: String,
    pub r#type: u8,
    pub timestamp: u64,
    pub sender_public_key: String,
    pub recipient_public_key: String,
    pub sender_id: String,
    pub recipient_id: String,
    pub amount: String,
    pub fee: String,
    pub signature: String,
    pub signatures: Option<Vec<Signature>>,
    #[serde(skip_serializing_if = "Asset::is_none")]
    pub asset: Asset,
    pub confirmations: u64,
    pub sender_second_public_key: Option<String>,
    pub sign_signature: Option<String>,
    pub relays: Option<u16>,
    pub ready: Option<bool>,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Signature {
    pub transaction_id: String,
    pub public_key: String,
    pub signature: String,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Dapp {
    pub transaction_id: String,
    pub icon: String,
    pub category: u8,
    pub r#type: u8,
    pub link: String,
    pub tags: String,
    pub description: String,
    pub name: String,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Peer {
    pub ip: String,
    pub http_port: Option<u64>,
    pub ws_port: u64,
    pub os: Option<String>,
    pub version: String,
    pub protocol_version: Option<String>,
    pub state: Option<u64>,
    pub height: Option<u64>,
    pub broadhash: Option<String>,
    pub nonce: Option<String>,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeConstants {
    pub epoch: String,
    pub milestone: String,
    pub build: String,
    pub commit: String,
    pub version: String,
    pub protocol_version: String,
    pub nethash: String,
    pub supply: String,
    pub reward: String,
    pub nonce: String,
    pub fees: Fees,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Fees {
    pub send: String,
    pub vote: String,
    pub second_signature: String,
    pub delegate: String,
    pub multisignature: String,
    pub dapp_registration: String,
    pub dapp_withdrawal: String,
    pub dapp_deposit: String,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeStatus {
    pub broadhash: String,
    pub consensus: u64,
    pub current_time: u64,
    pub seconds_since_epoch: u64,
    pub height: u64,
    pub loaded: bool,
    pub network_height: i64,
    pub syncing: bool,
    pub transactions: TransactionsInPool,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ForgingStats {
    pub fees: String,
    pub rewards: String,
    pub forged: String,
    pub count: String,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ForgingStatus {
    pub forging: bool,
    pub public_key: String,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Forger {
    pub username: String,
    pub address: String,
    pub public_key: String,
    pub next_slot: String,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DelegateWithAccount {
    pub username: String,
    pub vote: String,
    pub rewards: String,
    pub produced_blocks: u32,
    pub missed_blocks: u32,
    pub rank: u16,
    pub productivity: f32,
    pub approval: f32,
    pub account: Option<HashMap<String, String>>,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DelegateWithVoters {
    pub address: String,
    pub public_key: String,
    pub balance: String,
    pub votes: u32,
    pub username: String,
    pub voters: Vec<Voter>,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DelegateWithVotes {
    pub address: String,
    pub balance: String,
    pub username: String,
    pub public_key: String,
    pub votes_used: u32,
    pub votes_available: u32,
    pub votes: Vec<Vote>,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Voter {
    pub address: String,
    pub public_key: String,
    pub balance: String,
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Vote {
    pub address: String,
    pub public_key: String,
    pub balance: String,
    pub username: String,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum Asset {
    #[serde(skip)]
    None,
    Data(String),
    Signature {
        #[serde(rename = "publicKey")]
        public_key: String,
    },
    Delegate {
        #[serde(rename = "publicKey")]
        public_key: String,
        username: String,
        address: String,
    },
    Votes(Vec<String>),
    Multisignature {
        min: u8,
        lifetime: u64,
        keysgroup: Vec<String>,
    },
    Dapp {
        icon: String,
        link: String,
        name: String,
        tags: String,
        r#type: u8,
        category: u8,
        description: String,
    },
}

impl Asset {
    pub fn is_none(&self) -> bool {
        match *self {
            Asset::None => true,
            _ => false,
        }
    }
}

impl Default for Asset {
    fn default() -> Self {
        Asset::None
    }
}