diff --git a/Cargo.toml b/Cargo.toml index fad25fe0e..86cb87cfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,11 @@ authors = ["Ignotus Peverell <igno.peverell@protonmail.com>"] [workspace] members = ["api", "chain", "core", "grin", "p2p", "store", "util"] + +[dependencies] +grin_grin = { path = "./grin" } + +env_logger="^0.3.5" +log = "^0.3" +serde = "~0.9.10" +serde_json = "~0.9.9" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 000000000..e26e77f1d --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +hard_tabs = true +wrap_comments = true +write_mode = "Overwrite" diff --git a/src/bin/node.rs b/src/bin/node.rs index bebf83211..2dcc83ca8 100644 --- a/src/bin/node.rs +++ b/src/bin/node.rs @@ -14,5 +14,50 @@ //! Main for building the binary of a Grin peer-to-peer node. +#[macro_use] +extern crate log; +extern crate env_logger; +extern crate serde; +extern crate serde_json; + +extern crate grin_grin as grin; + +const GRIN_HOME: &'static str = ".grin"; + +use std::env; +use std::thread; +use std::io::Read; +use std::fs::File; +use std::time::Duration; + fn main() { + env_logger::init().unwrap(); + + info!("Starting the Grin server..."); + grin::Server::start(read_config()).unwrap(); + + loop { + thread::sleep(Duration::from_secs(60)); + } +} + +fn read_config() -> grin::ServerConfig { + let mut config_path = env::home_dir().ok_or("Failed to detect home directory!").unwrap(); + config_path.push(GRIN_HOME); + if !config_path.exists() { + return default_config(); + } + let mut config_file = File::open(config_path).unwrap(); + let mut config_content = String::new(); + config_file.read_to_string(&mut config_content).unwrap(); + serde_json::from_str(config_content.as_str()).unwrap() +} + +fn default_config() -> grin::ServerConfig { + grin::ServerConfig { + cuckoo_size: 12, + seeding_type: grin::Seeding::WebStatic, + enable_mining: false, + ..Default::default() + } }