Skip to content

Commit

Permalink
chore: Removes global Lazy<Config>
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-herasme committed Jul 20, 2024
1 parent 4b7b489 commit 170721e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 29 deletions.
22 changes: 0 additions & 22 deletions ghost-crab-common/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use dotenvy::dotenv;
use once_cell::sync::Lazy;
use serde::Deserialize;
use std::collections::HashMap;
use std::{env, fs};

#[derive(Clone, Copy, Deserialize, Debug)]
#[serde(rename_all = "lowercase")]
Expand Down Expand Up @@ -46,22 +43,3 @@ pub struct Config {
pub networks: HashMap<String, String>,
pub block_handlers: HashMap<String, BlockHandler>,
}

static CONFIG_CACHE: Lazy<Config> = Lazy::new(|| {
dotenv().ok();
let current_dir = env::current_dir().unwrap();
let config_string = fs::read_to_string(current_dir.join("config.json")).unwrap();
let mut config: Config = serde_json::from_str(&config_string).unwrap();

config.networks.iter_mut().for_each(|(_key, value)| {
if value.starts_with('$') {
*value = env::var(&value[1..]).unwrap();
}
});

config
});

pub fn load() -> Config {
CONFIG_CACHE.clone()
}
8 changes: 1 addition & 7 deletions ghost-crab/src/indexer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::block_handler::{process_logs_block, BlockConfig, BlockHandlerInstance};
use crate::config;
use crate::handler::{HandleInstance, HandlerConfig};
use crate::process_logs::process_logs;
use crate::server::Server;
Expand Down Expand Up @@ -33,7 +32,6 @@ impl TemplateManager {
}

pub struct Indexer {
config: config::Config,
handlers: Vec<HandlerConfig>,
block_handlers: Vec<BlockConfig>,
rx: Receiver<HandlerConfig>,
Expand All @@ -48,20 +46,16 @@ impl Default for Indexer {

impl Indexer {
pub fn new() -> Indexer {
let config = config::load();
let (tx, rx) = mpsc::channel::<HandlerConfig>(1);

let templates = TemplateManager { tx };

let server = Server::new(3000);
server.start();

Indexer {
config: config.clone(),
handlers: Vec::new(),
block_handlers: Vec::new(),
templates: TemplateManager { tx },
rx,
templates,
}
}

Expand Down

0 comments on commit 170721e

Please sign in to comment.