catbuffer_rust/
mosaic_definition_transaction_builder.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 super::amount_dto::*;
23use super::block_duration_dto::*;
24use super::entity_type_dto::*;
25use super::generator_utils::*;
26use super::key_dto::*;
27use super::mosaic_definition_transaction_body_builder::*;
28use super::mosaic_flags_dto::*;
29use super::mosaic_id_dto::*;
30use super::mosaic_nonce_dto::*;
31use super::network_type_dto::*;
32use super::signature_dto::*;
33use super::timestamp_dto::*;
34use super::transaction_builder::*;
35
36/// Binary layout for a non-embedded mosaic definition transaction.
37#[derive(Debug, Clone)]
38pub struct MosaicDefinitionTransactionBuilder {
39    /// Transaction.
40    pub super_object: TransactionBuilder,
41    /// Mosaic definition transaction body.
42    pub body: MosaicDefinitionTransactionBodyBuilder,
43}
44
45impl MosaicDefinitionTransactionBuilder {
46    const VERSION: u8 = 1;
47    const ENTITY_TYPE: u16 = 0x414d;
48
49
50    /// Creates an instance of MosaicDefinitionTransactionBuilder from binary payload.
51    /// payload: Byte payload to use to serialize the object.
52    /// # Returns
53    /// A MosaicDefinitionTransactionBuilder.
54    pub fn from_binary(payload: &[u8]) -> Self {
55        let mut _bytes = payload.to_vec();
56        let super_object = TransactionBuilder::from_binary(&_bytes);
57        assert_eq!(Self::VERSION, super_object.version, "Invalid entity version ({})", super_object.version);
58        assert_eq!(Self::ENTITY_TYPE, super_object._type.get_value(), "Invalid entity type ({:?})", super_object._type);
59        let mut _bytes = _bytes[super_object.get_size()..].to_vec();
60        let mosaic_definition_transaction_body = MosaicDefinitionTransactionBodyBuilder::from_binary(&_bytes); // kind:CUSTOM1
61        _bytes = _bytes[mosaic_definition_transaction_body.get_size()..].to_vec();
62        // create object and call.
63        MosaicDefinitionTransactionBuilder { super_object, body: mosaic_definition_transaction_body }  // Transaction
64    }
65
66
67    pub fn get_id(&self) -> MosaicIdDto {
68        self.body.id.clone()
69    }
70    pub fn set_id(&mut self, id: MosaicIdDto) {
71        self.body.id = id;   // MARKER1 AttributeKind.CUSTOM
72    }
73
74
75    pub fn get_duration(&self) -> BlockDurationDto {
76        self.body.duration.clone()
77    }
78    pub fn set_duration(&mut self, duration: BlockDurationDto) {
79        self.body.duration = duration;   // MARKER1 AttributeKind.CUSTOM
80    }
81
82
83    pub fn get_nonce(&self) -> MosaicNonceDto {
84        self.body.nonce.clone()
85    }
86    pub fn set_nonce(&mut self, nonce: MosaicNonceDto) {
87        self.body.nonce = nonce;   // MARKER1 AttributeKind.CUSTOM
88    }
89
90
91    pub fn get_flags(&self) -> Vec<MosaicFlagsDto> {
92        self.body.flags.clone()
93    }
94    pub fn set_flags(&mut self, flags: Vec<MosaicFlagsDto>) {
95        self.body.flags = flags;   // MARKER1 AttributeKind.FLAGS
96    }
97
98
99    pub fn get_divisibility(&self) -> u8 {
100        self.body.divisibility.clone()
101    }
102    pub fn set_divisibility(&mut self, divisibility: u8) {
103        self.body.divisibility = divisibility;   // MARKER1 AttributeKind.SIMPLE
104    }
105
106    /// Gets the size of the type.
107    ///
108    /// Returns:
109    /// A size in bytes.
110    pub fn get_size(&self) -> usize {
111        let mut size = self.super_object.get_size();
112        size += self.body.get_size();
113        size
114    }
115
116    /// Serializes self to bytes.
117    ///
118    /// # Returns
119    /// A Serialized bytes.
120    pub fn serializer(&self) -> Vec<u8> {
121        let mut buf: Vec<u8> = vec![];
122        buf.append(&mut (self.get_size() as u32).to_le_bytes().to_vec());
123        buf.append(&mut self.super_object.serializer());
124        buf.append(&mut self.body.serializer()); // kind:CUSTOM TransactionBody
125        buf
126    }
127}
128