catbuffer_rust/
vrf_key_link_transaction_body_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::generator_utils::*;
23use super::key_dto::*;
24use super::link_action_dto::*;
25
26/// Binary layout for a vrf key link transaction.
27#[derive(Debug, Clone)]
28pub struct VrfKeyLinkTransactionBodyBuilder {
29    /// Linked public key.
30    pub linked_public_key: KeyDto,
31    /// Link action.
32    pub link_action: LinkActionDto,
33}
34
35impl VrfKeyLinkTransactionBodyBuilder {
36    /// Creates an instance of VrfKeyLinkTransactionBodyBuilder from binary payload.
37    /// payload: Byte payload to use to serialize the object.
38    /// # Returns
39    /// A VrfKeyLinkTransactionBodyBuilder.
40    pub fn from_binary(payload: &[u8]) -> Self {
41        let mut _bytes = payload.to_vec();
42        let linked_public_key = KeyDto::from_binary(&_bytes); // kind:CUSTOM1
43        _bytes = _bytes[linked_public_key.get_size()..].to_vec();
44        let link_action = LinkActionDto::from_binary(&_bytes); // kind:CUSTOM2
45        _bytes = (&_bytes[link_action.get_size()..]).to_vec();
46        // create object and call.
47        VrfKeyLinkTransactionBodyBuilder { linked_public_key, link_action } // TransactionBody
48    }
49
50    /// Gets the size of the type.
51    ///
52    /// Returns:
53    /// A size in bytes.
54    pub fn get_size(&self) -> usize {
55        let mut size = 0;
56        size += self.linked_public_key.get_size(); // linked_public_key_size;
57        size += self.link_action.get_size(); // link_action_size;
58        size
59    }
60
61    /// Serializes self to bytes.
62    ///
63    /// # Returns
64    /// A Serialized bytes.
65    pub fn serializer(&self) -> Vec<u8> {
66        let mut buf: Vec<u8> = vec![];
67        buf.append(&mut self.linked_public_key.serializer()); // kind:CUSTOM
68        buf.append(&mut self.link_action.serializer()); // kind:CUSTOM
69        buf
70    }
71}
72