Skip to content

Commit

Permalink
feat(models): extend models to compute fwd fee
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Dec 19, 2024
1 parent 2d3139e commit 4974720
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/models/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/models/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ impl std::ops::DerefMut for BlockchainConfig {
pub struct BlockchainConfigParams(Dict<u32, Cell>);

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`].
Expand Down
36 changes: 36 additions & 0 deletions src/models/config/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
44 changes: 44 additions & 0 deletions src/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4974720

Please sign in to comment.