use super::account_restriction_address_value_builder::*;
use super::account_restriction_flags_dto::*;
use super::account_restriction_mosaic_value_builder::*;
use super::account_restriction_transaction_type_value_builder::*;
use super::generator_utils::*;
#[derive(Debug, Clone)]
pub struct AccountRestrictionsInfoBuilder {
restriction_flags: Vec<AccountRestrictionFlagsDto>,
address_restrictions: Option<AccountRestrictionAddressValueBuilder>,
mosaic_id_restrictions: Option<AccountRestrictionMosaicValueBuilder>,
transaction_type_restrictions: Option<AccountRestrictionTransactionTypeValueBuilder>,
}
impl AccountRestrictionsInfoBuilder {
pub fn from_binary(_bytes: &[u8]) -> Self {
let restriction_flags = AccountRestrictionFlagsDto::bytes_to_flags(&_bytes[..2]); let mut _bytes = (&_bytes[2..]).to_vec();
let mut address_restrictions = None;
if restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::ADDRESS) {
let raw_address_restrictions = AccountRestrictionAddressValueBuilder::from_binary(&_bytes);
_bytes = (&_bytes[raw_address_restrictions.get_size()..]).to_vec();
address_restrictions = Some(raw_address_restrictions); }
let mut mosaic_id_restrictions = None;
if restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::MOSAIC_ID) {
let raw_mosaic_id_restrictions = AccountRestrictionMosaicValueBuilder::from_binary(&_bytes);
_bytes = (&_bytes[raw_mosaic_id_restrictions.get_size()..]).to_vec();
mosaic_id_restrictions = Some(raw_mosaic_id_restrictions); }
let mut transaction_type_restrictions = None;
if restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::TRANSACTION_TYPE) {
let raw_transaction_type_restrictions = AccountRestrictionTransactionTypeValueBuilder::from_binary(&_bytes);
_bytes = (&_bytes[raw_transaction_type_restrictions.get_size()..]).to_vec();
transaction_type_restrictions = Some(raw_transaction_type_restrictions); }
AccountRestrictionsInfoBuilder { restriction_flags, address_restrictions, mosaic_id_restrictions, transaction_type_restrictions }
}
pub fn get_restriction_flags(&self) -> Vec<AccountRestrictionFlagsDto> {
self.restriction_flags.clone()
}
pub fn get_address_restrictions(&self) -> Option<AccountRestrictionAddressValueBuilder> {
if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::ADDRESS) {
panic!("restrictionFlags is not set to ADDRESS.")
};
self.address_restrictions.clone()
}
pub fn get_mosaic_id_restrictions(&self) -> Option<AccountRestrictionMosaicValueBuilder> {
if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::MOSAIC_ID) {
panic!("restrictionFlags is not set to MOSAIC_ID.")
};
self.mosaic_id_restrictions.clone()
}
pub fn get_transaction_type_restrictions(&self) -> Option<AccountRestrictionTransactionTypeValueBuilder> {
if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::TRANSACTION_TYPE) {
panic!("restrictionFlags is not set to TRANSACTION_TYPE.")
};
self.transaction_type_restrictions.clone()
}
pub fn get_size(&self) -> usize {
let mut size = 0;
size += 2; if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::ADDRESS) {
size += self.address_restrictions.as_ref().unwrap().get_size(); }
if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::MOSAIC_ID) {
size += self.mosaic_id_restrictions.as_ref().unwrap().get_size(); }
if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::TRANSACTION_TYPE) {
size += self.transaction_type_restrictions.as_ref().unwrap().get_size(); }
size
}
pub fn serializer(&self) -> Vec<u8> {
let mut buf: Vec<u8> = vec![];
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) {
buf.append(&mut self.address_restrictions.as_ref().unwrap().serializer()); };
if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::MOSAIC_ID) {
buf.append(&mut self.mosaic_id_restrictions.as_ref().unwrap().serializer()); };
if self.restriction_flags.iter().any(|&i| i == AccountRestrictionFlagsDto::TRANSACTION_TYPE) {
buf.append(&mut self.transaction_type_restrictions.as_ref().unwrap().serializer()); };
buf
}
}