Skip to content

Commit

Permalink
refactor(starknet_api): add contract class version to sierra contract
Browse files Browse the repository at this point in the history
  • Loading branch information
AvivYossef-starkware committed Nov 26, 2024
1 parent fcf5cce commit d9a5dec
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/papyrus_protobuf/src/converters/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ impl TryFrom<protobuf::Cairo1Class> for state::SierraContractClass {
let sierra_program =
value.program.into_iter().map(Felt::try_from).collect::<Result<Vec<_>, _>>()?;

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 {
Expand Down Expand Up @@ -243,7 +245,12 @@ impl TryFrom<protobuf::Cairo1Class> 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,
})
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_storage/src/serialization/serializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ impl StorageSerde for SierraContractClass {
bytes,
)?,
abi: String::deserialize_from(&mut decompress_from_reader(bytes)?.as_slice())?,
contract_class_version: String::deserialize_from(bytes)?,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_storage/src/utils_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn test_dump_declared_classes() {
declared_classes.push((
ClassHash(i_felt),
SierraContractClass {
contract_class_version: "".to_string(),
sierra_program: vec![i_felt, i_felt],
entry_points_by_type: HashMap::new(),
abi: "".to_string(),
Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ auto_impl_get_test_instance! {
pub sierra_program: Vec<Felt>,
pub entry_points_by_type: HashMap<EntryPointType, Vec<EntryPoint>>,
pub abi: String,
pub contract_class_version: String,
}
pub struct DeprecatedContractClass {
pub abi: Option<Vec<ContractClassAbiEntry>>,
Expand Down
1 change: 1 addition & 0 deletions crates/starknet_api/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ pub struct SierraContractClass {
pub sierra_program: Vec<Felt>,
pub entry_points_by_type: HashMap<EntryPointType, Vec<EntryPoint>>,
pub abi: String,
pub contract_class_version: String,
}

/// An entry point of a [ContractClass](`crate::state::ContractClass`).
Expand Down
1 change: 1 addition & 0 deletions crates/starknet_client/src/reader/objects/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub struct ContractClass {
impl From<ContractClass> for starknet_api::state::SierraContractClass {
fn from(class: ContractClass) -> Self {
Self {
contract_class_version: class.contract_class_version,
sierra_program: class.sierra_program,
entry_points_by_type: class.entry_points_by_type,
abi: class.abi,
Expand Down

0 comments on commit d9a5dec

Please sign in to comment.