diff --git a/Cargo.toml b/Cargo.toml index ef9ff0a..21c46f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] clap = { version = "4.4.11", features = ["cargo"] } - +config = { version = "*", path = "./config" } [workspace] diff --git a/config/src/lib.rs b/config/src/lib.rs index 94dff8c..9291733 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -1,5 +1,8 @@ use serde::Deserialize; -use std::{io, path::PathBuf}; +use std::{ + io::{self}, + path::PathBuf, +}; use toml::from_str; #[derive(Debug, Deserialize)] @@ -75,39 +78,44 @@ impl Config { let contents = std::fs::read_to_string(path)?; Ok(from_str(&contents)?) } -} - -#[cfg(test)] -mod tests { - use std::io::Write; - - use super::*; - fn temp_config_file() { - let mut p = std::env::temp_dir(); - p.push("./config.toml"); - let mut file = std::fs::File::create(p).expect("Failed to create temp config file"); - file.write_all( - b" -[network] + pub fn default_file() -> &'static [u8] { + b"[network] port = 37771 max_connections = 10 moniker = '' + [nostr] port = 443 bootstraps = [] max_ws_connections = 100 + [rpc] enable_grpc = true grpc_port = 9090 + [metrics] enable_metrics = false + [log] write_to_file = true path = 'log.r7' - ", - ) - .expect("Failed to write to temp config file") +" + } +} + +#[cfg(test)] +mod tests { + use std::io::Write; + + use super::*; + + fn temp_config_file() { + let mut p = std::env::temp_dir(); + p.push("./config.toml"); + let mut file = std::fs::File::create(p).expect("Failed to create temp config file"); + file.write_all(Config::default_file()) + .expect("Failed to write to temp config file") } #[test] diff --git a/rpc/src/server.rs b/rpc/src/server.rs index afd3667..2644c0a 100644 --- a/rpc/src/server.rs +++ b/rpc/src/server.rs @@ -1,3 +1,4 @@ +use config::RpcConfig; use std::io; use tonic::transport::Server; @@ -8,8 +9,8 @@ use crate::nostr; use crate::nostr::nostr::nostr_rpc_server::NostrRpcServer; #[tokio::main] -pub async fn start(port: u16) -> Result<(), io::Error> { - let addr = format!("[::1]:{}", port).parse().unwrap(); +pub async fn start(cfg: RpcConfig) -> Result<(), io::Error> { + let addr = format!("[::1]:{}", cfg.grpc_port).parse().unwrap(); let network_service = network::NetworkService::default(); let nostr_rpc_service = nostr::NostrRpcService::default();