diff --git a/mwixnet.yml b/mwixnet.yml index a341dfd..871b204 100644 --- a/mwixnet.yml +++ b/mwixnet.yml @@ -8,6 +8,10 @@ args: short: c long: config_file takes_value: true + - testnet: + help: Run grin against the Testnet (as opposed to mainnet) + long: testnet + takes_value: false - grin_node_url: help: Api address of running GRIN node on which to check inputs and post transactions short: n diff --git a/src/config.rs b/src/config.rs index b9b2980..decbbaf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,6 +2,7 @@ use crate::error::{self, Result}; use crate::secp::SecretKey; use core::num::NonZeroU32; +use grin_core::global::ChainTypes; use grin_util::{file, ToHex, ZeroingString}; use rand::{thread_rng, Rng}; use ring::{aead, pbkdf2}; @@ -12,7 +13,6 @@ use std::net::SocketAddr; use std::path::PathBuf; const GRIN_HOME: &str = ".grin"; -const CHAIN_NAME: &str = "main"; const NODE_API_SECRET_FILE_NAME: &str = ".api_secret"; const WALLET_OWNER_API_SECRET_FILE_NAME: &str = ".owner_api_secret"; @@ -218,24 +218,24 @@ pub fn load_config(config_path: &PathBuf, password: &ZeroingString) -> Result PathBuf { +pub fn get_grin_path(chain_type: &ChainTypes) -> PathBuf { let mut grin_path = match dirs::home_dir() { Some(p) => p, None => PathBuf::new(), }; grin_path.push(GRIN_HOME); - grin_path.push(CHAIN_NAME); + grin_path.push(chain_type.shortname()); grin_path } -pub fn node_secret_path() -> PathBuf { - let mut path = get_grin_path(); +pub fn node_secret_path(chain_type: &ChainTypes) -> PathBuf { + let mut path = get_grin_path(chain_type); path.push(NODE_API_SECRET_FILE_NAME); path } -pub fn wallet_owner_secret_path() -> PathBuf { - let mut path = get_grin_path(); +pub fn wallet_owner_secret_path(chain_type: &ChainTypes) -> PathBuf { + let mut path = get_grin_path(chain_type); path.push(WALLET_OWNER_API_SECRET_FILE_NAME); path } diff --git a/src/main.rs b/src/main.rs index c601d23..7425812 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use node::HttpGrinNode; use wallet::HttpWallet; use clap::App; +use grin_core::global::ChainTypes; use grin_util::{StopState, ZeroingString}; use rpassword; use std::path::PathBuf; @@ -32,11 +33,16 @@ fn main() { fn real_main() -> Result<(), Box> { let yml = load_yaml!("../mwixnet.yml"); let args = App::from_yaml(yml).get_matches(); + let chain_type = if args.is_present("testnet") { + ChainTypes::Testnet + } else { + ChainTypes::Mainnet + }; let config_path = match args.value_of("config_file") { Some(path) => PathBuf::from(path), None => { - let mut grin_path = config::get_grin_path(); + let mut grin_path = config::get_grin_path(&chain_type); grin_path.push("mwixnet-config.toml"); grin_path } @@ -67,12 +73,14 @@ fn real_main() -> Result<(), Box> { grin_node_url: grin_node_url.unwrap_or("127.0.0.1:3413").parse()?, grin_node_secret_path: match grin_node_secret_path { Some(p) => Some(p.to_owned()), - None => config::node_secret_path().to_str().map(|p| p.to_owned()), + None => config::node_secret_path(&chain_type) + .to_str() + .map(|p| p.to_owned()), }, wallet_owner_url: wallet_owner_url.unwrap_or("127.0.0.1:3420").parse()?, wallet_owner_secret_path: match wallet_owner_secret_path { Some(p) => Some(p.to_owned()), - None => config::wallet_owner_secret_path() + None => config::wallet_owner_secret_path(&chain_type) .to_str() .map(|p| p.to_owned()), },