use std::path::PathBuf; use nostr::{key::FromPkStr, secp256k1::XOnlyPublicKey}; #[derive(Clone, Debug)] pub struct Config { admin_pubkey: XOnlyPublicKey, db_path: PathBuf, } impl Default for Config { fn default() -> Self { panic!("Use Config::new(env_admin_pk)") } } impl Config { pub fn new() -> Self { let admin_pubkey = std::env::var("ADMIN_PUBKEY") .map(|env_pk| nostr::Keys::from_pk_str(&env_pk)) .and_then(|result| result.map_err(|err| panic!("{}", err))) .unwrap() .public_key(); let db_path = std::env::var("DATABASE_URL").map(PathBuf::from).unwrap(); Self { admin_pubkey, db_path, } } pub fn get_admin_pubkey(&self) -> &XOnlyPublicKey { &self.admin_pubkey } pub fn get_db_path(&self) -> PathBuf { self.db_path.clone() } pub fn get_relay_config_json(&self) -> serde_json::Value { serde_json::json!({ "contact": "klink@zhitno.st", "name": "zhitno.st", "description": "Very *special* nostr relay", "supported_nips": [ 1, 9, 11, 12, 15, 16, 20, 22, 28, 33, 45 ], "software": "git+https://git.zhitno.st/Klink/sneedstr.git", "version": "0.1.0" }) } }