diff --git a/crates/starknet_api/src/execution_resources.rs b/crates/starknet_api/src/execution_resources.rs index 9c56443464..c9831b34aa 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,19 @@ impl GasVector { } } + pub fn checked_scalar_mul(self, factor: u64) -> Option { + 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);