diff --git a/crates/starknet_api/src/execution_resources.rs b/crates/starknet_api/src/execution_resources.rs index 9c564434643..bfdbe4a9bbc 100644 --- a/crates/starknet_api/src/execution_resources.rs +++ b/crates/starknet_api/src/execution_resources.rs @@ -66,6 +66,10 @@ impl GasAmount { pub fn checked_mul(self, rhs: GasPrice) -> Option { rhs.checked_mul(self) } + + pub fn checked_factor_mul(self, factor: u64) -> Option { + self.0.checked_mul(factor).map(Self) + } } #[cfg_attr( @@ -109,6 +113,20 @@ impl GasVector { } } + pub fn checked_mul(self, factor: usize) -> Option { + let u64_factor = factor.try_into().ok()?; + match ( + self.l1_gas.checked_factor_mul(u64_factor), + self.l1_data_gas.checked_factor_mul(u64_factor), + self.l2_gas.checked_factor_mul(u64_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);