catbuffer_rust/
mosaic_global_restriction_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::entity_type_dto::*;
24use super::generator_utils::*;
25use super::key_dto::*;
26use super::mosaic_global_restriction_transaction_body_builder::*;
27use super::mosaic_restriction_type_dto::*;
28use super::network_type_dto::*;
29use super::signature_dto::*;
30use super::timestamp_dto::*;
31use super::transaction_builder::*;
32use super::unresolved_mosaic_id_dto::*;
33
34/// Binary layout for a non-embedded mosaic global restriction transaction.
35#[derive(Debug, Clone)]
36pub struct MosaicGlobalRestrictionTransactionBuilder {
37    /// Transaction.
38    pub super_object: TransactionBuilder,
39    /// Mosaic global restriction transaction body.
40    pub body: MosaicGlobalRestrictionTransactionBodyBuilder,
41}
42
43impl MosaicGlobalRestrictionTransactionBuilder {
44    const VERSION: u8 = 1;
45    const ENTITY_TYPE: u16 = 0x4151;
46
47
48    /// Creates an instance of MosaicGlobalRestrictionTransactionBuilder from binary payload.
49    /// payload: Byte payload to use to serialize the object.
50    /// # Returns
51    /// A MosaicGlobalRestrictionTransactionBuilder.
52    pub fn from_binary(payload: &[u8]) -> Self {
53        let mut _bytes = payload.to_vec();
54        let super_object = TransactionBuilder::from_binary(&_bytes);
55        assert_eq!(Self::VERSION, super_object.version, "Invalid entity version ({})", super_object.version);
56        assert_eq!(Self::ENTITY_TYPE, super_object._type.get_value(), "Invalid entity type ({:?})", super_object._type);
57        let mut _bytes = _bytes[super_object.get_size()..].to_vec();
58        let mosaic_global_restriction_transaction_body = MosaicGlobalRestrictionTransactionBodyBuilder::from_binary(&_bytes); // kind:CUSTOM1
59        _bytes = _bytes[mosaic_global_restriction_transaction_body.get_size()..].to_vec();
60        // create object and call.
61        MosaicGlobalRestrictionTransactionBuilder { super_object, body: mosaic_global_restriction_transaction_body }  // Transaction
62    }
63
64
65    pub fn get_mosaic_id(&self) -> UnresolvedMosaicIdDto {
66        self.body.mosaic_id.clone()
67    }
68    pub fn set_mosaic_id(&mut self, mosaic_id: UnresolvedMosaicIdDto) {
69        self.body.mosaic_id = mosaic_id;   // MARKER1 AttributeKind.CUSTOM
70    }
71
72
73    pub fn get_reference_mosaic_id(&self) -> UnresolvedMosaicIdDto {
74        self.body.reference_mosaic_id.clone()
75    }
76    pub fn set_reference_mosaic_id(&mut self, reference_mosaic_id: UnresolvedMosaicIdDto) {
77        self.body.reference_mosaic_id = reference_mosaic_id;   // MARKER1 AttributeKind.CUSTOM
78    }
79
80
81    pub fn get_restriction_key(&self) -> u64 {
82        self.body.restriction_key.clone()
83    }
84    pub fn set_restriction_key(&mut self, restriction_key: u64) {
85        self.body.restriction_key = restriction_key;   // MARKER1 AttributeKind.SIMPLE
86    }
87
88
89    pub fn get_previous_restriction_value(&self) -> u64 {
90        self.body.previous_restriction_value.clone()
91    }
92    pub fn set_previous_restriction_value(&mut self, previous_restriction_value: u64) {
93        self.body.previous_restriction_value = previous_restriction_value;   // MARKER1 AttributeKind.SIMPLE
94    }
95
96
97    pub fn get_new_restriction_value(&self) -> u64 {
98        self.body.new_restriction_value.clone()
99    }
100    pub fn set_new_restriction_value(&mut self, new_restriction_value: u64) {
101        self.body.new_restriction_value = new_restriction_value;   // MARKER1 AttributeKind.SIMPLE
102    }
103
104
105    pub fn get_previous_restriction_type(&self) -> MosaicRestrictionTypeDto {
106        self.body.previous_restriction_type.clone()
107    }
108    pub fn set_previous_restriction_type(&mut self, previous_restriction_type: MosaicRestrictionTypeDto) {
109        self.body.previous_restriction_type = previous_restriction_type;   // MARKER1 AttributeKind.CUSTOM
110    }
111
112
113    pub fn get_new_restriction_type(&self) -> MosaicRestrictionTypeDto {
114        self.body.new_restriction_type.clone()
115    }
116    pub fn set_new_restriction_type(&mut self, new_restriction_type: MosaicRestrictionTypeDto) {
117        self.body.new_restriction_type = new_restriction_type;   // MARKER1 AttributeKind.CUSTOM
118    }
119
120    /// Gets the size of the type.
121    ///
122    /// Returns:
123    /// A size in bytes.
124    pub fn get_size(&self) -> usize {
125        let mut size = self.super_object.get_size();
126        size += self.body.get_size();
127        size
128    }
129
130    /// Serializes self to bytes.
131    ///
132    /// # Returns
133    /// A Serialized bytes.
134    pub fn serializer(&self) -> Vec<u8> {
135        let mut buf: Vec<u8> = vec![];
136        buf.append(&mut (self.get_size() as u32).to_le_bytes().to_vec());
137        buf.append(&mut self.super_object.serializer());
138        buf.append(&mut self.body.serializer()); // kind:CUSTOM TransactionBody
139        buf
140    }
141}
142