Skip to content

Commit

Permalink
feat(native_blockifier): expose the starknet version (for VC) to python
Browse files Browse the repository at this point in the history
Signed-off-by: Dori Medini <[email protected]>
  • Loading branch information
dorimedini-starkware committed Sep 26, 2024
1 parent a225951 commit 8203a5f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/blockifier/src/versioned_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ macro_rules! define_versioned_constants {
$(StarknetVersion::$variant => $path_to_json,)*
}
}

pub fn latest() -> Self {
StarknetVersion::$latest_variant
}
}

impl From<StarknetVersion> for String {
fn from(version: StarknetVersion) -> Self {
match version {
$(StarknetVersion::$variant => String::from(
stringify!($variant)
).to_lowercase().replace("_", "."),)*
}
}
}

// Static (lazy) instances of the versioned constants.
Expand Down Expand Up @@ -76,7 +90,7 @@ macro_rules! define_versioned_constants {
/// Get the constants that shipped with the current version of the Blockifier.
/// To use custom constants, initialize the struct from a file using `try_from`.
pub fn latest_constants() -> &'static Self {
Self::get(StarknetVersion::$latest_variant)
Self::get(StarknetVersion::latest())
}
}

Expand Down
8 changes: 8 additions & 0 deletions crates/native_blockifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod state_readers;
pub mod storage;
pub mod test_utils;

use blockifier::versioned_constants::StarknetVersion;
use errors::{add_py_exceptions, UndeclaredClassHashError};
use py_block_executor::PyBlockExecutor;
use py_objects::PyExecutionResources;
Expand Down Expand Up @@ -51,6 +52,7 @@ fn native_blockifier(py: Python<'_>, py_module: &PyModule) -> PyResult<()> {
add_py_exceptions(py, py_module)?;

py_module.add_function(wrap_pyfunction!(blockifier_version, py)?)?;
py_module.add_function(wrap_pyfunction!(starknet_version, py)?)?;

// TODO(Dori, 1/4/2023): If and when supported in the Python build environment, gate this code
// with #[cfg(test)].
Expand All @@ -74,3 +76,9 @@ fn native_blockifier(py: Python<'_>, py_module: &PyModule) -> PyResult<()> {
pub fn blockifier_version() -> PyResult<String> {
Ok(env!("CARGO_PKG_VERSION").to_string())
}

/// Returns the latest Starknet version for versioned constants.
#[pyfunction]
pub fn starknet_version() -> PyResult<String> {
Ok(StarknetVersion::latest().into())
}

0 comments on commit 8203a5f

Please sign in to comment.