catbuffer_rust/
voting_key_link_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::amount_dto::*;
23use super::entity_type_dto::*;
24use super::finalization_epoch_dto::*;
25use super::generator_utils::*;
26use super::key_dto::*;
27use super::link_action_dto::*;
28use super::network_type_dto::*;
29use super::signature_dto::*;
30use super::timestamp_dto::*;
31use super::transaction_builder::*;
32use super::voting_key_dto::*;
33use super::voting_key_link_transaction_body_builder::*;
34
35/// Binary layout for a non-embedded voting key link transaction.
36#[derive(Debug, Clone)]
37pub struct VotingKeyLinkTransactionBuilder {
38    /// Transaction.
39    pub super_object: TransactionBuilder,
40    /// Voting key link transaction body.
41    pub body: VotingKeyLinkTransactionBodyBuilder,
42}
43
44impl VotingKeyLinkTransactionBuilder {
45    const VERSION: u8 = 1;
46    const ENTITY_TYPE: u16 = 0x4143;
47
48
49    /// Creates an instance of VotingKeyLinkTransactionBuilder from binary payload.
50    /// payload: Byte payload to use to serialize the object.
51    /// # Returns
52    /// A VotingKeyLinkTransactionBuilder.
53    pub fn from_binary(payload: &[u8]) -> Self {
54        let mut _bytes = payload.to_vec();
55        let super_object = TransactionBuilder::from_binary(&_bytes);
56        assert_eq!(Self::VERSION, super_object.version, "Invalid entity version ({})", super_object.version);
57        assert_eq!(Self::ENTITY_TYPE, super_object._type.get_value(), "Invalid entity type ({:?})", super_object._type);
58        let mut _bytes = _bytes[super_object.get_size()..].to_vec();
59        let voting_key_link_transaction_body = VotingKeyLinkTransactionBodyBuilder::from_binary(&_bytes); // kind:CUSTOM1
60        _bytes = _bytes[voting_key_link_transaction_body.get_size()..].to_vec();
61        // create object and call.
62        VotingKeyLinkTransactionBuilder { super_object, body: voting_key_link_transaction_body }  // Transaction
63    }
64
65
66    pub fn get_linked_public_key(&self) -> VotingKeyDto {
67        self.body.linked_public_key.clone()
68    }
69    pub fn set_linked_public_key(&mut self, linked_public_key: VotingKeyDto) {
70        self.body.linked_public_key = linked_public_key;   // MARKER1 AttributeKind.CUSTOM
71    }
72
73
74    pub fn get_start_epoch(&self) -> FinalizationEpochDto {
75        self.body.start_epoch.clone()
76    }
77    pub fn set_start_epoch(&mut self, start_epoch: FinalizationEpochDto) {
78        self.body.start_epoch = start_epoch;   // MARKER1 AttributeKind.CUSTOM
79    }
80
81
82    pub fn get_end_epoch(&self) -> FinalizationEpochDto {
83        self.body.end_epoch.clone()
84    }
85    pub fn set_end_epoch(&mut self, end_epoch: FinalizationEpochDto) {
86        self.body.end_epoch = end_epoch;   // MARKER1 AttributeKind.CUSTOM
87    }
88
89
90    pub fn get_link_action(&self) -> LinkActionDto {
91        self.body.link_action.clone()
92    }
93    pub fn set_link_action(&mut self, link_action: LinkActionDto) {
94        self.body.link_action = link_action;   // MARKER1 AttributeKind.CUSTOM
95    }
96
97    /// Gets the size of the type.
98    ///
99    /// Returns:
100    /// A size in bytes.
101    pub fn get_size(&self) -> usize {
102        let mut size = self.super_object.get_size();
103        size += self.body.get_size();
104        size
105    }
106
107    /// Serializes self to bytes.
108    ///
109    /// # Returns
110    /// A Serialized bytes.
111    pub fn serializer(&self) -> Vec<u8> {
112        let mut buf: Vec<u8> = vec![];
113        buf.append(&mut (self.get_size() as u32).to_le_bytes().to_vec());
114        buf.append(&mut self.super_object.serializer());
115        buf.append(&mut self.body.serializer()); // kind:CUSTOM TransactionBody
116        buf
117    }
118}
119