-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathenv.rs
53 lines (46 loc) · 1.62 KB
/
env.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use envy::Error::MissingValue;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
pub struct Environment {
#[serde(default = "default_blobscan_api_endpoint")]
pub blobscan_api_endpoint: String,
#[serde(default = "default_beacon_node_endpoint")]
pub beacon_node_endpoint: String,
#[serde(default = "default_execution_node_endpoint")]
pub execution_node_endpoint: String,
pub secret_key: String,
#[serde(default = "default_dencun_fork_slot")]
pub dencun_fork_slot: u32,
pub sentry_dsn: Option<String>,
}
fn default_blobscan_api_endpoint() -> String {
"http://localhost:3001".to_string()
}
fn default_beacon_node_endpoint() -> String {
"http://localhost:3500".to_string()
}
fn default_execution_node_endpoint() -> String {
"http://localhost:8545".to_string()
}
fn default_dencun_fork_slot() -> u32 {
0
}
impl Environment {
pub fn from_env() -> Result<Self, envy::Error> {
match envy::from_env::<Environment>() {
Ok(config) => {
if config.beacon_node_endpoint.is_empty() {
return Err(MissingValue("BEACON_NODE_ENDPOINT"));
} else if config.blobscan_api_endpoint.is_empty() {
return Err(MissingValue("BLOBSCAN_API_ENDPOINT"));
} else if config.execution_node_endpoint.is_empty() {
return Err(MissingValue("EXECUTION_NODE_ENDPOINT"));
} else if config.secret_key.is_empty() {
return Err(MissingValue("SECRET_KEY"));
}
Ok(config)
}
Err(err) => Err(err),
}
}
}