diff --git a/bin/katana/src/main.rs b/bin/katana/src/main.rs index 8a2b524426..506c91d014 100644 --- a/bin/katana/src/main.rs +++ b/bin/katana/src/main.rs @@ -6,7 +6,8 @@ use clap::{CommandFactory, Parser}; use clap_complete::{generate, Shell}; use console::Style; use katana_core::sequencer::KatanaSequencer; -use katana_primitives::contract::{ClassHash, ContractAddress}; +use katana_primitives::class::ClassHash; +use katana_primitives::contract::ContractAddress; use katana_primitives::genesis::allocation::GenesisAccountAlloc; use katana_primitives::genesis::Genesis; use katana_rpc::{spawn, NodeHandle}; diff --git a/crates/katana/core/src/backend/contract.rs b/crates/katana/core/src/backend/contract.rs index e66cf748ad..57966dc61c 100644 --- a/crates/katana/core/src/backend/contract.rs +++ b/crates/katana/core/src/backend/contract.rs @@ -1,4 +1,4 @@ -use katana_primitives::contract::DeprecatedCompiledClass; +use katana_primitives::class::DeprecatedCompiledClass; use starknet::core::types::FlattenedSierraClass; pub enum StarknetContract { diff --git a/crates/katana/core/src/sequencer.rs b/crates/katana/core/src/sequencer.rs index 7579410eb7..aa76cd9d3a 100644 --- a/crates/katana/core/src/sequencer.rs +++ b/crates/katana/core/src/sequencer.rs @@ -12,9 +12,8 @@ use katana_executor::blockifier::utils::{block_context_from_envs, EntryPointCall use katana_executor::blockifier::PendingState; use katana_primitives::block::{BlockHash, BlockHashOrNumber, BlockIdOrTag, BlockNumber}; use katana_primitives::chain::ChainId; -use katana_primitives::contract::{ - ClassHash, CompiledClass, ContractAddress, Nonce, StorageKey, StorageValue, -}; +use katana_primitives::class::{ClassHash, CompiledClass}; +use katana_primitives::contract::{ContractAddress, Nonce, StorageKey, StorageValue}; use katana_primitives::event::{ContinuationToken, ContinuationTokenError}; use katana_primitives::receipt::Event; use katana_primitives::transaction::{ExecutableTxWithHash, TxHash, TxWithHash}; diff --git a/crates/katana/executor/src/blockifier/state.rs b/crates/katana/executor/src/blockifier/state.rs index 46fc4a14f8..1ba6152a53 100644 --- a/crates/katana/executor/src/blockifier/state.rs +++ b/crates/katana/executor/src/blockifier/state.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use blockifier::state::cached_state::{CachedState, GlobalContractCache}; use blockifier::state::errors::StateError; use blockifier::state::state_api::{StateReader, StateResult}; -use katana_primitives::contract::{CompiledClass, FlattenedSierraClass}; +use katana_primitives::class::{CompiledClass, FlattenedSierraClass}; use katana_primitives::conversion::blockifier::to_class; use katana_primitives::FieldElement; use katana_provider::traits::contract::ContractClassProvider; @@ -16,9 +16,8 @@ use starknet_api::patricia_key; use starknet_api::state::StorageKey; mod primitives { - pub use katana_primitives::contract::{ - ClassHash, CompiledClassHash, ContractAddress, Nonce, StorageKey, StorageValue, - }; + pub use katana_primitives::class::{ClassHash, CompiledClassHash}; + pub use katana_primitives::contract::{ContractAddress, Nonce, StorageKey, StorageValue}; } /// A state db only provide read access. @@ -171,10 +170,7 @@ impl ContractClassProvider for CachedStateWrapper where Db: StateReader + StateProvider + Sync + Send, { - fn class( - &self, - hash: katana_primitives::contract::ClassHash, - ) -> ProviderResult> { + fn class(&self, hash: primitives::ClassHash) -> ProviderResult> { if let res @ Some(_) = self.class_cache.read().compiled.get(&hash).cloned() { Ok(res) } else { @@ -184,8 +180,8 @@ where fn compiled_class_hash_of_class_hash( &self, - hash: katana_primitives::contract::ClassHash, - ) -> ProviderResult> { + hash: primitives::ClassHash, + ) -> ProviderResult> { let Ok(hash) = self.inner().get_compiled_class_hash(ClassHash(hash.into())) else { return Ok(None); }; @@ -194,7 +190,7 @@ where fn sierra_class( &self, - hash: katana_primitives::contract::ClassHash, + hash: primitives::ClassHash, ) -> ProviderResult> { let class = self.class_cache.read().sierra.get(&hash).cloned(); Ok(class) @@ -207,9 +203,9 @@ where { fn storage( &self, - address: katana_primitives::contract::ContractAddress, - storage_key: katana_primitives::contract::StorageKey, - ) -> ProviderResult> { + address: primitives::ContractAddress, + storage_key: primitives::StorageKey, + ) -> ProviderResult> { let Ok(value) = self.inner().get_storage_at(address.into(), StorageKey(patricia_key!(storage_key))) else { @@ -220,8 +216,8 @@ where fn nonce( &self, - address: katana_primitives::contract::ContractAddress, - ) -> ProviderResult> { + address: primitives::ContractAddress, + ) -> ProviderResult> { let Ok(nonce) = self.inner().get_nonce_at(address.into()) else { return Ok(None); }; @@ -230,8 +226,8 @@ where fn class_hash_of_contract( &self, - address: katana_primitives::contract::ContractAddress, - ) -> ProviderResult> { + address: primitives::ContractAddress, + ) -> ProviderResult> { let Ok(hash) = self.inner().get_class_hash_at(address.into()) else { return Ok(None); }; diff --git a/crates/katana/executor/src/blockifier/utils.rs b/crates/katana/executor/src/blockifier/utils.rs index f309cc9a9c..b5c39fa6c5 100644 --- a/crates/katana/executor/src/blockifier/utils.rs +++ b/crates/katana/executor/src/blockifier/utils.rs @@ -245,8 +245,8 @@ pub fn get_state_update_from_cached_state( (class_hash.0.into(), class) }) .collect::>(); let nonce_updates = @@ -275,23 +275,25 @@ pub fn get_state_update_from_cached_state( }) .collect::>(); - let contract_updates = state_diff - .address_to_class_hash - .into_iter() - .map(|(key, value)| (key.into(), value.0.into())) - .collect::>(); - - let declared_classes = state_diff - .class_hash_to_compiled_class_hash - .into_iter() - .map(|(key, value)| (key.0.into(), value.0.into())) - .collect::>(); + let contract_updates = + state_diff + .address_to_class_hash + .into_iter() + .map(|(key, value)| (key.into(), value.0.into())) + .collect::>(); + + let declared_classes = + state_diff + .class_hash_to_compiled_class_hash + .into_iter() + .map(|(key, value)| (key.0.into(), value.0.into())) + .collect::>(); StateUpdatesWithDeclaredClasses { declared_sierra_classes, diff --git a/crates/katana/primitives/Cargo.toml b/crates/katana/primitives/Cargo.toml index d9cd822c32..3e91d40bb9 100644 --- a/crates/katana/primitives/Cargo.toml +++ b/crates/katana/primitives/Cargo.toml @@ -23,8 +23,8 @@ strum_macros.workspace = true thiserror.workspace = true blockifier.workspace = true -cairo-lang-starknet.workspace = true cairo-lang-sierra.workspace = true +cairo-lang-starknet.workspace = true flate2.workspace = true starknet_api.workspace = true diff --git a/crates/katana/primitives/src/class.rs b/crates/katana/primitives/src/class.rs new file mode 100644 index 0000000000..610b58c3c6 --- /dev/null +++ b/crates/katana/primitives/src/class.rs @@ -0,0 +1,38 @@ +use cairo_lang_starknet::casm_contract_class::CasmContractClass; + +use crate::FieldElement; + +/// The canonical hash of a contract class. This is the identifier of a class. +pub type ClassHash = FieldElement; +/// The hash of a compiled contract class. +pub type CompiledClassHash = FieldElement; + +pub type SierraClass = starknet::core::types::contract::SierraClass; +pub type FlattenedSierraClass = starknet::core::types::FlattenedSierraClass; + +/// Deprecated legacy (Cairo 0) CASM class +pub type DeprecatedCompiledClass = ::starknet_api::deprecated_contract_class::ContractClass; + +/// Represents an executable Sierra program. +#[derive(Debug, Clone, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct SierraProgram { + pub program: cairo_lang_sierra::program::Program, + pub entry_points_by_type: cairo_lang_starknet::contract_class::ContractEntryPoints, +} + +#[derive(Debug, Clone, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct SierraCompiledClass { + pub casm: CasmContractClass, + pub sierra: SierraProgram, +} + +/// Executable contract class +#[allow(clippy::large_enum_variant)] +#[derive(Debug, Clone, Eq, PartialEq, derive_more::From)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum CompiledClass { + Class(SierraCompiledClass), + Deprecated(DeprecatedCompiledClass), +} diff --git a/crates/katana/primitives/src/contract.rs b/crates/katana/primitives/src/contract.rs index efbc169eaa..028bd8a95a 100644 --- a/crates/katana/primitives/src/contract.rs +++ b/crates/katana/primitives/src/contract.rs @@ -1,9 +1,9 @@ use std::fmt; -use cairo_lang_starknet::casm_contract_class::CasmContractClass; use derive_more::Deref; use starknet::core::utils::normalize_address; +use crate::class::ClassHash; use crate::FieldElement; /// Represents the type for a contract storage key. @@ -11,17 +11,9 @@ pub type StorageKey = FieldElement; /// Represents the type for a contract storage value. pub type StorageValue = FieldElement; -/// The canonical hash of a contract class. This is the class hash value of a contract instance. -pub type ClassHash = FieldElement; -/// The hash of a compiled contract class. -pub type CompiledClassHash = FieldElement; - /// Represents the type for a contract nonce. pub type Nonce = FieldElement; -pub type SierraClass = starknet::core::types::contract::SierraClass; -pub type FlattenedSierraClass = starknet::core::types::FlattenedSierraClass; - /// Represents a contract address. #[derive(Default, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, Debug, Deref)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -60,28 +52,3 @@ pub struct GenericContractInfo { /// The hash of the contract class. pub class_hash: ClassHash, } - -pub type DeprecatedCompiledClass = ::starknet_api::deprecated_contract_class::ContractClass; - -#[derive(Debug, Clone, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct SierraProgram { - pub program: cairo_lang_sierra::program::Program, - pub entry_points_by_type: cairo_lang_starknet::contract_class::ContractEntryPoints, -} - -#[derive(Debug, Clone, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct SierraCompiledClass { - pub casm: CasmContractClass, - pub sierra: SierraProgram, -} - -/// Executable contract class -#[allow(clippy::large_enum_variant)] -#[derive(Debug, Clone, Eq, PartialEq, derive_more::From)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub enum CompiledClass { - Deprecated(DeprecatedCompiledClass), - Class(SierraCompiledClass), -} diff --git a/crates/katana/primitives/src/conversion/blockifier.rs b/crates/katana/primitives/src/conversion/blockifier.rs index eade10ec20..0670820076 100644 --- a/crates/katana/primitives/src/conversion/blockifier.rs +++ b/crates/katana/primitives/src/conversion/blockifier.rs @@ -8,7 +8,7 @@ use starknet_api::hash::StarkHash; use starknet_api::patricia_key; use crate::chain::ChainId; -use crate::contract::CompiledClass; +use crate::class::CompiledClass; impl From for ContractAddress { fn from(address: crate::contract::ContractAddress) -> Self { diff --git a/crates/katana/primitives/src/conversion/rpc.rs b/crates/katana/primitives/src/conversion/rpc.rs index 4a38a11625..41d9836743 100644 --- a/crates/katana/primitives/src/conversion/rpc.rs +++ b/crates/katana/primitives/src/conversion/rpc.rs @@ -23,13 +23,13 @@ use starknet_api::deprecated_contract_class::{ ContractClassAbiEntry, EntryPoint, EntryPointType, TypedParameter, }; -use crate::contract::{ +use crate::class::{ ClassHash, CompiledClassHash, DeprecatedCompiledClass, FlattenedSierraClass, SierraCompiledClass, SierraProgram, }; use crate::FieldElement; -/// Converts the legacy inner compiled class type [CompiledContractClassV0] into its RPC equivalent +/// Converts the legacy inner compiled class type [DeprecatedCompiledClass] into its RPC equivalent /// [`ContractClass`]. pub fn legacy_inner_to_rpc_class( legacy_contract_class: DeprecatedCompiledClass, @@ -135,11 +135,11 @@ pub fn legacy_inner_to_rpc_class( Ok(ContractClass::Legacy(CompressedLegacyContractClass { abi, program, entry_points_by_type })) } -/// Convert the given [`FlattenedSierraClass`] into the inner compiled class type -/// [`CompiledContractClass`] along with its class hashes. +/// Convert the given [FlattenedSierraClass] into the inner compiled class type +/// [CompiledClass](crate::class::CompiledClass) along with its class hashes. pub fn flattened_sierra_to_compiled_class( contract_class: &FlattenedSierraClass, -) -> Result<(ClassHash, CompiledClassHash, crate::contract::CompiledClass)> { +) -> Result<(ClassHash, CompiledClassHash, crate::class::CompiledClass)> { let class_hash = contract_class.class_hash(); let class = rpc_to_cairo_contract_class(contract_class)?; @@ -151,7 +151,7 @@ pub fn flattened_sierra_to_compiled_class( let casm = CasmContractClass::from_contract_class(class, true)?; let compiled_hash = FieldElement::from_bytes_be(&casm.compiled_class_hash().to_be_bytes())?; - let class = crate::contract::CompiledClass::Class(SierraCompiledClass { casm, sierra }); + let class = crate::class::CompiledClass::Class(SierraCompiledClass { casm, sierra }); Ok((class_hash, compiled_hash, class)) } @@ -166,10 +166,10 @@ pub fn compiled_class_hash_from_flattened_sierra_class( } /// Converts a legacy RPC compiled contract class [CompressedLegacyContractClass] type to the inner -/// compiled class type [CompiledContractClass] along with its class hash. +/// compiled class type [CompiledClass](crate::class::CompiledClass) along with its class hash. pub fn legacy_rpc_to_compiled_class( compressed_legacy_contract: &CompressedLegacyContractClass, -) -> Result<(ClassHash, crate::contract::CompiledClass)> { +) -> Result<(ClassHash, crate::class::CompiledClass)> { let class_json = json!({ "abi": compressed_legacy_contract.abi.clone().unwrap_or_default(), "entry_points_by_type": compressed_legacy_contract.entry_points_by_type, @@ -179,7 +179,7 @@ pub fn legacy_rpc_to_compiled_class( let deprecated_class: DeprecatedCompiledClass = serde_json::from_value(class_json.clone())?; let class_hash = serde_json::from_value::(class_json)?.class_hash()?; - Ok((class_hash, crate::contract::CompiledClass::Deprecated(deprecated_class))) + Ok((class_hash, crate::class::CompiledClass::Deprecated(deprecated_class))) } /// Converts `starknet-rs` RPC [FlattenedSierraClass] type to Cairo's @@ -274,7 +274,7 @@ mod tests { use starknet::core::types::ContractClass; use super::{legacy_inner_to_rpc_class, legacy_rpc_to_compiled_class}; - use crate::contract::{CompiledClass, DeprecatedCompiledClass}; + use crate::class::{CompiledClass, DeprecatedCompiledClass}; use crate::genesis::constant::DEFAULT_OZ_ACCOUNT_CONTRACT; use crate::utils::class::parse_deprecated_compiled_class; diff --git a/crates/katana/primitives/src/genesis/allocation.rs b/crates/katana/primitives/src/genesis/allocation.rs index 81cf25abbd..fa5fd2a07c 100644 --- a/crates/katana/primitives/src/genesis/allocation.rs +++ b/crates/katana/primitives/src/genesis/allocation.rs @@ -11,7 +11,8 @@ use starknet::core::utils::get_contract_address; use starknet::signers::SigningKey; use super::constant::DEFAULT_OZ_ACCOUNT_CONTRACT_CLASS_HASH; -use crate::contract::{ClassHash, ContractAddress, StorageKey, StorageValue}; +use crate::class::ClassHash; +use crate::contract::{ContractAddress, StorageKey, StorageValue}; use crate::FieldElement; /// Represents a contract allocation in the genesis block. diff --git a/crates/katana/primitives/src/genesis/constant.rs b/crates/katana/primitives/src/genesis/constant.rs index 6d3c295b8a..16d8019b85 100644 --- a/crates/katana/primitives/src/genesis/constant.rs +++ b/crates/katana/primitives/src/genesis/constant.rs @@ -1,9 +1,8 @@ use lazy_static::lazy_static; use starknet::core::utils::get_storage_var_address; -use crate::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, SierraClass, StorageKey, -}; +use crate::class::{ClassHash, CompiledClass, CompiledClassHash, SierraClass}; +use crate::contract::{ContractAddress, StorageKey}; use crate::utils::class::{parse_compiled_class, parse_sierra_class}; use crate::FieldElement; diff --git a/crates/katana/primitives/src/genesis/json.rs b/crates/katana/primitives/src/genesis/json.rs index 92dce1e9c6..3efc140fa2 100644 --- a/crates/katana/primitives/src/genesis/json.rs +++ b/crates/katana/primitives/src/genesis/json.rs @@ -36,9 +36,8 @@ use super::constant::{ }; use super::{FeeTokenConfig, Genesis, GenesisAllocation, UniversalDeployerConfig}; use crate::block::{BlockHash, BlockNumber, GasPrices}; -use crate::contract::{ - ClassHash, CompiledClass, ContractAddress, SierraClass, StorageKey, StorageValue, -}; +use crate::class::{ClassHash, CompiledClass, SierraClass}; +use crate::contract::{ContractAddress, StorageKey, StorageValue}; use crate::genesis::GenesisClass; use crate::utils::class::{parse_compiled_class_v1, parse_deprecated_compiled_class}; use crate::FieldElement; diff --git a/crates/katana/primitives/src/genesis/mod.rs b/crates/katana/primitives/src/genesis/mod.rs index f75b91c858..865170f166 100644 --- a/crates/katana/primitives/src/genesis/mod.rs +++ b/crates/katana/primitives/src/genesis/mod.rs @@ -24,10 +24,8 @@ use self::constant::{ OZ_ACCOUNT_CONTRACT_PUBKEY_STORAGE_SLOT, }; use crate::block::{Block, BlockHash, BlockNumber, GasPrices, Header}; -use crate::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, StorageKey, - StorageValue, -}; +use crate::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; +use crate::contract::{ContractAddress, StorageKey, StorageValue}; use crate::state::StateUpdatesWithDeclaredClasses; use crate::utils::split_u256; use crate::version::CURRENT_STARKNET_VERSION; diff --git a/crates/katana/primitives/src/lib.rs b/crates/katana/primitives/src/lib.rs index 8ad19bdd5a..80e043914b 100644 --- a/crates/katana/primitives/src/lib.rs +++ b/crates/katana/primitives/src/lib.rs @@ -1,5 +1,6 @@ pub mod block; pub mod chain; +pub mod class; pub mod contract; pub mod env; pub mod event; diff --git a/crates/katana/primitives/src/state.rs b/crates/katana/primitives/src/state.rs index a14b445ece..16b80769f0 100644 --- a/crates/katana/primitives/src/state.rs +++ b/crates/katana/primitives/src/state.rs @@ -1,9 +1,7 @@ use std::collections::HashMap; -use crate::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, Nonce, - StorageKey, StorageValue, -}; +use crate::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; +use crate::contract::{ContractAddress, Nonce, StorageKey, StorageValue}; /// State updates. /// diff --git a/crates/katana/primitives/src/transaction.rs b/crates/katana/primitives/src/transaction.rs index 13d1466777..4493f26de1 100644 --- a/crates/katana/primitives/src/transaction.rs +++ b/crates/katana/primitives/src/transaction.rs @@ -2,9 +2,8 @@ use derive_more::{AsRef, Deref}; use ethers::types::H256; use crate::chain::ChainId; -use crate::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, Nonce, -}; +use crate::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; +use crate::contract::{ContractAddress, Nonce}; use crate::utils::transaction::{ compute_declare_v1_tx_hash, compute_declare_v2_tx_hash, compute_deploy_account_v1_tx_hash, compute_invoke_v1_tx_hash, compute_l1_handler_tx_hash, diff --git a/crates/katana/primitives/src/utils/class.rs b/crates/katana/primitives/src/utils/class.rs index fe92c31cea..de2d83e10f 100644 --- a/crates/katana/primitives/src/utils/class.rs +++ b/crates/katana/primitives/src/utils/class.rs @@ -3,7 +3,7 @@ use cairo_lang_starknet::casm_contract_class::CasmContractClass; use cairo_lang_starknet::contract_class::ContractClass; use serde_json::Value; -use crate::contract::{ +use crate::class::{ CompiledClass, DeprecatedCompiledClass, SierraClass, SierraCompiledClass, SierraProgram, }; diff --git a/crates/katana/rpc/rpc-types/src/account.rs b/crates/katana/rpc/rpc-types/src/account.rs index f7b9f3c333..d73eb48f3c 100644 --- a/crates/katana/rpc/rpc-types/src/account.rs +++ b/crates/katana/rpc/rpc-types/src/account.rs @@ -1,5 +1,6 @@ use ethers::types::U256; -use katana_primitives::contract::{ClassHash, ContractAddress}; +use katana_primitives::class::ClassHash; +use katana_primitives::contract::ContractAddress; use katana_primitives::genesis::allocation::GenesisAccountAlloc; use katana_primitives::FieldElement; use serde::{Deserialize, Serialize}; diff --git a/crates/katana/rpc/rpc-types/src/transaction.rs b/crates/katana/rpc/rpc-types/src/transaction.rs index 928e166a79..3032b84a18 100644 --- a/crates/katana/rpc/rpc-types/src/transaction.rs +++ b/crates/katana/rpc/rpc-types/src/transaction.rs @@ -3,7 +3,8 @@ use std::sync::Arc; use anyhow::Result; use derive_more::Deref; use katana_primitives::chain::ChainId; -use katana_primitives::contract::{ClassHash, ContractAddress}; +use katana_primitives::class::ClassHash; +use katana_primitives::contract::ContractAddress; use katana_primitives::conversion::rpc::{ compiled_class_hash_from_flattened_sierra_class, flattened_sierra_to_compiled_class, legacy_rpc_to_compiled_class, diff --git a/crates/katana/storage/db/benches/codec.rs b/crates/katana/storage/db/benches/codec.rs index d04b0043bc..f4e6fbe3b1 100644 --- a/crates/katana/storage/db/benches/codec.rs +++ b/crates/katana/storage/db/benches/codec.rs @@ -1,6 +1,6 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; use katana_db::codecs::{Compress, Decompress}; -use katana_primitives::contract::CompiledClass; +use katana_primitives::class::CompiledClass; use katana_primitives::utils::class::parse_compiled_class; fn compress_contract(contract: CompiledClass) -> Vec { diff --git a/crates/katana/storage/db/src/codecs/mod.rs b/crates/katana/storage/db/src/codecs/mod.rs index 622e96921b..c45a2a93f5 100644 --- a/crates/katana/storage/db/src/codecs/mod.rs +++ b/crates/katana/storage/db/src/codecs/mod.rs @@ -2,7 +2,8 @@ pub mod postcard; use katana_primitives::block::FinalityStatus; -use katana_primitives::contract::{ContractAddress, FlattenedSierraClass}; +use katana_primitives::class::FlattenedSierraClass; +use katana_primitives::contract::ContractAddress; use katana_primitives::FieldElement; use crate::error::CodecError; diff --git a/crates/katana/storage/db/src/models/class.rs b/crates/katana/storage/db/src/models/class.rs index f0d2a4a4b3..3e762f561b 100644 --- a/crates/katana/storage/db/src/models/class.rs +++ b/crates/katana/storage/db/src/models/class.rs @@ -1,4 +1,4 @@ -use katana_primitives::contract::CompiledClass; +use katana_primitives::class::CompiledClass; use crate::codecs::{Compress, Decompress}; use crate::error::CodecError; diff --git a/crates/katana/storage/db/src/models/contract.rs b/crates/katana/storage/db/src/models/contract.rs index 25c9818671..73f5025d0c 100644 --- a/crates/katana/storage/db/src/models/contract.rs +++ b/crates/katana/storage/db/src/models/contract.rs @@ -1,5 +1,6 @@ use katana_primitives::block::BlockNumber; -use katana_primitives::contract::{ClassHash, ContractAddress, Nonce}; +use katana_primitives::class::ClassHash; +use katana_primitives::contract::{ContractAddress, Nonce}; use serde::{Deserialize, Serialize}; use crate::codecs::{Compress, Decode, Decompress, Encode}; diff --git a/crates/katana/storage/db/src/tables.rs b/crates/katana/storage/db/src/tables.rs index ab601fc3a4..e9c94e1269 100644 --- a/crates/katana/storage/db/src/tables.rs +++ b/crates/katana/storage/db/src/tables.rs @@ -1,8 +1,6 @@ use katana_primitives::block::{BlockHash, BlockNumber, FinalityStatus, Header}; -use katana_primitives::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, - GenericContractInfo, StorageKey, -}; +use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; +use katana_primitives::contract::{ContractAddress, GenericContractInfo, StorageKey}; use katana_primitives::receipt::Receipt; use katana_primitives::transaction::{Tx, TxHash, TxNumber}; diff --git a/crates/katana/storage/provider/src/error.rs b/crates/katana/storage/provider/src/error.rs index 97cf5515a9..f4120f03e9 100644 --- a/crates/katana/storage/provider/src/error.rs +++ b/crates/katana/storage/provider/src/error.rs @@ -1,6 +1,7 @@ use katana_db::error::DatabaseError; use katana_primitives::block::BlockNumber; -use katana_primitives::contract::{ClassHash, ContractAddress, StorageKey}; +use katana_primitives::class::ClassHash; +use katana_primitives::contract::{ContractAddress, StorageKey}; use katana_primitives::transaction::TxNumber; use crate::providers::fork::backend::ForkedBackendError; diff --git a/crates/katana/storage/provider/src/lib.rs b/crates/katana/storage/provider/src/lib.rs index c03b4a020a..c14d1cbfbf 100644 --- a/crates/katana/storage/provider/src/lib.rs +++ b/crates/katana/storage/provider/src/lib.rs @@ -5,10 +5,8 @@ use katana_primitives::block::{ Block, BlockHash, BlockHashOrNumber, BlockNumber, BlockWithTxHashes, FinalityStatus, Header, SealedBlockWithStatus, }; -use katana_primitives::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, - GenericContractInfo, StorageKey, StorageValue, -}; +use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; +use katana_primitives::contract::{ContractAddress, GenericContractInfo, StorageKey, StorageValue}; use katana_primitives::env::BlockEnv; use katana_primitives::receipt::Receipt; use katana_primitives::state::{StateUpdates, StateUpdatesWithDeclaredClasses}; diff --git a/crates/katana/storage/provider/src/providers/db/mod.rs b/crates/katana/storage/provider/src/providers/db/mod.rs index aa02e3c015..3393133416 100644 --- a/crates/katana/storage/provider/src/providers/db/mod.rs +++ b/crates/katana/storage/provider/src/providers/db/mod.rs @@ -19,9 +19,9 @@ use katana_primitives::block::{ Block, BlockHash, BlockHashOrNumber, BlockNumber, BlockWithTxHashes, FinalityStatus, Header, SealedBlockWithStatus, }; +use katana_primitives::class::{ClassHash, CompiledClassHash}; use katana_primitives::contract::{ - ClassHash, CompiledClassHash, ContractAddress, GenericContractInfo, Nonce, StorageKey, - StorageValue, + ContractAddress, GenericContractInfo, Nonce, StorageKey, StorageValue, }; use katana_primitives::env::BlockEnv; use katana_primitives::receipt::Receipt; diff --git a/crates/katana/storage/provider/src/providers/db/state.rs b/crates/katana/storage/provider/src/providers/db/state.rs index 0c9793be00..381e60063c 100644 --- a/crates/katana/storage/provider/src/providers/db/state.rs +++ b/crates/katana/storage/provider/src/providers/db/state.rs @@ -5,9 +5,9 @@ use katana_db::models::contract::ContractInfoChangeList; use katana_db::models::storage::{ContractStorageKey, StorageEntry}; use katana_db::tables; use katana_primitives::block::BlockNumber; +use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; use katana_primitives::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, - GenericContractInfo, Nonce, StorageKey, StorageValue, + ContractAddress, GenericContractInfo, Nonce, StorageKey, StorageValue, }; use super::DbProvider; @@ -137,7 +137,7 @@ impl StateProvider for LatestStateProvider { fn class_hash_of_contract( &self, address: ContractAddress, - ) -> ProviderResult> { + ) -> ProviderResult> { let info = self.0.get::(address)?; Ok(info.map(|info| info.class_hash)) } diff --git a/crates/katana/storage/provider/src/providers/fork/backend.rs b/crates/katana/storage/provider/src/providers/fork/backend.rs index ea5a5940ed..45052b8eef 100644 --- a/crates/katana/storage/provider/src/providers/fork/backend.rs +++ b/crates/katana/storage/provider/src/providers/fork/backend.rs @@ -10,9 +10,9 @@ use futures::future::BoxFuture; use futures::stream::Stream; use futures::{Future, FutureExt}; use katana_primitives::block::BlockHashOrNumber; +use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; use katana_primitives::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, - GenericContractInfo, Nonce, StorageKey, StorageValue, + ContractAddress, GenericContractInfo, Nonce, StorageKey, StorageValue, }; use katana_primitives::conversion::rpc::{ compiled_class_hash_from_flattened_sierra_class, flattened_sierra_to_compiled_class, diff --git a/crates/katana/storage/provider/src/providers/fork/mod.rs b/crates/katana/storage/provider/src/providers/fork/mod.rs index 47c644bb26..e98bc9e1e4 100644 --- a/crates/katana/storage/provider/src/providers/fork/mod.rs +++ b/crates/katana/storage/provider/src/providers/fork/mod.rs @@ -9,9 +9,8 @@ use katana_primitives::block::{ Block, BlockHash, BlockHashOrNumber, BlockNumber, BlockWithTxHashes, FinalityStatus, Header, SealedBlockWithStatus, }; -use katana_primitives::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, -}; +use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; +use katana_primitives::contract::ContractAddress; use katana_primitives::env::BlockEnv; use katana_primitives::receipt::Receipt; use katana_primitives::state::{StateUpdates, StateUpdatesWithDeclaredClasses}; diff --git a/crates/katana/storage/provider/src/providers/fork/state.rs b/crates/katana/storage/provider/src/providers/fork/state.rs index 3593cda493..ba35a010d5 100644 --- a/crates/katana/storage/provider/src/providers/fork/state.rs +++ b/crates/katana/storage/provider/src/providers/fork/state.rs @@ -1,8 +1,8 @@ use std::sync::Arc; +use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; use katana_primitives::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, - GenericContractInfo, Nonce, StorageKey, StorageValue, + ContractAddress, GenericContractInfo, Nonce, StorageKey, StorageValue, }; use super::backend::SharedStateProvider; diff --git a/crates/katana/storage/provider/src/providers/in_memory/cache.rs b/crates/katana/storage/provider/src/providers/in_memory/cache.rs index 01e44a924e..82e493ab4c 100644 --- a/crates/katana/storage/provider/src/providers/in_memory/cache.rs +++ b/crates/katana/storage/provider/src/providers/in_memory/cache.rs @@ -3,10 +3,8 @@ use std::sync::Arc; use katana_db::models::block::StoredBlockBodyIndices; use katana_primitives::block::{BlockHash, BlockNumber, FinalityStatus, Header}; -use katana_primitives::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, - GenericContractInfo, StorageKey, StorageValue, -}; +use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; +use katana_primitives::contract::{ContractAddress, GenericContractInfo, StorageKey, StorageValue}; use katana_primitives::receipt::Receipt; use katana_primitives::state::{StateUpdates, StateUpdatesWithDeclaredClasses}; use katana_primitives::transaction::{Tx, TxHash, TxNumber}; diff --git a/crates/katana/storage/provider/src/providers/in_memory/mod.rs b/crates/katana/storage/provider/src/providers/in_memory/mod.rs index e52898c6ca..ae9b0873bf 100644 --- a/crates/katana/storage/provider/src/providers/in_memory/mod.rs +++ b/crates/katana/storage/provider/src/providers/in_memory/mod.rs @@ -9,9 +9,8 @@ use katana_primitives::block::{ Block, BlockHash, BlockHashOrNumber, BlockNumber, BlockWithTxHashes, FinalityStatus, Header, SealedBlockWithStatus, }; -use katana_primitives::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, -}; +use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; +use katana_primitives::contract::ContractAddress; use katana_primitives::env::BlockEnv; use katana_primitives::receipt::Receipt; use katana_primitives::state::{StateUpdates, StateUpdatesWithDeclaredClasses}; diff --git a/crates/katana/storage/provider/src/providers/in_memory/state.rs b/crates/katana/storage/provider/src/providers/in_memory/state.rs index 195adbedf2..a481d7c21f 100644 --- a/crates/katana/storage/provider/src/providers/in_memory/state.rs +++ b/crates/katana/storage/provider/src/providers/in_memory/state.rs @@ -2,9 +2,9 @@ use std::collections::{HashMap, VecDeque}; use std::sync::Arc; use katana_primitives::block::BlockNumber; +use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; use katana_primitives::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, - GenericContractInfo, Nonce, StorageKey, StorageValue, + ContractAddress, GenericContractInfo, Nonce, StorageKey, StorageValue, }; use super::cache::{CacheSnapshotWithoutClasses, CacheStateDb, SharedContractClasses}; diff --git a/crates/katana/storage/provider/src/traits/contract.rs b/crates/katana/storage/provider/src/traits/contract.rs index d832b33063..7ff77f1999 100644 --- a/crates/katana/storage/provider/src/traits/contract.rs +++ b/crates/katana/storage/provider/src/traits/contract.rs @@ -1,7 +1,5 @@ -use katana_primitives::contract::{ - ClassHash, CompiledClass, CompiledClassHash, ContractAddress, FlattenedSierraClass, - GenericContractInfo, -}; +use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; +use katana_primitives::contract::{ContractAddress, GenericContractInfo}; use crate::ProviderResult; diff --git a/crates/katana/storage/provider/src/traits/state.rs b/crates/katana/storage/provider/src/traits/state.rs index 279769d71b..3ec9aade09 100644 --- a/crates/katana/storage/provider/src/traits/state.rs +++ b/crates/katana/storage/provider/src/traits/state.rs @@ -1,5 +1,6 @@ use katana_primitives::block::BlockHashOrNumber; -use katana_primitives::contract::{ClassHash, ContractAddress, Nonce, StorageKey, StorageValue}; +use katana_primitives::class::ClassHash; +use katana_primitives::contract::{ContractAddress, Nonce, StorageKey, StorageValue}; use katana_primitives::FieldElement; use super::contract::ContractClassProvider; diff --git a/crates/katana/storage/provider/tests/class.rs b/crates/katana/storage/provider/tests/class.rs index 39c0574424..3e850b83c8 100644 --- a/crates/katana/storage/provider/tests/class.rs +++ b/crates/katana/storage/provider/tests/class.rs @@ -6,9 +6,7 @@ use fixtures::{ DOJO_WORLD_COMPILED_CLASS, DOJO_WORLD_SIERRA_CLASS, }; use katana_primitives::block::{BlockHashOrNumber, BlockNumber}; -use katana_primitives::contract::{ - ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass, -}; +use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; use katana_primitives::genesis::constant::{ DEFAULT_LEGACY_ERC20_CONTRACT_CASM, DEFAULT_LEGACY_UDC_CASM, }; diff --git a/crates/katana/storage/provider/tests/contract.rs b/crates/katana/storage/provider/tests/contract.rs index 57a6f428fd..2e7e874263 100644 --- a/crates/katana/storage/provider/tests/contract.rs +++ b/crates/katana/storage/provider/tests/contract.rs @@ -5,7 +5,8 @@ use fixtures::{ db_provider, fork_provider_with_spawned_fork_network, in_memory_provider, provider_with_states, }; use katana_primitives::block::{BlockHashOrNumber, BlockNumber}; -use katana_primitives::contract::{ClassHash, ContractAddress, Nonce}; +use katana_primitives::class::ClassHash; +use katana_primitives::contract::{ContractAddress, Nonce}; use katana_provider::providers::fork::ForkedProvider; use katana_provider::providers::in_memory::InMemoryProvider; use katana_provider::traits::state::{StateFactoryProvider, StateProvider}; diff --git a/crates/katana/storage/provider/tests/fixtures.rs b/crates/katana/storage/provider/tests/fixtures.rs index a1591fceed..d6334f61ce 100644 --- a/crates/katana/storage/provider/tests/fixtures.rs +++ b/crates/katana/storage/provider/tests/fixtures.rs @@ -5,9 +5,8 @@ use katana_db::mdbx; use katana_primitives::block::{ BlockHashOrNumber, FinalityStatus, Header, SealedBlock, SealedBlockWithStatus, SealedHeader, }; -use katana_primitives::contract::{ - CompiledClass, ContractAddress, FlattenedSierraClass, SierraClass, -}; +use katana_primitives::class::{CompiledClass, FlattenedSierraClass, SierraClass}; +use katana_primitives::contract::ContractAddress; use katana_primitives::genesis::constant::{ DEFAULT_LEGACY_ERC20_CONTRACT_CASM, DEFAULT_LEGACY_UDC_CASM, };