From 49747202c1c3c288a30a078c68c792df6515288e Mon Sep 17 00:00:00 2001 From: Ivan Kalinin Date: Thu, 19 Dec 2024 19:01:01 +0100 Subject: [PATCH] feat(models): extend models to compute fwd fee --- src/models/account/mod.rs | 4 ++-- src/models/config/mod.rs | 7 ++++++ src/models/config/params.rs | 36 ++++++++++++++++++++++++++++++ src/num/mod.rs | 44 +++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) diff --git a/src/models/account/mod.rs b/src/models/account/mod.rs index ab5508c6..f441dcec 100644 --- a/src/models/account/mod.rs +++ b/src/models/account/mod.rs @@ -406,14 +406,14 @@ impl StateInit { } /// Returns the number of data bits that this struct occupies. - const fn bit_len(&self) -> u16 { + pub const fn bit_len(&self) -> u16 { (1 + self.split_depth.is_some() as u16 * SplitDepth::BITS) + (1 + self.special.is_some() as u16 * SpecialFlags::BITS) + 3 } /// Returns the number of references that this struct occupies. - const fn reference_count(&self) -> u8 { + pub const fn reference_count(&self) -> u8 { self.code.is_some() as u8 + self.data.is_some() as u8 + !self.libraries.is_empty() as u8 } } diff --git a/src/models/config/mod.rs b/src/models/config/mod.rs index 0deaad26..64d12785 100644 --- a/src/models/config/mod.rs +++ b/src/models/config/mod.rs @@ -59,6 +59,13 @@ impl std::ops::DerefMut for BlockchainConfig { pub struct BlockchainConfigParams(Dict); impl BlockchainConfigParams { + /// Creates a dictionary from a raw cell. + /// + /// NOTE: Root is mandatory since the configs dictionary can't be empty. + pub fn from_raw(dict_root: Cell) -> Self { + Self(Dict::from_raw(Some(dict_root))) + } + /// Returns the elector account address (in masterchain). /// /// Uses [`ConfigParam1`]. diff --git a/src/models/config/params.rs b/src/models/config/params.rs index ce5961c2..f7f2e450 100644 --- a/src/models/config/params.rs +++ b/src/models/config/params.rs @@ -1372,6 +1372,42 @@ impl ValidatorSetPRNG { } } +/// size_limits_config_v2#02 +/// max_msg_bits:uint32 +/// max_msg_cells:uint32 +/// max_library_cells:uint32 +/// max_vm_data_depth:uint16 +/// max_ext_msg_size:uint32 +/// max_ext_msg_depth:uint16 +/// max_acc_state_cells:uint32 +/// max_acc_state_bits:uint32 +/// max_acc_public_libraries:uint32 +/// defer_out_queue_size_limit:uint32 = SizeLimitsConfig; +#[derive(Debug, Clone, Eq, PartialEq, Store, Load)] +#[tlb(tag = "#02")] +pub struct SizeLimitsConfig { + /// Max number of bits in message. + pub max_msg_bits: u32, + /// Max number of cells in message. + pub max_msg_cells: u32, + /// Max number of cells in library. + pub max_library_cells: u32, + /// Max cell tree depth for VM data. + pub max_vm_data_depth: u16, + /// Max number of bytes of a BOC-encoded external message. + pub max_ext_msg_size: u32, + /// Max cell tree depth of an external message. + pub max_ext_msg_depth: u16, + /// Max number of cells per account. + pub max_acc_state_cells: u32, + /// Max number of bits per account. + pub max_acc_state_bits: u32, + /// Max number of public libraries per account. + pub max_acc_public_libraries: u32, + /// Size limit of a deferred out messages queue. + pub defer_out_queue_size_limit: u32, +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/num/mod.rs b/src/num/mod.rs index 8cd912a1..8d44042d 100644 --- a/src/num/mod.rs +++ b/src/num/mod.rs @@ -422,6 +422,50 @@ macro_rules! impl_var_uints { _ => None, } } + + /// Tries to add an other value to the current one. + pub fn try_add_assign(&mut self, other: Self) -> Result<(), Error> { + match self.checked_add(other) { + Some(new_value) => { + *self = new_value; + Ok(()) + }, + None => Err(Error::IntOverflow), + } + } + + /// Tries to subtract an other value from the current one. + pub fn try_sub_assign(&mut self, other: Self) -> Result<(), Error> { + match self.checked_sub(other) { + Some(new_value) => { + *self = new_value; + Ok(()) + }, + None => Err(Error::IntOverflow), + } + } + + /// Tries to multiply the current value by the other value. + pub fn try_mul_assign(&mut self, other: Self) -> Result<(), Error> { + match self.checked_mul(other) { + Some(new_value) => { + *self = new_value; + Ok(()) + }, + None => Err(Error::IntOverflow), + } + } + + /// Tries to divice the current value by the other value. + pub fn try_div_assign(&mut self, other: Self) -> Result<(), Error> { + match self.checked_div(other) { + Some(new_value) => { + *self = new_value; + Ok(()) + }, + None => Err(Error::IntOverflow), + } + } } impl ExactSize for $ident {