catbuffer_rust/
account_restrictions_info_builder.rs1use super::account_restriction_address_value_builder::*;
23use super::account_restriction_flags_dto::*;
24use super::account_restriction_mosaic_value_builder::*;
25use super::account_restriction_transaction_type_value_builder::*;
26use super::generator_utils::*;
27
28#[derive(Debug, Clone)]
30pub struct AccountRestrictionsInfoBuilder {
31 restriction_flags: Vec<AccountRestrictionFlagsDto>,
33 address_restrictions: Option<AccountRestrictionAddressValueBuilder>,
35 mosaic_id_restrictions: Option<AccountRestrictionMosaicValueBuilder>,
37 transaction_type_restrictions: Option<AccountRestrictionTransactionTypeValueBuilder>,
39}
40
41
42impl AccountRestrictionsInfoBuilder {
43 pub fn from_binary(_bytes: &[u8]) -> Self {
48 let restriction_flags = AccountRestrictionFlagsDto::bytes_to_flags(&_bytes[..2]); let mut _bytes = (&_bytes[2..]).to_vec();
50 let mut address_restrictions = None;
51 if restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::ADDRESS) {
52 let raw_address_restrictions = AccountRestrictionAddressValueBuilder::from_binary(&_bytes);
53 _bytes = (&_bytes[raw_address_restrictions.get_size()..]).to_vec();
54 address_restrictions = Some(raw_address_restrictions); }
56 let mut mosaic_id_restrictions = None;
57 if restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::MOSAIC_ID) {
58 let raw_mosaic_id_restrictions = AccountRestrictionMosaicValueBuilder::from_binary(&_bytes);
59 _bytes = (&_bytes[raw_mosaic_id_restrictions.get_size()..]).to_vec();
60 mosaic_id_restrictions = Some(raw_mosaic_id_restrictions); }
62 let mut transaction_type_restrictions = None;
63 if restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::TRANSACTION_TYPE) {
64 let raw_transaction_type_restrictions = AccountRestrictionTransactionTypeValueBuilder::from_binary(&_bytes);
65 _bytes = (&_bytes[raw_transaction_type_restrictions.get_size()..]).to_vec();
66 transaction_type_restrictions = Some(raw_transaction_type_restrictions); }
68 AccountRestrictionsInfoBuilder { restriction_flags, address_restrictions, mosaic_id_restrictions, transaction_type_restrictions }
69 }
70
71 pub fn get_restriction_flags(&self) -> Vec<AccountRestrictionFlagsDto> {
76 self.restriction_flags.clone()
77 }
78
79 pub fn get_address_restrictions(&self) -> Option<AccountRestrictionAddressValueBuilder> {
84 if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::ADDRESS) {
85 panic!("restrictionFlags is not set to ADDRESS.")
86 };
87 self.address_restrictions.clone()
88 }
89
90 pub fn get_mosaic_id_restrictions(&self) -> Option<AccountRestrictionMosaicValueBuilder> {
95 if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::MOSAIC_ID) {
96 panic!("restrictionFlags is not set to MOSAIC_ID.")
97 };
98 self.mosaic_id_restrictions.clone()
99 }
100
101 pub fn get_transaction_type_restrictions(&self) -> Option<AccountRestrictionTransactionTypeValueBuilder> {
106 if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::TRANSACTION_TYPE) {
107 panic!("restrictionFlags is not set to TRANSACTION_TYPE.")
108 };
109 self.transaction_type_restrictions.clone()
110 }
111
112 pub fn get_size(&self) -> usize {
117 let mut size = 0;
118 size += 2; if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::ADDRESS) {
120 size += self.address_restrictions.as_ref().unwrap().get_size(); }
122 if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::MOSAIC_ID) {
123 size += self.mosaic_id_restrictions.as_ref().unwrap().get_size(); }
125 if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::TRANSACTION_TYPE) {
126 size += self.transaction_type_restrictions.as_ref().unwrap().get_size(); }
128 size
129 }
130
131 pub fn serializer(&self) -> Vec<u8> {
136 let mut buf: Vec<u8> = vec![];
137 buf.append(&mut AccountRestrictionFlagsDto::flags_to_int(self.get_restriction_flags()).to_le_bytes().to_vec()); if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::ADDRESS) {
139 buf.append(&mut self.address_restrictions.as_ref().unwrap().serializer()); };
141 if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::MOSAIC_ID) {
142 buf.append(&mut self.mosaic_id_restrictions.as_ref().unwrap().serializer()); };
144 if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::TRANSACTION_TYPE) {
145 buf.append(&mut self.transaction_type_restrictions.as_ref().unwrap().serializer()); };
147 buf
148 }
149}
150