catbuffer_rust/detached_cosignature_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::cosignature_builder::*;
23use super::generator_utils::*;
24use super::hash256_dto::*;
25use super::key_dto::*;
26use super::signature_dto::*;
27
28/// Cosignature detached from an aggregate transaction.
29#[derive(Debug, Clone)]
30pub struct DetachedCosignatureBuilder {
31 /// Cosignature.
32 super_object: CosignatureBuilder,
33 /// Hash of the aggregate transaction that is signed by this cosignature.
34 parent_hash: Hash256Dto,
35}
36
37
38impl DetachedCosignatureBuilder {
39 /// Creates an instance of DetachedCosignatureBuilder from binary payload.
40 /// payload: Byte payload to use to serialize the object.
41 /// # Returns
42 /// A DetachedCosignatureBuilder.
43 pub fn from_binary(_bytes: &[u8]) -> Self {
44 let super_object = CosignatureBuilder::from_binary(_bytes);
45 let mut _bytes = _bytes[super_object.get_size()..].to_vec();
46 let parent_hash = Hash256Dto::from_binary(&_bytes); // kind:CUSTOM1
47 let mut _bytes = _bytes[parent_hash.get_size()..].to_vec();
48 DetachedCosignatureBuilder { super_object, parent_hash }
49 }
50
51 /// Gets hash of the aggregate transaction that is signed by this cosignature.
52 ///
53 /// # Returns
54 /// A Hash of the aggregate transaction that is signed by this cosignature.
55 pub fn get_parent_hash(&self) -> Hash256Dto {
56 self.parent_hash.clone()
57 }
58
59 /// Gets the size of the type.
60 ///
61 /// Returns:
62 /// A size in bytes.
63 pub fn get_size(&self) -> usize {
64 let mut size = self.super_object.get_size();
65 size += self.parent_hash.get_size(); // parent_hash;
66 size
67 }
68
69 /// Serializes self to bytes.
70 ///
71 /// # Returns
72 /// A Serialized bytes.
73 pub fn serializer(&self) -> Vec<u8> {
74 let mut buf: Vec<u8> = vec![];
75 buf.append(&mut self.super_object.serializer());
76 buf.append(&mut self.parent_hash.serializer()); // kind:CUSTOM
77 buf
78 }
79}
80