catbuffer_rust/
balance_transfer_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 transfer receipt.
29#[derive(Debug, Clone)]
30pub struct BalanceTransferReceiptBuilder {
31    /// Receipt.
32    super_object: ReceiptBuilder,
33    /// Mosaic.
34    mosaic: MosaicBuilder,
35    /// Mosaic sender address.
36    sender_address: AddressDto,
37    /// Mosaic recipient address.
38    recipient_address: AddressDto,
39}
40
41
42impl BalanceTransferReceiptBuilder {
43    /// Creates an instance of BalanceTransferReceiptBuilder from binary payload.
44    /// payload: Byte payload to use to serialize the object.
45    /// # Returns
46    /// A BalanceTransferReceiptBuilder.
47    pub fn from_binary(_bytes: &[u8]) -> Self {
48        let super_object = ReceiptBuilder::from_binary(_bytes);
49        let mut _bytes = _bytes[super_object.get_size()..].to_vec();
50        let mosaic = MosaicBuilder::from_binary(&_bytes); // kind:CUSTOM1
51        let mut _bytes = _bytes[mosaic.get_size()..].to_vec();
52        let sender_address = AddressDto::from_binary(&_bytes); // kind:CUSTOM1
53        let mut _bytes = _bytes[sender_address.get_size()..].to_vec();
54        let recipient_address = AddressDto::from_binary(&_bytes); // kind:CUSTOM1
55        let mut _bytes = _bytes[recipient_address.get_size()..].to_vec();
56        BalanceTransferReceiptBuilder { super_object, mosaic, sender_address, recipient_address }
57    }
58
59    /// Gets mosaic.
60    ///
61    /// # Returns
62    /// A Mosaic.
63    pub fn get_mosaic(&self) -> MosaicBuilder {
64        self.mosaic.clone()
65    }
66
67    /// Gets mosaic sender address.
68    ///
69    /// # Returns
70    /// A Mosaic sender address.
71    pub fn get_sender_address(&self) -> AddressDto {
72        self.sender_address.clone()
73    }
74
75    /// Gets mosaic recipient address.
76    ///
77    /// # Returns
78    /// A Mosaic recipient address.
79    pub fn get_recipient_address(&self) -> AddressDto {
80        self.recipient_address.clone()
81    }
82
83    /// Gets the size of the type.
84    ///
85    /// Returns:
86    /// A size in bytes.
87    pub fn get_size(&self) -> usize {
88        let mut size = self.super_object.get_size();
89        size += self.mosaic.get_size(); // mosaic;
90        size += self.sender_address.get_size(); // sender_address;
91        size += self.recipient_address.get_size(); // recipient_address;
92        size
93    }
94
95    /// Serializes self to bytes.
96    ///
97    /// # Returns
98    /// A Serialized bytes.
99    pub fn serializer(&self) -> Vec<u8> {
100        let mut buf: Vec<u8> = vec![];
101        buf.append(&mut self.super_object.serializer());
102        buf.append(&mut self.mosaic.serializer()); // kind:CUSTOM
103        buf.append(&mut self.sender_address.serializer()); // kind:CUSTOM
104        buf.append(&mut self.recipient_address.serializer()); // kind:CUSTOM
105        buf
106    }
107}
108