cdk_mintd/env_vars/
info.rs1use std::env;
4use std::str::FromStr;
5
6use cdk_common::common::QuoteTTL;
7
8use super::common::*;
9use crate::config::{Info, LoggingOutput};
10
11impl Info {
12 pub fn from_env(mut self) -> Self {
13 if let Ok(url) = env::var(ENV_URL) {
15 self.url = url;
16 }
17
18 if let Ok(host) = env::var(ENV_LISTEN_HOST) {
19 self.listen_host = host;
20 }
21
22 if let Ok(port_str) = env::var(ENV_LISTEN_PORT) {
23 if let Ok(port) = port_str.parse() {
24 self.listen_port = port;
25 }
26 }
27
28 if let Ok(seed) = env::var(ENV_SEED) {
29 self.seed = Some(seed);
30 }
31
32 if let Ok(mnemonic) = env::var(ENV_MNEMONIC) {
33 self.mnemonic = Some(mnemonic);
34 }
35
36 if let Ok(cache_seconds_str) = env::var(ENV_CACHE_SECONDS) {
37 if let Ok(seconds) = cache_seconds_str.parse() {
38 self.http_cache.ttl = Some(seconds);
39 }
40 }
41
42 if let Ok(extend_cache_str) = env::var(ENV_EXTEND_CACHE_SECONDS) {
43 if let Ok(seconds) = extend_cache_str.parse() {
44 self.http_cache.tti = Some(seconds);
45 }
46 }
47
48 if let Ok(fee_str) = env::var(ENV_INPUT_FEE_PPK) {
49 if let Ok(fee) = fee_str.parse() {
50 self.input_fee_ppk = Some(fee);
51 }
52 }
53
54 if let Ok(info_page_str) = env::var(ENV_ENABLE_INFO_PAGE) {
55 if let Ok(enable) = info_page_str.parse() {
56 self.enable_info_page = Some(enable);
57 }
58 }
59
60 if let Ok(use_keyset_v2_str) = env::var(ENV_USE_KEYSET_V2) {
61 if let Ok(use_keyset_v2) = use_keyset_v2_str.parse() {
62 self.use_keyset_v2 = Some(use_keyset_v2);
63 }
64 }
65
66 if let Ok(output_str) = env::var(ENV_LOGGING_OUTPUT) {
68 if let Ok(output) = LoggingOutput::from_str(&output_str) {
69 self.logging.output = output;
70 } else {
71 tracing::warn!(
72 "Invalid logging output '{}' in environment variable. Valid options: stdout, file, both",
73 output_str
74 );
75 }
76 }
77
78 if let Ok(console_level) = env::var(ENV_LOGGING_CONSOLE_LEVEL) {
79 self.logging.console_level = Some(console_level);
80 }
81
82 if let Ok(file_level) = env::var(ENV_LOGGING_FILE_LEVEL) {
83 self.logging.file_level = Some(file_level);
84 }
85
86 self.http_cache = self.http_cache.from_env();
87
88 let mut mint_ttl_env: Option<u64> = None;
90 let mut melt_ttl_env: Option<u64> = None;
91 if let Ok(mint_ttl_str) = env::var(ENV_QUOTE_TTL_MINT) {
92 if let Ok(v) = mint_ttl_str.parse::<u64>() {
93 mint_ttl_env = Some(v);
94 }
95 }
96 if let Ok(melt_ttl_str) = env::var(ENV_QUOTE_TTL_MELT) {
97 if let Ok(v) = melt_ttl_str.parse::<u64>() {
98 melt_ttl_env = Some(v);
99 }
100 }
101 if mint_ttl_env.is_some() || melt_ttl_env.is_some() {
102 let current = self.quote_ttl.unwrap_or_default();
103 self.quote_ttl = Some(QuoteTTL {
104 mint_ttl: mint_ttl_env.unwrap_or(current.mint_ttl),
105 melt_ttl: melt_ttl_env.unwrap_or(current.melt_ttl),
106 });
107 }
108
109 self
110 }
111}