Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(starknet_api): add contract class version to sierra contract #2277

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions crates/papyrus_storage/src/serialization/serializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand All @@ -979,6 +980,7 @@ impl StorageSerde for SierraContractClass {
sierra_program: Vec::<Felt>::deserialize_from(
&mut decompress_from_reader(bytes)?.as_slice(),
)?,
contract_class_version: String::deserialize_from(bytes)?,
entry_points_by_type: HashMap::<EntryPointType, Vec<EntryPoint>>::deserialize_from(
bytes,
)?,
Expand Down
2 changes: 2 additions & 0 deletions crates/papyrus_storage/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct DumpDeclaredClass {
class_hash: ClassHash,
compiled_class_hash: CompiledClassHash,
sierra_program: Vec<Felt>,
contract_class_version: String,
entry_points_by_type: HashMap<EntryPointType, Vec<EntryPoint>>,
}

Expand Down Expand Up @@ -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(),
},
)?;
Expand Down
3 changes: 3 additions & 0 deletions crates/papyrus_storage/src/utils_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand Down Expand Up @@ -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(),
},
];
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 @@ -498,6 +498,7 @@ auto_impl_get_test_instance! {
pub struct ContractAddressSalt(pub StarkHash);
pub struct SierraContractClass {
pub sierra_program: Vec<Felt>,
pub contract_class_version: String,
pub entry_points_by_type: HashMap<EntryPointType, Vec<EntryPoint>>,
pub abi: String,
}
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 @@ -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<Felt>,
pub contract_class_version: String,
pub entry_points_by_type: HashMap<EntryPointType, Vec<EntryPoint>>,
pub abi: String,
}
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 @@ -67,6 +67,7 @@ impl From<ContractClass> 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,
}
Expand Down
Loading