Skip to content

Commit

Permalink
include json in binary
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Feb 18, 2024
1 parent 7c47b93 commit a11856f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions vm/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ cairo-lang-runner = "=2.6.0-rc.1"
cairo-lang-starknet = "=2.6.0-rc.1"
cairo-lang-utils = "=2.6.0-rc.1"

lazy_static = "1.4.0"


[lib]
crate-type = ["staticlib"]
22 changes: 15 additions & 7 deletions vm/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use blockifier::{
versioned_constants::VersionedConstants
};

use std::path::Path;
use juno_state_reader::{contract_class_from_json_str, felt_to_byte_array};
use serde::Deserialize;
use starknet_api::transaction::{Calldata, Transaction as StarknetApiTransaction, TransactionHash};
Expand All @@ -56,6 +55,17 @@ extern "C" {
const GLOBAL_CONTRACT_CACHE_SIZE: usize= 100; // Todo ? default used to set this to 100.



use lazy_static::lazy_static;
extern crate serde_json;
use std::sync::Mutex;
const VERSIONED_CONSTANTS_JSON: &'static str = include_str!("../versioned_constants.json");
lazy_static! {
static ref VERSIONED_CONSTANTS: Mutex<Result<VersionedConstants, serde_json::Error>> = Mutex::new(serde_json::from_str(VERSIONED_CONSTANTS_JSON));
}



#[no_mangle]
pub extern "C" fn cairoVMCall(
contract_address: *const c_uchar,
Expand All @@ -69,9 +79,8 @@ pub extern "C" fn cairoVMCall(
chain_id: *const c_char,
_max_steps: c_ulonglong,
) {
let path = Path::new("versioned_constants.json");
let versioned_constants_result = VersionedConstants::try_from(path);
let versioned_constants = match versioned_constants_result {
let versioned_constants = VERSIONED_CONSTANTS.lock().unwrap();
let versioned_constants = match &*versioned_constants {
Ok(constants) => constants,
Err(e) => {
println!("Failed to load versioned constants: {}", e);
Expand Down Expand Up @@ -182,9 +191,8 @@ pub extern "C" fn cairoVMExecute(
legacy_json: c_uchar,
use_kzg_da: bool // Todo: new parameter? Hardcode to true/false?
) {
let path = Path::new("versioned_constants.json");
let versioned_constants_result = VersionedConstants::try_from(path);
let versioned_constants = match versioned_constants_result {
let versioned_constants = VERSIONED_CONSTANTS.lock().unwrap();
let versioned_constants = match &*versioned_constants {
Ok(constants) => constants,
Err(e) => {
println!("Failed to load versioned constants: {}", e);
Expand Down

0 comments on commit a11856f

Please sign in to comment.