Skip to content

Commit

Permalink
refactor: merge multiple EntryPointType structs (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
noaov1 authored Oct 13, 2024
1 parent b862557 commit 3ae5b34
Show file tree
Hide file tree
Showing 34 changed files with 84 additions and 123 deletions.
3 changes: 1 addition & 2 deletions crates/blockifier/src/execution/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ use itertools::Itertools;
use semver::Version;
use serde::de::Error as DeserializationError;
use serde::{Deserialize, Deserializer, Serialize};
use starknet_api::contract_class::ContractClass as RawContractClass;
use starknet_api::contract_class::{ContractClass as RawContractClass, EntryPointType};
use starknet_api::core::EntryPointSelector;
use starknet_api::deprecated_contract_class::{
ContractClass as DeprecatedContractClass,
EntryPoint,
EntryPointOffset,
EntryPointType,
Program as DeprecatedProgram,
};
use starknet_types_core::felt::Felt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use cairo_vm::types::layout_name::LayoutName;
use cairo_vm::types::relocatable::{MaybeRelocatable, Relocatable};
use cairo_vm::vm::errors::vm_errors::VirtualMachineError;
use cairo_vm::vm::runners::cairo_runner::{CairoArg, CairoRunner, ExecutionResources};
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::EntryPointSelector;
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::hash::StarkHash;

use super::execution_utils::SEGMENT_ARENA_BUILTIN_SIZE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use cairo_vm::vm::errors::vm_errors::VirtualMachineError;
use cairo_vm::vm::runners::cairo_runner::{ExecutionResources, ResourceTracker, RunResources};
use cairo_vm::vm::vm_core::VirtualMachine;
use num_bigint::{BigUint, TryFromBigIntError};
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::state::StorageKey;
use starknet_api::transaction::Calldata;
use starknet_api::StarknetApiError;
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/execution/deprecated_syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use cairo_vm::types::relocatable::Relocatable;
use cairo_vm::vm::vm_core::VirtualMachine;
use serde::Deserialize;
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{
calculate_contract_address,
ClassHash,
ContractAddress,
EntryPointSelector,
EthAddress,
};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::state::StorageKey;
use starknet_api::transaction::{
Calldata,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/execution/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::sync::Arc;
use cairo_vm::vm::runners::cairo_runner::{ExecutionResources, ResourceTracker, RunResources};
use num_traits::{Inv, Zero};
use serde::Serialize;
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::state::StorageKey;
use starknet_api::transaction::{Calldata, TransactionVersion};
use starknet_types_core::felt::Felt;
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/execution/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use cairo_vm::vm::errors::runner_errors::RunnerError;
use cairo_vm::vm::errors::trace_errors::TraceError;
use cairo_vm::vm::errors::vm_errors::VirtualMachineError;
use num_bigint::{BigInt, TryFromBigIntError};
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_types_core::felt::Felt;
use thiserror::Error;

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/execution/syscalls/hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use cairo_vm::vm::errors::memory_errors::MemoryError;
use cairo_vm::vm::errors::vm_errors::VirtualMachineError;
use cairo_vm::vm::runners::cairo_runner::{ExecutionResources, ResourceTracker, RunResources};
use cairo_vm::vm::vm_core::VirtualMachine;
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::state::StorageKey;
use starknet_api::transaction::{AllResourceBounds, Calldata, Resource, ValidResourceBounds};
use starknet_api::StarknetApiError;
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/execution/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use cairo_vm::types::relocatable::{MaybeRelocatable, Relocatable};
use cairo_vm::vm::vm_core::VirtualMachine;
use num_traits::ToPrimitive;
use starknet_api::block::{BlockHash, BlockNumber};
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{
calculate_contract_address,
ClassHash,
ContractAddress,
EntryPointSelector,
EthAddress,
};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::state::StorageKey;
use starknet_api::transaction::{
Calldata,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/test_utils/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{
ClassHash,
CompiledClassHash,
Expand All @@ -8,7 +9,6 @@ use starknet_api::core::{
use starknet_api::deprecated_contract_class::{
ContractClass as DeprecatedContractClass,
EntryPointOffset,
EntryPointType,
};
use starknet_api::{class_hash, contract_address, felt, patricia_key};
use starknet_types_core::felt::Felt;
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::sync::Arc;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use starknet_api::block::GasPriceVector;
use starknet_api::calldata;
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector, Nonce};
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::transaction::Resource::{L1DataGas, L1Gas, L2Gas};
use starknet_api::transaction::{
AccountDeploymentData,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::sync::Arc;

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::transaction::{
AccountDeploymentData,
Calldata,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use num_traits::Pow;
use pretty_assertions::assert_eq;
use rstest::{fixture, rstest};
use starknet_api::block::GasPriceVector;
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ChainId, ClassHash, ContractAddress, EthAddress, Nonce, PatriciaKey};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::execution_resources::GasVector;
use starknet_api::state::StorageKey;
use starknet_api::test_utils::invoke::InvokeTxArgs;
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier_reexecution/src/state_reader/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use cairo_lang_utils::bigint::BigUintAsHex;
use cairo_vm::types::program::Program;
use flate2::bufread;
use serde::Deserialize;
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::EntryPointSelector;
use starknet_api::deprecated_contract_class::{EntryPoint, EntryPointOffset, EntryPointType};
use starknet_api::deprecated_contract_class::{EntryPoint, EntryPointOffset};
use starknet_api::hash::StarkHash;
use starknet_core::types::{
CompressedLegacyContractClass,
Expand Down
3 changes: 2 additions & 1 deletion crates/papyrus_common/src/class_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
mod class_hash_test;
use lazy_static::lazy_static;
use sha3::Digest;
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::ClassHash;
use starknet_api::hash::PoseidonHash;
use starknet_api::state::{ContractClass, EntryPointType};
use starknet_api::state::ContractClass;
use starknet_types_core::felt::Felt;
use starknet_types_core::hash::{Poseidon, StarkHash};

Expand Down
7 changes: 2 additions & 5 deletions crates/papyrus_execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,10 @@ use papyrus_storage::header::HeaderStorageReader;
use papyrus_storage::{StorageError, StorageReader};
use serde::{Deserialize, Serialize};
use starknet_api::block::{BlockNumber, NonzeroGasPrice, StarknetVersion};
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ChainId, ClassHash, ContractAddress, EntryPointSelector, PatriciaKey};
use starknet_api::data_availability::L1DataAvailabilityMode;
// TODO: merge multiple EntryPointType structs in SN_API into one.
use starknet_api::deprecated_contract_class::{
ContractClass as DeprecatedContractClass,
EntryPointType,
};
use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass;
use starknet_api::state::{StateNumber, ThinStateDiff};
use starknet_api::transaction::{
Calldata,
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_execution/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use papyrus_common::state::{
};
use serde::{Deserialize, Serialize};
use starknet_api::block::{BlockTimestamp, GasPrice, GasPricePerToken};
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{
ClassHash,
ContractAddress,
Expand All @@ -31,7 +32,6 @@ use starknet_api::core::{
SequencerContractAddress,
};
use starknet_api::data_availability::L1DataAvailabilityMode;
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::execution_resources::{
Builtin,
ExecutionResources,
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_execution/src/testing_instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
pub use blockifier::abi::abi_utils::get_storage_var_address;
use papyrus_test_utils::{auto_impl_get_test_instance, get_number_of_variants, GetTestInstance};
use starknet_api::block::GasPrice;
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector, PatriciaKey};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::execution_resources::ExecutionResources;
use starknet_api::transaction::{Calldata, EventContent, Fee, MessageToL1};
use starknet_api::{contract_address, felt, patricia_key};
Expand Down
25 changes: 13 additions & 12 deletions crates/papyrus_protobuf/src/converters/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::convert::{TryFrom, TryInto};

use papyrus_common::pending_classes::ApiContractClass;
use prost::Message;
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ClassHash, EntryPointSelector};
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::{deprecated_contract_class, state};
Expand Down Expand Up @@ -100,7 +101,7 @@ impl TryFrom<protobuf::Cairo0Class> for deprecated_contract_class::ContractClass

if !value.constructors.is_empty() {
entry_points_by_type.insert(
deprecated_contract_class::EntryPointType::Constructor,
EntryPointType::Constructor,
value
.constructors
.into_iter()
Expand All @@ -110,7 +111,7 @@ impl TryFrom<protobuf::Cairo0Class> for deprecated_contract_class::ContractClass
}
if !value.externals.is_empty() {
entry_points_by_type.insert(
deprecated_contract_class::EntryPointType::External,
EntryPointType::External,
value
.externals
.into_iter()
Expand All @@ -120,7 +121,7 @@ impl TryFrom<protobuf::Cairo0Class> for deprecated_contract_class::ContractClass
}
if !value.l1_handlers.is_empty() {
entry_points_by_type.insert(
deprecated_contract_class::EntryPointType::L1Handler,
EntryPointType::L1Handler,
value
.l1_handlers
.into_iter()
Expand All @@ -142,23 +143,23 @@ impl From<deprecated_contract_class::ContractClass> for protobuf::Cairo0Class {
protobuf::Cairo0Class {
constructors: value
.entry_points_by_type
.get(&deprecated_contract_class::EntryPointType::Constructor)
.get(&EntryPointType::Constructor)
.unwrap_or(&vec![])
.iter()
.cloned()
.map(protobuf::EntryPoint::from)
.collect(),
externals: value
.entry_points_by_type
.get(&deprecated_contract_class::EntryPointType::External)
.get(&EntryPointType::External)
.unwrap_or(&vec![])
.iter()
.cloned()
.map(protobuf::EntryPoint::from)
.collect(),
l1_handlers: value
.entry_points_by_type
.get(&deprecated_contract_class::EntryPointType::L1Handler)
.get(&EntryPointType::L1Handler)
.unwrap_or(&vec![])
.iter()
.cloned()
Expand Down Expand Up @@ -186,7 +187,7 @@ impl TryFrom<protobuf::Cairo1Class> for state::ContractClass {
})?;
if !entry_points.constructors.is_empty() {
entry_points_by_type.insert(
state::EntryPointType::Constructor,
EntryPointType::Constructor,
entry_points
.constructors
.into_iter()
Expand All @@ -196,7 +197,7 @@ impl TryFrom<protobuf::Cairo1Class> for state::ContractClass {
}
if !entry_points.externals.is_empty() {
entry_points_by_type.insert(
state::EntryPointType::External,
EntryPointType::External,
entry_points
.externals
.into_iter()
Expand All @@ -206,7 +207,7 @@ impl TryFrom<protobuf::Cairo1Class> for state::ContractClass {
}
if !entry_points.l1_handlers.is_empty() {
entry_points_by_type.insert(
state::EntryPointType::L1Handler,
EntryPointType::L1Handler,
entry_points
.l1_handlers
.into_iter()
Expand All @@ -229,7 +230,7 @@ impl From<state::ContractClass> for protobuf::Cairo1Class {
let entry_points = Some(protobuf::Cairo1EntryPoints {
constructors: value
.entry_points_by_type
.get(&state::EntryPointType::Constructor)
.get(&EntryPointType::Constructor)
.unwrap_or(&vec![])
.iter()
.cloned()
Expand All @@ -238,15 +239,15 @@ impl From<state::ContractClass> for protobuf::Cairo1Class {

externals: value
.entry_points_by_type
.get(&state::EntryPointType::External)
.get(&EntryPointType::External)
.unwrap_or(&vec![])
.iter()
.cloned()
.map(protobuf::SierraEntryPoint::from)
.collect(),
l1_handlers: value
.entry_points_by_type
.get(&state::EntryPointType::L1Handler)
.get(&EntryPointType::L1Handler)
.unwrap_or(&vec![])
.iter()
.cloned()
Expand Down
8 changes: 4 additions & 4 deletions crates/papyrus_rpc/src/v0_8/broadcasted_transaction_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use papyrus_test_utils::{
get_rng,
GetTestInstance,
};
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{CompiledClassHash, ContractAddress, Nonce};
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::deprecated_contract_class::{
ContractClassAbiEntry as DeprecatedContractClassAbiEntry,
EntryPoint as DeprecatedEntryPoint,
EntryPointType as DeprecatedEntryPointType,
EventAbiEntry,
FunctionAbiEntry,
StructAbiEntry,
Expand Down Expand Up @@ -140,15 +140,15 @@ fn declare_v1_fits_rpc() {
abi,
entry_points_by_type: HashMap::from([
(
DeprecatedEntryPointType::Constructor,
EntryPointType::Constructor,
vec![DeprecatedEntryPoint::get_test_instance(&mut rng)],
),
(
DeprecatedEntryPointType::External,
EntryPointType::External,
vec![DeprecatedEntryPoint::get_test_instance(&mut rng)],
),
(
DeprecatedEntryPointType::L1Handler,
EntryPointType::L1Handler,
vec![DeprecatedEntryPoint::get_test_instance(&mut rng)],
),
]),
Expand Down
3 changes: 2 additions & 1 deletion crates/papyrus_rpc/src/v0_8/deprecated_contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::collections::HashMap;

use papyrus_storage::db::serialization::StorageSerdeError;
use serde::{Deserialize, Serialize};
use starknet_api::deprecated_contract_class::{ContractClassAbiEntry, EntryPoint, EntryPointType};
use starknet_api::contract_class::EntryPointType;
use starknet_api::deprecated_contract_class::{ContractClassAbiEntry, EntryPoint};

use crate::compression_utils::compress_and_encode;

Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_rpc/src/v0_8/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use papyrus_execution::objects::{
TransactionTrace as ExecutionTransactionTrace,
};
use serde::{Deserialize, Serialize};
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ClassHash, ContractAddress};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::state::ThinStateDiff as StarknetApiThinStateDiff;

use super::state::ThinStateDiff;
Expand Down
6 changes: 2 additions & 4 deletions crates/papyrus_rpc/src/v0_8/execution_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use starknet_api::block::{
BlockTimestamp,
GasPricePerToken,
};
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{
ClassHash,
CompiledClassHash,
Expand All @@ -61,10 +62,7 @@ use starknet_api::core::{
SequencerContractAddress,
};
use starknet_api::data_availability::L1DataAvailabilityMode;
use starknet_api::deprecated_contract_class::{
ContractClass as SN_API_DeprecatedContractClass,
EntryPointType,
};
use starknet_api::deprecated_contract_class::ContractClass as SN_API_DeprecatedContractClass;
use starknet_api::hash::StarkHash;
use starknet_api::state::{StorageKey, ThinStateDiff as StarknetApiStateDiff};
use starknet_api::test_utils::read_json_file;
Expand Down
Loading

0 comments on commit 3ae5b34

Please sign in to comment.