catbuffer_rust/
embedded_account_operation_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::account_operation_restriction_transaction_body_builder::*;
23use super::account_restriction_flags_dto::*;
24use super::embedded_transaction_builder::*;
25use super::embedded_transaction_helper::*;
26use super::entity_type_dto::*;
27use super::entity_type_dto::*;
28use super::generator_utils::*;
29use super::key_dto::*;
30use super::network_type_dto::*;
31
32/// Binary layout for an embedded account operation restriction transaction.
33#[derive(Debug, Clone)]
34pub struct EmbeddedAccountOperationRestrictionTransactionBuilder {
35    /// Embedded transaction.
36    pub super_object: EmbeddedTransactionBuilder,
37    /// Account operation restriction transaction body.
38    pub body: AccountOperationRestrictionTransactionBodyBuilder,
39}
40
41impl EmbeddedAccountOperationRestrictionTransactionBuilder {
42    const VERSION: u8 = 1;
43    const ENTITY_TYPE: u16 = 0x4350;
44
45
46    /// Creates an instance of EmbeddedAccountOperationRestrictionTransactionBuilder from binary payload.
47    /// payload: Byte payload to use to serialize the object.
48    /// # Returns
49    /// A EmbeddedAccountOperationRestrictionTransactionBuilder.
50    pub fn from_binary(payload: &[u8]) -> Self {
51        let mut _bytes = payload.to_vec();
52        let super_object = EmbeddedTransactionBuilder::from_binary(&_bytes);
53        assert_eq!(Self::VERSION, super_object.version, "Invalid entity version ({})", super_object.version);
54        assert_eq!(Self::ENTITY_TYPE, super_object._type.get_value(), "Invalid entity type ({:?})", super_object._type);
55        let mut _bytes = _bytes[super_object.get_size()..].to_vec();
56        let account_operation_restriction_transaction_body = AccountOperationRestrictionTransactionBodyBuilder::from_binary(&_bytes); // kind:CUSTOM1
57        _bytes = _bytes[account_operation_restriction_transaction_body.get_size()..].to_vec();
58        // create object and call.
59        EmbeddedAccountOperationRestrictionTransactionBuilder { super_object, body: account_operation_restriction_transaction_body }  // Transaction
60        // nothing needed to copy into EmbeddedTransaction
61    }
62
63
64    pub fn get_restriction_flags(&self) -> Vec<AccountRestrictionFlagsDto> {
65        self.body.restriction_flags.clone()
66    }
67    pub fn set_restriction_flags(&mut self, restriction_flags: Vec<AccountRestrictionFlagsDto>) {
68        self.body.restriction_flags = restriction_flags;   // MARKER1 AttributeKind.FLAGS
69    }
70
71
72    pub fn get_restriction_additions(&self) -> Vec<EntityTypeDto> {
73        self.body.restriction_additions.clone()
74    }
75
76    pub fn get_restriction_deletions(&self) -> Vec<EntityTypeDto> {
77        self.body.restriction_deletions.clone()
78    }
79    /// Gets the size of the type.
80    ///
81    /// Returns:
82    /// A size in bytes.
83    pub fn get_size(&self) -> usize {
84        let mut size = self.super_object.get_size();
85        size += self.body.get_size();
86        size
87    }
88
89    /// Serializes self to bytes.
90    ///
91    /// # Returns
92    /// A Serialized bytes.
93    pub fn serializer(&self) -> Vec<u8> {
94        let mut buf: Vec<u8> = vec![];
95        buf.append(&mut (self.get_size() as u32).to_le_bytes().to_vec());
96        buf.append(&mut self.super_object.serializer());
97        buf.append(&mut self.body.serializer()); // kind:CUSTOM TransactionBody
98        buf
99    }
100}
101
102impl EmbeddedTransactionHelper for EmbeddedAccountOperationRestrictionTransactionBuilder {
103    fn box_clone(&self) -> Box<dyn EmbeddedTransactionHelper> {
104        Box::new((*self).clone())
105    }
106
107    fn get_size(&self) -> usize {
108        self.get_size()
109    }
110
111    fn serializer(&self) -> Vec<u8> {
112        self.serializer()
113    }
114}
115