catbuffer_rust/balance_change_receipt_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::address_dto::*;
23use super::generator_utils::*;
24use super::mosaic_builder::*;
25use super::receipt_builder::*;
26use super::receipt_type_dto::*;
27
28/// Binary layout for a balance change receipt.
29#[derive(Debug, Clone)]
30pub struct BalanceChangeReceiptBuilder {
31 /// Receipt.
32 super_object: ReceiptBuilder,
33 /// Mosaic.
34 mosaic: MosaicBuilder,
35 /// Account address.
36 target_address: AddressDto,
37}
38
39
40impl BalanceChangeReceiptBuilder {
41 /// Creates an instance of BalanceChangeReceiptBuilder from binary payload.
42 /// payload: Byte payload to use to serialize the object.
43 /// # Returns
44 /// A BalanceChangeReceiptBuilder.
45 pub fn from_binary(_bytes: &[u8]) -> Self {
46 let super_object = ReceiptBuilder::from_binary(_bytes);
47 let mut _bytes = _bytes[super_object.get_size()..].to_vec();
48 let mosaic = MosaicBuilder::from_binary(&_bytes); // kind:CUSTOM1
49 let mut _bytes = _bytes[mosaic.get_size()..].to_vec();
50 let target_address = AddressDto::from_binary(&_bytes); // kind:CUSTOM1
51 let mut _bytes = _bytes[target_address.get_size()..].to_vec();
52 BalanceChangeReceiptBuilder { super_object, mosaic, target_address }
53 }
54
55 /// Gets mosaic.
56 ///
57 /// # Returns
58 /// A Mosaic.
59 pub fn get_mosaic(&self) -> MosaicBuilder {
60 self.mosaic.clone()
61 }
62
63 /// Gets account address.
64 ///
65 /// # Returns
66 /// A Account address.
67 pub fn get_target_address(&self) -> AddressDto {
68 self.target_address.clone()
69 }
70
71 /// Gets the size of the type.
72 ///
73 /// Returns:
74 /// A size in bytes.
75 pub fn get_size(&self) -> usize {
76 let mut size = self.super_object.get_size();
77 size += self.mosaic.get_size(); // mosaic;
78 size += self.target_address.get_size(); // target_address;
79 size
80 }
81
82 /// Serializes self to bytes.
83 ///
84 /// # Returns
85 /// A Serialized bytes.
86 pub fn serializer(&self) -> Vec<u8> {
87 let mut buf: Vec<u8> = vec![];
88 buf.append(&mut self.super_object.serializer());
89 buf.append(&mut self.mosaic.serializer()); // kind:CUSTOM
90 buf.append(&mut self.target_address.serializer()); // kind:CUSTOM
91 buf
92 }
93}
94