diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/get_execution_info.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/get_execution_info.rs index 93d49c6b10..50e7e5ecf5 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/get_execution_info.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/get_execution_info.rs @@ -1,5 +1,3 @@ -use std::collections::BTreeMap; - use cairo_vm::Felt252; use num_traits::Pow; use starknet_api::core::ChainId; @@ -8,14 +6,13 @@ use starknet_api::felt; use starknet_api::transaction::{ AccountDeploymentData, Calldata, - DeprecatedResourceBoundsMapping, Fee, PaymasterData, - Resource, ResourceBounds, Tip, TransactionHash, TransactionVersion, + ValidResourceBounds, }; use starknet_types_core::felt::Felt; use test_case::test_case; @@ -213,23 +210,10 @@ fn test_get_execution_info( only_query, ..Default::default() }, - resource_bounds: DeprecatedResourceBoundsMapping(BTreeMap::from([ - ( - Resource::L1Gas, - // TODO(Ori, 1/2/2024): Write an indicative expect message explaining why - // the convertion works. - ResourceBounds { - max_amount: max_amount - .0 - .try_into() - .expect("Failed to convert u128 to u64."), - max_price_per_unit: max_price_per_unit.0, - }, - ), - (Resource::L2Gas, ResourceBounds { max_amount: 0, max_price_per_unit: 0 }), - ])) - .try_into() - .unwrap(), + resource_bounds: ValidResourceBounds::L1Gas(ResourceBounds { + max_amount: max_amount.0.try_into().expect("Failed to convert u128 to u64."), + max_price_per_unit: max_price_per_unit.0, + }), tip: Tip::default(), nonce_data_availability_mode: DataAvailabilityMode::L1, fee_data_availability_mode: DataAvailabilityMode::L1, diff --git a/crates/native_blockifier/src/py_transaction.rs b/crates/native_blockifier/src/py_transaction.rs index aaa6e071e9..708c8499b8 100644 --- a/crates/native_blockifier/src/py_transaction.rs +++ b/crates/native_blockifier/src/py_transaction.rs @@ -73,26 +73,17 @@ impl From for starknet_api::transaction::ResourceBounds { #[derive(Clone, FromPyObject)] pub struct PyResourceBoundsMapping(pub BTreeMap); -impl TryFrom - for starknet_api::transaction::DeprecatedResourceBoundsMapping -{ +impl TryFrom for ValidResourceBounds { type Error = StarknetApiError; fn try_from(py_resource_bounds_mapping: PyResourceBoundsMapping) -> Result { - let resource_bounds_vec: Vec<(Resource, ResourceBounds)> = py_resource_bounds_mapping + let map = py_resource_bounds_mapping .0 .into_iter() .map(|(py_resource_type, py_resource_bounds)| { (Resource::from(py_resource_type), ResourceBounds::from(py_resource_bounds)) }) .collect(); - Self::try_from(resource_bounds_vec) - } -} - -impl TryFrom for ValidResourceBounds { - type Error = StarknetApiError; - fn try_from(py_resource_bounds_mapping: PyResourceBoundsMapping) -> Result { - DeprecatedResourceBoundsMapping::try_from(py_resource_bounds_mapping)?.try_into() + DeprecatedResourceBoundsMapping(map).try_into() } } diff --git a/crates/papyrus_storage/src/serialization/serializers.rs b/crates/papyrus_storage/src/serialization/serializers.rs index e58e5366be..f707da82ac 100644 --- a/crates/papyrus_storage/src/serialization/serializers.rs +++ b/crates/papyrus_storage/src/serialization/serializers.rs @@ -90,7 +90,6 @@ use starknet_api::transaction::{ DeployAccountTransactionV3, DeployTransaction, DeployTransactionOutput, - DeprecatedResourceBoundsMapping, Event, EventContent, EventData, @@ -368,7 +367,6 @@ auto_storage_serde! { pub max_amount: u64, pub max_price_per_unit: u128, } - pub struct DeprecatedResourceBoundsMapping(pub BTreeMap); pub struct SequencerContractAddress(pub ContractAddress); pub struct Signature { pub r: Felt, diff --git a/crates/papyrus_test_utils/src/lib.rs b/crates/papyrus_test_utils/src/lib.rs index d62893e045..9fc0455039 100644 --- a/crates/papyrus_test_utils/src/lib.rs +++ b/crates/papyrus_test_utils/src/lib.rs @@ -113,7 +113,6 @@ use starknet_api::transaction::{ DeployAccountTransactionV3, DeployTransaction, DeployTransactionOutput, - DeprecatedResourceBoundsMapping, Event, EventContent, EventData, @@ -729,7 +728,6 @@ auto_impl_get_test_instance! { pub max_amount: u64, pub max_price_per_unit: u128, } - pub struct DeprecatedResourceBoundsMapping(pub BTreeMap); pub struct SequencerContractAddress(pub ContractAddress); pub struct Signature { pub r: Felt, diff --git a/crates/starknet_api/Cargo.toml b/crates/starknet_api/Cargo.toml index e00c47ab8e..496b47d797 100644 --- a/crates/starknet_api/Cargo.toml +++ b/crates/starknet_api/Cargo.toml @@ -29,3 +29,6 @@ thiserror.workspace = true [dev-dependencies] assert_matches.workspace = true rstest.workspace = true + +[package.metadata.cargo-machete] +ignored = ["strum"] diff --git a/crates/starknet_api/src/rpc_transaction.rs b/crates/starknet_api/src/rpc_transaction.rs index 5dce9b4009..c32892558b 100644 --- a/crates/starknet_api/src/rpc_transaction.rs +++ b/crates/starknet_api/src/rpc_transaction.rs @@ -2,8 +2,6 @@ #[path = "rpc_transaction_test.rs"] mod rpc_transaction_test; -use std::collections::BTreeMap; - use serde::{Deserialize, Serialize}; use starknet_types_core::felt::Felt; @@ -28,7 +26,6 @@ use crate::transaction::{ InvokeTransaction, InvokeTransactionV3, PaymasterData, - Resource, Tip, Transaction, TransactionSignature, @@ -285,17 +282,3 @@ pub struct EntryPointByType { #[serde(rename = "L1_HANDLER")] pub l1handler: Vec, } - -// TODO(Nimrod): Remove this conversion. -impl From for crate::transaction::DeprecatedResourceBoundsMapping { - fn from( - all_resource_bounds: AllResourceBounds, - ) -> crate::transaction::DeprecatedResourceBoundsMapping { - let map = BTreeMap::from([ - (Resource::L1Gas, all_resource_bounds.l1_gas), - (Resource::L2Gas, all_resource_bounds.l2_gas), - (Resource::L1DataGas, all_resource_bounds.l1_data_gas), - ]); - crate::transaction::DeprecatedResourceBoundsMapping(map) - } -} diff --git a/crates/starknet_api/src/transaction.rs b/crates/starknet_api/src/transaction.rs index 39bd199d46..43e58c752f 100644 --- a/crates/starknet_api/src/transaction.rs +++ b/crates/starknet_api/src/transaction.rs @@ -1,11 +1,10 @@ -use std::collections::{BTreeMap, HashSet}; +use std::collections::BTreeMap; use std::fmt::Display; use std::sync::Arc; use derive_more::{Display, From}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use starknet_types_core::felt::Felt; -use strum::IntoEnumIterator; use strum_macros::EnumIter; use crate::block::{BlockHash, BlockNumber}; @@ -936,29 +935,6 @@ where // TODO(Nimrod): Remove this struct definition. pub struct DeprecatedResourceBoundsMapping(pub BTreeMap); -impl TryFrom> for DeprecatedResourceBoundsMapping { - type Error = StarknetApiError; - fn try_from( - resource_resource_bounds_pairs: Vec<(Resource, ResourceBounds)>, - ) -> Result { - let n_variants = Resource::iter().count(); - let allowed_signed_variants = [n_variants, n_variants - 1]; - let unique_resources: HashSet = - HashSet::from_iter(resource_resource_bounds_pairs.iter().map(|(k, _)| *k)); - if !allowed_signed_variants.contains(&unique_resources.len()) - || !allowed_signed_variants.contains(&resource_resource_bounds_pairs.len()) - { - // TODO(Nimrod): Consider making this check more strict. - Err(StarknetApiError::InvalidResourceMappingInitializer(format!( - "{:?}", - resource_resource_bounds_pairs - ))) - } else { - Ok(Self(resource_resource_bounds_pairs.into_iter().collect::>())) - } - } -} - #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub enum ValidResourceBounds { L1Gas(ResourceBounds), // Pre 0.13.3. Only L1 gas. L2 bounds are signed but never used. diff --git a/crates/starknet_client/src/writer/objects/transaction.rs b/crates/starknet_client/src/writer/objects/transaction.rs index 50adae8afd..c9f68ecdde 100644 --- a/crates/starknet_client/src/writer/objects/transaction.rs +++ b/crates/starknet_client/src/writer/objects/transaction.rs @@ -31,12 +31,12 @@ use starknet_api::transaction::{ AccountDeploymentData, Calldata, ContractAddressSalt, - DeprecatedResourceBoundsMapping, Fee, PaymasterData, Tip, TransactionSignature, TransactionVersion, + ValidResourceBounds, }; // Each transaction type has a field called `type`. This field needs to be of a type that @@ -104,7 +104,7 @@ pub struct DeployAccountV1Transaction { #[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq)] #[serde(deny_unknown_fields)] pub struct DeployAccountV3Transaction { - pub resource_bounds: DeprecatedResourceBoundsMapping, + pub resource_bounds: ValidResourceBounds, pub tip: Tip, pub contract_address_salt: ContractAddressSalt, pub class_hash: ClassHash, @@ -169,7 +169,7 @@ pub struct InvokeV1Transaction { #[derive(Debug, Deserialize, Serialize, Clone, Eq, PartialEq)] #[serde(deny_unknown_fields)] pub struct InvokeV3Transaction { - pub resource_bounds: DeprecatedResourceBoundsMapping, + pub resource_bounds: ValidResourceBounds, pub tip: Tip, pub calldata: Calldata, pub sender_address: ContractAddress, @@ -235,7 +235,7 @@ pub struct DeclareV2Transaction { #[serde(deny_unknown_fields)] pub struct DeclareV3Transaction { pub contract_class: ContractClass, - pub resource_bounds: DeprecatedResourceBoundsMapping, + pub resource_bounds: ValidResourceBounds, pub tip: Tip, pub signature: TransactionSignature, pub nonce: Nonce,