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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
//! # Basic Transactions types for Blockchain functions and getters
//!
//! Most common representations for Blockchain transactions type,
//! traits, and informations getters.

use std::collections::HashMap;

use serde::{Deserialize, Serialize};

pub const FUNCTION_RETURN_SUCCESS: i64 = 0;
pub const FUNCTION_CONSTRUCTOR_FAIL_TO_SAVE: i64 = -39;
pub const FUNCTION_ERROR: i64 = -1000;

pub type Cid = String;
pub type NetworkType = u8;
pub type EntityType = u16;
pub type EntityVersion = u32;
pub type Amount = i64;
pub type Deadline = i64;
pub type Height = i64;
pub type Hash = String;
pub type Address = String;
pub type NamespaceId = u64;
pub type AliasActionType = u8;
pub type MosaicId = u64;
pub type PubKey = String;
pub type AssetId = u64;
pub type Duration = i64;
pub type MosaicSupplyType = u8;
pub type MetadataModificationType = u8;
pub type HashType = u8;
pub type Message = String;
pub type OfferType = u8;
pub type TransactionID = String;
pub type TransactionType = u8;
pub type Signature = String;

#[derive(Debug, Deserialize, Serialize)]
pub struct Drive {
	pub drive: Cid,
	pub owner: PubKey,
	pub root: Cid,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct SuperContract {
	pub id: Cid,
	pub drive: Drive,
	pub file: Cid,
	pub vmversion: u64,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct AbstractTransaction {
	pub height: Height,
	pub index: u32,
	pub transaction_hash: Option<Hash>,
	pub merkle_component_hash: Option<Hash>,
	pub aggregate_hash: Option<Hash>,
	pub unique_aggregate_hash: Option<Hash>,
	pub aggregate_id: Vec<u8>,

	pub network_type: NetworkType,
	pub deadline: Option<Deadline>,
	pub entity_type: EntityType,
	pub version: EntityVersion,
	pub max_fee: Amount,
	pub signature: Vec<u8>,
	pub signer: Option<PublicAccount>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct MosaicDefinition {
	pub nonce: u32,
	pub owner_public_key: String,
	pub mosaic_props: Option<MosaicProperties>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct MosaicProperties {
	pub supply_mutable: bool,
	pub transferable: bool,
	pub divisibility: u8,
	pub optional_properties: Vec<MosaicProperty>,
}

pub type MosaicPropertyId = u8;

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct MosaicProperty {
	pub id: MosaicPropertyId,
	pub value: i64,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct AddressAlias {
	pub address: Option<Address>,
	pub namespace_id: Option<NamespaceId>,
	pub action_type: AliasActionType,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct MosaicAlias {
	pub mosaic_id: Option<MosaicId>,
	pub namespace_id: Option<NamespaceId>,
	pub action_type: AliasActionType,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct AddExchangeOffer {
	pub add_offers: Option<Vec<AddOffer>>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ExchangeConfirmation {
	#[serde(rename = "Type")]
	pub offer_type: OfferType,
	pub mosaic: Option<Mosaic>,
	pub cost: Amount,
	pub owner: Option<PublicAccount>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct AddOffer {
	#[serde(rename = "Type")]
	pub offer_type: OfferType,
	pub mosaic: Option<Mosaic>,
	pub cost: Amount,
	pub duration: Duration,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ExchangeOffer {
	pub offer: Option<Vec<ExchangeConfirmation>>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Transfer {
	pub pub_key: PubKey,
	pub asset_id: AssetId,
	pub amount: i64,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct RemoveOffer {
	#[serde(rename = "Type")]
	pub offer_type: OfferType,
	pub asset_id: AssetId,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct RemoveExchangeOffer {
	pub remove_offers: Option<Vec<RemoveOffer>>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct MosaicSupplyChange {
	pub asset_id: AssetId,
	pub supply_type: MosaicSupplyType,
	pub delta: Duration,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct RegisterRootNamespace {
	pub namespace_name: String,
	pub duration: Duration,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct RegisterSubNamespace {
	pub namespace_name: String,
	pub parent_id: Option<NamespaceId>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct Mosaic {
	pub asset_id: AssetId,
	pub amount: Amount,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Secret {
	pub hash: Hash,
	pub hash_type: HashType,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct SecretLock {
	pub mosaic: Option<Mosaic>,
	pub duration: Duration,
	pub secret: Option<Secret>,
	pub recipient: Option<Address>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Proof {
	pub data: Vec<u8>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct SecretProof {
	pub hash_type: HashType,
	pub proof: Option<Proof>,
	pub recipient: Option<Address>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct TransferWithNamespace {
	pub recipient: Option<NamespaceId>,
	pub mosaics: Option<Vec<Mosaic>>,
	pub message: Message,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ModifyMetadataAddress {
	pub address: Option<Address>,
	pub modifications: Option<Vec<MetadataModification>>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ModifyMetadataMosaic {
	pub mosaic_id: Option<MosaicId>,
	pub modifications: Option<Vec<MetadataModification>>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct MetadataModification {
	#[serde(rename = "Type")]
	pub modification_type: MetadataModificationType,
	pub key: String,
	pub value: String,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct ModifyMetadataNamespace {
	pub namespace_id: Option<NamespaceId>,
	pub modifications: Option<Vec<MetadataModification>>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct OfferInfo {
	#[serde(rename = "Type")]
	pub offer_type: OfferType,
	pub owner: Option<PublicAccount>,
	pub mosaic: Option<Mosaic>,
	pub price_numerator: Amount,
	pub price_denominator: Amount,
	pub deadline: Height,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct UserExchangeInfo {
	pub owner: Option<PublicAccount>,
	pub offers: Option<HashMap<OfferType, HashMap<MosaicId, Option<OfferInfo>>>>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetAccountExchangeInfo {
	pub pub_key: Option<PubKey>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetExchangeOfferByAssetId {
	pub asset_id: AssetId,
	pub offer_type: OfferType,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct PublicAccount {
	pub public_key: String,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct MosaicInfo {
	pub mosaic_id: Option<MosaicId>,
	pub supply: Amount,
	pub height: Height,
	pub owner: Option<PublicAccount>,
	pub revision: u32,
	pub properties: Option<MosaicProperties>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetMosaicInfo {
	pub mosaic_id: Option<MosaicId>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetMosaicInfos {
	pub msc_ids: Option<Vec<MosaicId>>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct MosaicName {
	pub mosaic_id: Option<MosaicId>,
	pub names: Option<Vec<String>>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetMosaicsNames {
	pub msc_ids: Option<Vec<MosaicId>>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetTransaction {
	pub id: TransactionID,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct GetTransactions {
	pub ids: Vec<TransactionID>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct TransactionStatus {
	pub deadline: Option<Deadline>,
	pub group: String,
	pub status: String,
	pub hash: Option<Hash>,
	pub height: Height,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetTransactionStatus {
	pub id: TransactionID,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetTransactionStatuses {
	pub ids: Vec<TransactionID>,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetTransactionEffectiveFee {
	pub id: TransactionID,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetMosaicID {
	pub nonce: u32,
	pub owner_public_key: String,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct GetInitiatorPubKey {
	pub public_key: String,
}

/// # Transactions
/// **SignedTransaction** is common interface for transactions data
/// from Blockchain.
pub trait SignedTransaction {
	fn id(&self) -> TransactionID;
	fn transaction_type(&self) -> TransactionType;
	fn signer(&self) -> PubKey;
	fn signature(&self) -> Signature;
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Action {
	pub hash: Hash,
	pub action_type: i64,
	pub size: u64,
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct DriveFsTransaction {
	pub id: TransactionID,
	pub transaction_type: TransactionType,
	pub signer: PubKey,
	pub signature: Signature,
	pub drive_id: Hash,
	pub add_actions: Option<Vec<Action>>,
	pub remove_actions: Option<Vec<Action>>,
}

impl DriveFsTransaction {
	pub fn drive_id(&self) -> Hash {
		self.drive_id.clone()
	}

	pub fn add_actions(&self) -> Option<Vec<Action>> {
		self.add_actions.clone()
	}

	pub fn remove_actions(&self) -> Option<Vec<Action>> {
		self.remove_actions.clone()
	}
}

impl SignedTransaction for DriveFsTransaction {
	fn id(&self) -> TransactionID {
		self.id.clone()
	}

	fn transaction_type(&self) -> TransactionType {
		self.transaction_type
	}

	fn signer(&self) -> PubKey {
		self.signer.clone()
	}

	fn signature(&self) -> Signature {
		self.signature.clone()
	}
}