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