Skip to content

Commit

Permalink
update: added env_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Dec 8, 2024
1 parent 2c47281 commit d4540fc
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"crates/starknet-os",
"crates/starknet-os-types",
"tests",
"crates/utils",
]

[workspace.package]
Expand All @@ -31,13 +32,19 @@ assert_matches = "1.5.0"
base64 = "0.21.3"
bitvec = { version = "1.0.1", features = ["serde"] }
# Point to the latest commit of branch msl/backport-secp-patches-0.8.0-rc.3
blockifier = { git = "https://github.com/Moonsong-Labs/sequencer", rev = "6624e910c57db9a16f1607c1ed26f7d8f1114e73", features = ["testing"] }
blockifier = { git = "https://github.com/Moonsong-Labs/sequencer", rev = "6624e910c57db9a16f1607c1ed26f7d8f1114e73", features = [
"testing",
] }
cairo-lang-starknet = { version = "=2.8.2" }
cairo-lang-starknet-classes = { version = "=2.8.2" }
cairo-lang-utils = { version = "=2.8.2" }
cairo-lang-casm = { version = "=2.8.2" }
cairo-type-derive = { version = "0.1.0", path = "crates/cairo-type-derive" }
cairo-vm = { git = "https://github.com/Moonsong-Labs/cairo-vm", branch = "notlesh/snos-2024-11-04", features = ["cairo-1-hints", "extensive_hints", "mod_builtin"] }
cairo-vm = { git = "https://github.com/Moonsong-Labs/cairo-vm", branch = "notlesh/snos-2024-11-04", features = [
"cairo-1-hints",
"extensive_hints",
"mod_builtin",
] }
clap = { version = "4.5.4", features = ["derive"] }
c-kzg = { version = "1.0.3" }
env_logger = "0.11.3"
Expand Down Expand Up @@ -68,11 +75,14 @@ serde_with = "3.3.0"
serde_yaml = "0.9.25"
sha2 = "0.10.8"
starknet = "0.11.0"
starknet_api = { git = "https://github.com/Moonsong-Labs/sequencer", rev = "6624e910c57db9a16f1607c1ed26f7d8f1114e73", features = ["testing"] }
starknet_api = { git = "https://github.com/Moonsong-Labs/sequencer", rev = "6624e910c57db9a16f1607c1ed26f7d8f1114e73", features = [
"testing",
] }
starknet-core = "0.11.1"
starknet-crypto = "0.6.2"
starknet-os = { path = "crates/starknet-os" }
starknet-os-types = { path = "crates/starknet-os-types" }
utils = { path = "crates/utils" }
starknet-types-core = "0.1.5"
thiserror = "1.0.48"
tokio = { version = "1.37.0", features = ["rt-multi-thread"] }
Expand Down
1 change: 1 addition & 0 deletions crates/rpc-replay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ serde_json = { workspace = true }
starknet = { workspace = true }
starknet_api = { workspace = true }
starknet-os-types = { workspace = true }
utils = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }

Expand Down
18 changes: 12 additions & 6 deletions crates/rpc-replay/src/block_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use starknet::core::types::{BlockWithTxs, Felt, L1DataAvailabilityMode};
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::core::{ChainId, ContractAddress, PatriciaKey};
use starknet_api::{contract_address, felt, patricia_key};
use utils::env_utils::get_env_var_or_default;

use crate::utils::{felt_to_u128, FeltConversionError};

Expand Down Expand Up @@ -49,16 +50,21 @@ pub fn build_block_context(
use_kzg_da,
};

let strk_fee_token_address = get_env_var_or_default(
"SNOS_STRK_FEE_TOKEN_ADDRESS",
"0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
);
let eth_fee_token_address = get_env_var_or_default(
"SNOS_ETH_FEE_TOKEN_ADDRESS",
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
);

let chain_info = ChainInfo {
chain_id,
// cf. https://docs.starknet.io/tools/important-addresses/
fee_token_addresses: FeeTokenAddresses {
strk_fee_token_address: contract_address!(
"0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
),
eth_fee_token_address: contract_address!(
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
),
strk_fee_token_address: contract_address!(strk_fee_token_address.as_str()),
eth_fee_token_address: contract_address!(eth_fee_token_address.as_str()),
},
};

Expand Down
9 changes: 9 additions & 0 deletions crates/utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "utils"
version.workspace = true
edition.workspace = true
repository.workspace = true
license.workspace = true
license-file.workspace = true

[dependencies]
27 changes: 27 additions & 0 deletions crates/utils/src/env_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::env::VarError;

pub fn get_env_var(key: &str) -> Result<String, VarError> {
std::env::var(key)
}

pub fn get_env_var_or_panic(key: &str) -> String {
get_env_var(key).unwrap_or_else(|e| panic!("Failed to get env var {}: {}", key, e))
}

pub fn get_env_var_or_default(key: &str, default: &str) -> String {
get_env_var(key).unwrap_or(default.to_string())
}

pub fn get_env_var_optional(key: &str) -> Result<Option<String>, VarError> {
match get_env_var(key) {
// if value is empty string, return None
Ok(s) if s.is_empty() => Ok(None),
Ok(s) => Ok(Some(s)),
Err(VarError::NotPresent) => Ok(None),
Err(e) => Err(e),
}
}

pub fn get_env_car_optional_or_panic(key: &str) -> Option<String> {
get_env_var_optional(key).unwrap_or_else(|e| panic!("Failed to get env var {}: {}", key, e))
}
1 change: 1 addition & 0 deletions crates/utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod env_utils;

0 comments on commit d4540fc

Please sign in to comment.