From 97d7a43ccf42ce59bde391c233f65b8f9d4a45d2 Mon Sep 17 00:00:00 2001 From: Ignotus Peverell Date: Wed, 15 Nov 2017 17:30:48 -0500 Subject: [PATCH] Default value for ChainType, when not in grin.toml --- core/src/global.rs | 6 ++++++ grin/src/server.rs | 2 +- grin/src/types.rs | 5 +++-- src/bin/grin.rs | 6 ++---- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/src/global.rs b/core/src/global.rs index 3f55dcc74..50dd5112d 100644 --- a/core/src/global.rs +++ b/core/src/global.rs @@ -64,6 +64,12 @@ pub enum ChainTypes { Mainnet, } +impl Default for ChainTypes { + fn default() -> ChainTypes { + ChainTypes::UserTesting + } +} + lazy_static!{ /// The mining parameter mode pub static ref CHAIN_TYPE: RwLock = diff --git a/grin/src/server.rs b/grin/src/server.rs index cbc9faf55..3d6235eb1 100644 --- a/grin/src/server.rs +++ b/grin/src/server.rs @@ -91,7 +91,7 @@ impl Server { let mut genesis_block = None; if !chain::Chain::chain_exists(config.db_root.clone()) { - let chain_type = config.chain_type.clone().unwrap(); + let chain_type = config.chain_type.clone(); if chain_type == global::ChainTypes::Testnet1 { genesis_block = Some(genesis::genesis_testnet1()); } else { diff --git a/grin/src/types.rs b/grin/src/types.rs index fe697c783..3a6f67999 100644 --- a/grin/src/types.rs +++ b/grin/src/types.rs @@ -92,7 +92,8 @@ pub struct ServerConfig { pub api_http_addr: String, /// Setup the server for tests, testnet or mainnet - pub chain_type: Option, + #[serde(default)] + pub chain_type: ChainTypes, /// Method used to get the list of seed nodes for initial bootstrap. pub seeding_type: Seeding, @@ -125,7 +126,7 @@ impl Default for ServerConfig { seeds: None, p2p_config: Some(p2p::P2PConfig::default()), mining_config: Some(pow::types::MinerConfig::default()), - chain_type: Some(ChainTypes::Testnet1), + chain_type: ChainTypes::default(), pool_config: pool::PoolConfig::default(), } } diff --git a/src/bin/grin.rs b/src/bin/grin.rs index 08ac0e35e..51f6c0c40 100644 --- a/src/bin/grin.rs +++ b/src/bin/grin.rs @@ -57,8 +57,7 @@ fn start_from_config_file(mut global_config: GlobalConfig) { .unwrap() .server .clone() - .chain_type - .unwrap(), + .chain_type, ); grin::Server::start(global_config.members.as_mut().unwrap().server.clone()).unwrap(); @@ -102,8 +101,7 @@ fn main() { .unwrap() .server .clone() - .chain_type - .unwrap(), + .chain_type, ); } else { init_logger(Some(LoggingConfig::default()));