Skip to content

Commit

Permalink
feat(starknet_api): checked mul for gas vector (#2300)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavGrs authored Dec 3, 2024
1 parent 1aa2fae commit 340c229
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/starknet_api/src/execution_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ impl GasAmount {
pub fn checked_mul(self, rhs: GasPrice) -> Option<Fee> {
rhs.checked_mul(self)
}

pub fn checked_factor_mul(self, factor: u64) -> Option<Self> {
self.0.checked_mul(factor).map(Self)
}
}

#[cfg_attr(
Expand Down Expand Up @@ -109,6 +113,19 @@ impl GasVector {
}
}

pub fn checked_scalar_mul(self, factor: u64) -> Option<Self> {
match (
self.l1_gas.checked_factor_mul(factor),
self.l1_data_gas.checked_factor_mul(factor),
self.l2_gas.checked_factor_mul(factor),
) {
(Some(l1_gas), Some(l1_data_gas), Some(l2_gas)) => {
Some(Self { l1_gas, l1_data_gas, l2_gas })
}
_ => None,
}
}

/// Computes the cost (in fee token units) of the gas vector (panicking on overflow).
pub fn cost(&self, gas_prices: &GasPriceVector) -> Fee {
let mut sum = Fee(0);
Expand Down

0 comments on commit 340c229

Please sign in to comment.