catbuffer_rust/
importance_block_header_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::amount_dto::*;
24use super::block_fee_multiplier_dto::*;
25use super::block_header_builder::*;
26use super::difficulty_dto::*;
27use super::entity_type_dto::*;
28use super::generator_utils::*;
29use super::hash256_dto::*;
30use super::height_dto::*;
31use super::importance_block_footer_builder::*;
32use super::key_dto::*;
33use super::network_type_dto::*;
34use super::signature_dto::*;
35use super::timestamp_dto::*;
36use super::vrf_proof_builder::*;
37
38/// Binary layout for an importance block header.
39#[derive(Debug, Clone)]
40pub struct ImportanceBlockHeaderBuilder {
41    /// Block header.
42    super_object: BlockHeaderBuilder,
43    /// Importance block footer.
44    importance_block_footer: ImportanceBlockFooterBuilder,
45}
46
47
48impl ImportanceBlockHeaderBuilder {
49    /// Creates an instance of ImportanceBlockHeaderBuilder from binary payload.
50    /// payload: Byte payload to use to serialize the object.
51    /// # Returns
52    /// A ImportanceBlockHeaderBuilder.
53    pub fn from_binary(_bytes: &[u8]) -> Self {
54        let super_object = BlockHeaderBuilder::from_binary(_bytes);
55        let mut _bytes = _bytes[super_object.get_size()..].to_vec();
56        let importance_block_footer = ImportanceBlockFooterBuilder::from_binary(&_bytes); // kind:CUSTOM1
57        let mut _bytes = _bytes[importance_block_footer.get_size()..].to_vec();
58        ImportanceBlockHeaderBuilder { super_object, importance_block_footer }
59    }
60
61    /// Gets number of voting eligible accounts.
62    ///
63    /// # Returns
64    /// A Number of voting eligible accounts.
65    pub fn get_voting_eligible_accounts_count(&self) -> u32 {
66        self.importance_block_footer.get_voting_eligible_accounts_count()
67    }
68
69    /// Gets number of harvesting eligible accounts.
70    ///
71    /// # Returns
72    /// A Number of harvesting eligible accounts.
73    pub fn get_harvesting_eligible_accounts_count(&self) -> u64 {
74        self.importance_block_footer.get_harvesting_eligible_accounts_count()
75    }
76
77    /// Gets total balance eligible for voting.
78    ///
79    /// # Returns
80    /// A Total balance eligible for voting.
81    pub fn get_total_voting_balance(&self) -> AmountDto {
82        self.importance_block_footer.get_total_voting_balance()
83    }
84
85    /// Gets previous importance block hash.
86    ///
87    /// # Returns
88    /// A Previous importance block hash.
89    pub fn get_previous_importance_block_hash(&self) -> Hash256Dto {
90        self.importance_block_footer.get_previous_importance_block_hash()
91    }
92
93    /// Gets the size of the type.
94    ///
95    /// Returns:
96    /// A size in bytes.
97    pub fn get_size(&self) -> usize {
98        let mut size = self.super_object.get_size();
99        size += self.importance_block_footer.get_size(); // importance_block_footer;
100        size
101    }
102
103    /// Serializes self to bytes.
104    ///
105    /// # Returns
106    /// A Serialized bytes.
107    pub fn serializer(&self) -> Vec<u8> {
108        let mut buf: Vec<u8> = vec![];
109        buf.append(&mut self.super_object.serializer());
110        buf.append(&mut self.importance_block_footer.serializer()); // kind:CUSTOM
111        buf
112    }
113}
114