From 8203a5f0c5ecda04a553c3159589caa3f5bf4db5 Mon Sep 17 00:00:00 2001 From: Dori Medini Date: Thu, 26 Sep 2024 13:13:31 +0300 Subject: [PATCH] feat(native_blockifier): expose the starknet version (for VC) to python Signed-off-by: Dori Medini --- crates/blockifier/src/versioned_constants.rs | 16 +++++++++++++++- crates/native_blockifier/src/lib.rs | 8 ++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/blockifier/src/versioned_constants.rs b/crates/blockifier/src/versioned_constants.rs index f1617e05f9..4052af36a5 100644 --- a/crates/blockifier/src/versioned_constants.rs +++ b/crates/blockifier/src/versioned_constants.rs @@ -44,6 +44,20 @@ macro_rules! define_versioned_constants { $(StarknetVersion::$variant => $path_to_json,)* } } + + pub fn latest() -> Self { + StarknetVersion::$latest_variant + } + } + + impl From 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. @@ -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()) } } diff --git a/crates/native_blockifier/src/lib.rs b/crates/native_blockifier/src/lib.rs index 8ce52197ed..082826e745 100644 --- a/crates/native_blockifier/src/lib.rs +++ b/crates/native_blockifier/src/lib.rs @@ -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; @@ -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)]. @@ -74,3 +76,9 @@ fn native_blockifier(py: Python<'_>, py_module: &PyModule) -> PyResult<()> { pub fn blockifier_version() -> PyResult { Ok(env!("CARGO_PKG_VERSION").to_string()) } + +/// Returns the latest Starknet version for versioned constants. +#[pyfunction] +pub fn starknet_version() -> PyResult { + Ok(StarknetVersion::latest().into()) +}