@@ -23,6 +23,7 @@ use crate::{
2323
2424pub ( crate ) mod cassandra_db;
2525pub ( crate ) mod chain_follower;
26+ pub ( crate ) mod event_db;
2627pub ( crate ) mod signed_doc;
2728mod str_env_var;
2829
@@ -53,10 +54,6 @@ const METRICS_MEMORY_INTERVAL_DEFAULT: Duration = Duration::from_secs(1);
5354/// Default `METRICS_FOLLOWER_INTERVAL`, 1 second.
5455const METRICS_FOLLOWER_INTERVAL_DEFAULT : Duration = Duration :: from_secs ( 1 ) ;
5556
56- /// Default Event DB URL.
57- const EVENT_DB_URL_DEFAULT : & str =
58- "postgresql://postgres:postgres@localhost/catalyst_events?sslmode=disable" ;
59-
6057/// Default number of slots used as overlap when purging Live Index data.
6158const PURGE_BACKWARD_SLOT_BUFFER_DEFAULT : u64 = 100 ;
6259
@@ -119,15 +116,6 @@ struct EnvVars {
119116 /// The base path the API is served at.
120117 api_url_prefix : StringEnvVar ,
121118
122- /// The Address of the Event DB.
123- event_db_url : StringEnvVar ,
124-
125- /// The `UserName` to use for the Event DB.
126- event_db_username : Option < StringEnvVar > ,
127-
128- /// The Address of the Event DB.
129- event_db_password : Option < StringEnvVar > ,
130-
131119 /// The Config of the Persistent Cassandra DB.
132120 cassandra_persistent_db : cassandra_db:: EnvVars ,
133121
@@ -137,6 +125,9 @@ struct EnvVars {
137125 /// The Chain Follower configuration
138126 chain_follower : chain_follower:: EnvVars ,
139127
128+ /// The event db configuration
129+ event_db : event_db:: EnvVars ,
130+
140131 /// The Catalyst Signed Documents configuration
141132 signed_doc : signed_doc:: EnvVars ,
142133
@@ -203,9 +194,7 @@ static ENV_VARS: LazyLock<EnvVars> = LazyLock::new(|| {
203194 client_id_key : StringEnvVar :: new ( "CLIENT_ID_KEY" , CLIENT_ID_KEY_DEFAULT . into ( ) ) ,
204195 api_host_names : StringEnvVar :: new_optional ( "API_HOST_NAMES" , false ) ,
205196 api_url_prefix : StringEnvVar :: new ( "API_URL_PREFIX" , API_URL_PREFIX_DEFAULT . into ( ) ) ,
206- event_db_url : StringEnvVar :: new ( "EVENT_DB_URL" , EVENT_DB_URL_DEFAULT . into ( ) ) ,
207- event_db_username : StringEnvVar :: new_optional ( "EVENT_DB_USERNAME" , false ) ,
208- event_db_password : StringEnvVar :: new_optional ( "EVENT_DB_PASSWORD" , true ) ,
197+
209198 cassandra_persistent_db : cassandra_db:: EnvVars :: new (
210199 cassandra_db:: PERSISTENT_URL_DEFAULT ,
211200 cassandra_db:: PERSISTENT_NAMESPACE_DEFAULT ,
@@ -215,6 +204,7 @@ static ENV_VARS: LazyLock<EnvVars> = LazyLock::new(|| {
215204 cassandra_db:: VOLATILE_NAMESPACE_DEFAULT ,
216205 ) ,
217206 chain_follower : chain_follower:: EnvVars :: new ( ) ,
207+ event_db : event_db:: EnvVars :: new ( ) ,
218208 signed_doc : signed_doc:: EnvVars :: new ( ) ,
219209 internal_api_key : StringEnvVar :: new_optional ( "INTERNAL_API_KEY" , true ) ,
220210 check_config_tick : StringEnvVar :: new_as_duration (
@@ -248,7 +238,7 @@ impl EnvVars {
248238 pub ( crate ) fn validate ( ) -> anyhow:: Result < ( ) > {
249239 let mut status = Ok ( ( ) ) ;
250240
251- let url = ENV_VARS . event_db_url . as_str ( ) ;
241+ let url = ENV_VARS . event_db . url . as_str ( ) ;
252242 if let Err ( error) = tokio_postgres:: config:: Config :: from_str ( url) {
253243 error ! ( error=%error, url=url, "Invalid Postgres DB URL." ) ;
254244 status = Err ( anyhow ! ( "Environment Variable Validation Error." ) ) ;
@@ -284,19 +274,44 @@ impl Settings {
284274 }
285275
286276 /// Get the current Event DB settings for this service.
287- pub ( crate ) fn event_db_settings ( ) -> ( & ' static str , Option < & ' static str > , Option < & ' static str > )
288- {
289- let url = ENV_VARS . event_db_url . as_str ( ) ;
277+ pub ( crate ) fn event_db_settings ( ) -> (
278+ & ' static str ,
279+ Option < & ' static str > ,
280+ Option < & ' static str > ,
281+ u32 ,
282+ u32 ,
283+ u32 ,
284+ u32 ,
285+ ) {
286+ let url = ENV_VARS . event_db . url . as_str ( ) ;
290287 let user = ENV_VARS
291- . event_db_username
288+ . event_db
289+ . username
292290 . as_ref ( )
293291 . map ( StringEnvVar :: as_str) ;
294292 let pass = ENV_VARS
295- . event_db_password
293+ . event_db
294+ . password
296295 . as_ref ( )
297296 . map ( StringEnvVar :: as_str) ;
298297
299- ( url, user, pass)
298+ let max_connections = ENV_VARS . event_db . max_connections ;
299+
300+ let max_lifetime = ENV_VARS . event_db . max_lifetime ;
301+
302+ let min_idle = ENV_VARS . event_db . min_idle ;
303+
304+ let connection_timeout = ENV_VARS . event_db . connection_timeout ;
305+
306+ (
307+ url,
308+ user,
309+ pass,
310+ max_connections,
311+ max_lifetime,
312+ min_idle,
313+ connection_timeout,
314+ )
300315 }
301316
302317 /// Get the Persistent & Volatile Cassandra DB config for this service.
0 commit comments