diff --git a/crates/papyrus_protobuf/src/converters/class.rs b/crates/papyrus_protobuf/src/converters/class.rs index 770f2bdee9..b7cca8aac1 100644 --- a/crates/papyrus_protobuf/src/converters/class.rs +++ b/crates/papyrus_protobuf/src/converters/class.rs @@ -207,6 +207,8 @@ impl TryFrom for state::SierraContractClass { let sierra_program = value.program.into_iter().map(Felt::try_from).collect::, _>>()?; + let contract_class_version = value.contract_class_version; + let mut entry_points_by_type = HashMap::new(); let entry_points = value.entry_points.clone().ok_or(ProtobufConversionError::MissingField { @@ -243,7 +245,12 @@ impl TryFrom for state::SierraContractClass { ); } - Ok(state::SierraContractClass { sierra_program, entry_points_by_type, abi }) + Ok(state::SierraContractClass { + sierra_program, + entry_points_by_type, + abi, + contract_class_version, + }) } } @@ -282,15 +289,7 @@ impl From for protobuf::Cairo1Class { .collect(), }); - let contract_class_version = format!( - "sierra-v{}.{}.{} cairo-v{}.{}.{}", - value.sierra_program[0], - value.sierra_program[1], - value.sierra_program[2], - value.sierra_program[3], - value.sierra_program[4], - value.sierra_program[5] - ); + let contract_class_version = value.contract_class_version; protobuf::Cairo1Class { abi, program, entry_points, contract_class_version } } diff --git a/crates/papyrus_storage/src/serialization/serializers.rs b/crates/papyrus_storage/src/serialization/serializers.rs index d4dab673a5..6a76f7fc9b 100644 --- a/crates/papyrus_storage/src/serialization/serializers.rs +++ b/crates/papyrus_storage/src/serialization/serializers.rs @@ -969,6 +969,7 @@ impl StorageSerde for TransactionOffsetInBlock { impl StorageSerde for SierraContractClass { fn serialize_into(&self, res: &mut impl std::io::Write) -> Result<(), StorageSerdeError> { serialize_and_compress(&self.sierra_program)?.serialize_into(res)?; + self.contract_class_version.serialize_into(res)?; self.entry_points_by_type.serialize_into(res)?; serialize_and_compress(&self.abi)?.serialize_into(res)?; Ok(()) @@ -979,6 +980,7 @@ impl StorageSerde for SierraContractClass { sierra_program: Vec::::deserialize_from( &mut decompress_from_reader(bytes)?.as_slice(), )?, + contract_class_version: String::deserialize_from(bytes)?, entry_points_by_type: HashMap::>::deserialize_from( bytes, )?, diff --git a/crates/papyrus_storage/src/utils.rs b/crates/papyrus_storage/src/utils.rs index 508756cc97..2348137434 100644 --- a/crates/papyrus_storage/src/utils.rs +++ b/crates/papyrus_storage/src/utils.rs @@ -27,6 +27,7 @@ struct DumpDeclaredClass { class_hash: ClassHash, compiled_class_hash: CompiledClassHash, sierra_program: Vec, + contract_class_version: String, entry_points_by_type: HashMap>, } @@ -77,6 +78,7 @@ fn dump_declared_classes_table_by_block_range_internal( class_hash: *class_hash, compiled_class_hash: *compiled_class_hash, sierra_program: contract_class.sierra_program.clone(), + contract_class_version: contract_class.contract_class_version.clone(), entry_points_by_type: contract_class.entry_points_by_type.clone(), }, )?; diff --git a/crates/papyrus_storage/src/utils_test.rs b/crates/papyrus_storage/src/utils_test.rs index 157e2e7efd..33fede7061 100644 --- a/crates/papyrus_storage/src/utils_test.rs +++ b/crates/papyrus_storage/src/utils_test.rs @@ -32,6 +32,7 @@ fn test_dump_declared_classes() { ClassHash(i_felt), SierraContractClass { sierra_program: vec![i_felt, i_felt], + contract_class_version: "0.1.0".to_string(), entry_points_by_type: HashMap::new(), abi: "".to_string(), }, @@ -66,12 +67,14 @@ fn test_dump_declared_classes() { class_hash: declared_classes[2].0, compiled_class_hash, sierra_program: declared_classes[2].1.sierra_program.clone(), + contract_class_version: declared_classes[2].1.contract_class_version.clone(), entry_points_by_type: declared_classes[2].1.entry_points_by_type.clone(), }, DumpDeclaredClass { class_hash: declared_classes[3].0, compiled_class_hash, sierra_program: declared_classes[3].1.sierra_program.clone(), + contract_class_version: declared_classes[3].1.contract_class_version.clone(), entry_points_by_type: declared_classes[3].1.entry_points_by_type.clone(), }, ]; diff --git a/crates/papyrus_test_utils/src/lib.rs b/crates/papyrus_test_utils/src/lib.rs index 08f6bb9855..8c2b2f7948 100644 --- a/crates/papyrus_test_utils/src/lib.rs +++ b/crates/papyrus_test_utils/src/lib.rs @@ -498,6 +498,7 @@ auto_impl_get_test_instance! { pub struct ContractAddressSalt(pub StarkHash); pub struct SierraContractClass { pub sierra_program: Vec, + pub contract_class_version: String, pub entry_points_by_type: HashMap>, pub abi: String, } diff --git a/crates/starknet_api/src/state.rs b/crates/starknet_api/src/state.rs index e0e37067a0..3216ed90f1 100644 --- a/crates/starknet_api/src/state.rs +++ b/crates/starknet_api/src/state.rs @@ -213,6 +213,7 @@ impl_from_through_intermediate!(u128, StorageKey, u8, u16, u32, u64); #[derive(Debug, Clone, Default, Eq, PartialEq, Deserialize, Serialize)] pub struct SierraContractClass { pub sierra_program: Vec, + pub contract_class_version: String, pub entry_points_by_type: HashMap>, pub abi: String, } diff --git a/crates/starknet_client/src/reader/objects/state.rs b/crates/starknet_client/src/reader/objects/state.rs index 67ad35b75b..eb70e036f3 100644 --- a/crates/starknet_client/src/reader/objects/state.rs +++ b/crates/starknet_client/src/reader/objects/state.rs @@ -67,6 +67,7 @@ impl From for starknet_api::state::SierraContractClass { fn from(class: ContractClass) -> Self { Self { sierra_program: class.sierra_program, + contract_class_version: class.contract_class_version, entry_points_by_type: class.entry_points_by_type, abi: class.abi, }