catbuffer_rust/
receipt_type_dto.rs

1/*
2 * // Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp.
3 * // Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie.
4 * // All rights reserved.
5 * //
6 * // This file is part of Catapult.
7 * //
8 * // Catapult is free software: you can redistribute it and/or modify
9 * // it under the terms of the GNU Lesser General Public License as published by
10 * // the Free Software Foundation, either version 3 of the License, or
11 * // (at your option) any later version.
12 * //
13 * // Catapult is distributed in the hope that it will be useful,
14 * // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * // GNU Lesser General Public License for more details.
17 * //
18 * // You should have received a copy of the GNU Lesser General Public License
19 * // along with Catapult. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22use num_derive::{FromPrimitive, ToPrimitive};
23use num_traits::{FromPrimitive, ToPrimitive};
24use strum_macros::EnumIter;
25
26use super::generator_utils::*;
27
28/// Enumeration of receipt types.
29#[allow(non_camel_case_types)]
30#[repr(u16)]
31#[derive(Debug, Clone, Copy, PartialEq, FromPrimitive, ToPrimitive, EnumIter)]
32pub enum ReceiptTypeDto {
33    /// Reserved receipt type.
34    RESERVED = 0,
35
36    /// Mosaic rental fee receipt type.
37    MOSAIC_RENTAL_FEE = 4685,
38
39    /// Namespace rental fee receipt type.
40    NAMESPACE_RENTAL_FEE = 4942,
41
42    /// Harvest fee receipt type.
43    HARVEST_FEE = 8515,
44
45    /// Lock hash completed receipt type.
46    LOCK_HASH_COMPLETED = 8776,
47
48    /// Lock hash expired receipt type.
49    LOCK_HASH_EXPIRED = 9032,
50
51    /// Lock secret completed receipt type.
52    LOCK_SECRET_COMPLETED = 8786,
53
54    /// Lock secret expired receipt type.
55    LOCK_SECRET_EXPIRED = 9042,
56
57    /// Lock hash created receipt type.
58    LOCK_HASH_CREATED = 12616,
59
60    /// Lock secret created receipt type.
61    LOCK_SECRET_CREATED = 12626,
62
63    /// Mosaic expired receipt type.
64    MOSAIC_EXPIRED = 16717,
65
66    /// Namespace expired receipt type.
67    NAMESPACE_EXPIRED = 16718,
68
69    /// Namespace deleted receipt type.
70    NAMESPACE_DELETED = 16974,
71
72    /// Inflation receipt type.
73    INFLATION = 20803,
74
75    /// Transaction group receipt type.
76    TRANSACTION_GROUP = 57667,
77
78    /// Address alias resolution receipt type.
79    ADDRESS_ALIAS_RESOLUTION = 61763,
80
81    /// Mosaic alias resolution receipt type.
82    MOSAIC_ALIAS_RESOLUTION = 62019,
83
84}
85
86impl ReceiptTypeDto {
87    pub const LENGTH: usize = std::mem::size_of::<Self>();
88
89    /// Gets the size of the type.
90    ///
91    /// # Returns
92    ///
93    /// A usize.
94    pub fn get_size(&self) -> usize {
95        Self::LENGTH
96    }
97
98    /// Gets the value of the enum.
99    ///
100    /// # Returns
101    ///
102    /// A u16
103    pub fn get_value(&self) -> u16 {
104        self.to_u16().unwrap()
105    }
106
107
108    /// Creates an `ReceiptTypeDto` from a slice.
109    ///
110    /// # Returns
111    ///
112    /// A `ReceiptTypeDto`.
113    pub fn from_binary(src: &[u8]) -> Self {
114        // assert_eq!(src.len(), Self::LENGTH);
115        let buf = fixed_bytes::<{ Self::LENGTH }>(src);
116        Self::from_u16(u16::from_le_bytes(buf)).unwrap()
117    }
118
119    /// Serializes an type to bytes.
120    ///
121    /// # Returns
122    ///
123    /// A Serialized bytes.
124    pub fn serializer(&self) -> Vec<u8> {
125        self.get_value().to_le_bytes().to_vec()
126    }
127}