use config::{Config, File, Value}; use serde::Deserialize; use std::collections::HashMap; use std::thread::available_parallelism; use crate::blockchains::Blockchain; use crate::key_generators::KeyAlgorithm; use crate::utils::DynError; #[derive(Debug, Deserialize)] pub struct Settings { pub key_generators: HashMap, pub blockchains: HashMap, pub notifications: NotificationSettings, } #[derive(Debug, Deserialize, Clone)] pub struct KeyGeneratorSettings { #[serde(default = "default_workers")] pub workers: usize, #[serde(flatten)] pub data: HashMap, } #[derive(Debug, Deserialize, Clone)] pub struct BlockchainSettings { #[serde(default = "default_workers")] pub workers: usize, #[serde(flatten)] pub data: HashMap, } fn default_workers() -> usize { available_parallelism().unwrap().get() } #[derive(Debug, Deserialize, Clone)] pub struct NotificationSettings { pub telegram_bot_token: String, pub telegram_user_id: String, } impl Settings { pub fn load(path: &str) -> Result { Config::builder() .add_source(File::with_name(path).required(false)) .build()? .try_deserialize() .map_err(|e| e.into()) } }