add testnet config option

This commit is contained in:
scilio 2022-08-20 13:31:09 -04:00
parent f4c6e91eb4
commit 1d9e59b7d6
3 changed files with 22 additions and 10 deletions

View file

@ -8,6 +8,10 @@ args:
short: c short: c
long: config_file long: config_file
takes_value: true takes_value: true
- testnet:
help: Run grin against the Testnet (as opposed to mainnet)
long: testnet
takes_value: false
- grin_node_url: - grin_node_url:
help: Api address of running GRIN node on which to check inputs and post transactions help: Api address of running GRIN node on which to check inputs and post transactions
short: n short: n

View file

@ -2,6 +2,7 @@ use crate::error::{self, Result};
use crate::secp::SecretKey; use crate::secp::SecretKey;
use core::num::NonZeroU32; use core::num::NonZeroU32;
use grin_core::global::ChainTypes;
use grin_util::{file, ToHex, ZeroingString}; use grin_util::{file, ToHex, ZeroingString};
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use ring::{aead, pbkdf2}; use ring::{aead, pbkdf2};
@ -12,7 +13,6 @@ use std::net::SocketAddr;
use std::path::PathBuf; use std::path::PathBuf;
const GRIN_HOME: &str = ".grin"; const GRIN_HOME: &str = ".grin";
const CHAIN_NAME: &str = "main";
const NODE_API_SECRET_FILE_NAME: &str = ".api_secret"; const NODE_API_SECRET_FILE_NAME: &str = ".api_secret";
const WALLET_OWNER_API_SECRET_FILE_NAME: &str = ".owner_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<Se
}) })
} }
pub fn get_grin_path() -> PathBuf { pub fn get_grin_path(chain_type: &ChainTypes) -> PathBuf {
let mut grin_path = match dirs::home_dir() { let mut grin_path = match dirs::home_dir() {
Some(p) => p, Some(p) => p,
None => PathBuf::new(), None => PathBuf::new(),
}; };
grin_path.push(GRIN_HOME); grin_path.push(GRIN_HOME);
grin_path.push(CHAIN_NAME); grin_path.push(chain_type.shortname());
grin_path grin_path
} }
pub fn node_secret_path() -> PathBuf { pub fn node_secret_path(chain_type: &ChainTypes) -> PathBuf {
let mut path = get_grin_path(); let mut path = get_grin_path(chain_type);
path.push(NODE_API_SECRET_FILE_NAME); path.push(NODE_API_SECRET_FILE_NAME);
path path
} }
pub fn wallet_owner_secret_path() -> PathBuf { pub fn wallet_owner_secret_path(chain_type: &ChainTypes) -> PathBuf {
let mut path = get_grin_path(); let mut path = get_grin_path(chain_type);
path.push(WALLET_OWNER_API_SECRET_FILE_NAME); path.push(WALLET_OWNER_API_SECRET_FILE_NAME);
path path
} }

View file

@ -3,6 +3,7 @@ use node::HttpGrinNode;
use wallet::HttpWallet; use wallet::HttpWallet;
use clap::App; use clap::App;
use grin_core::global::ChainTypes;
use grin_util::{StopState, ZeroingString}; use grin_util::{StopState, ZeroingString};
use rpassword; use rpassword;
use std::path::PathBuf; use std::path::PathBuf;
@ -32,11 +33,16 @@ fn main() {
fn real_main() -> Result<(), Box<dyn std::error::Error>> { fn real_main() -> Result<(), Box<dyn std::error::Error>> {
let yml = load_yaml!("../mwixnet.yml"); let yml = load_yaml!("../mwixnet.yml");
let args = App::from_yaml(yml).get_matches(); 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") { let config_path = match args.value_of("config_file") {
Some(path) => PathBuf::from(path), Some(path) => PathBuf::from(path),
None => { 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.push("mwixnet-config.toml");
grin_path grin_path
} }
@ -67,12 +73,14 @@ fn real_main() -> Result<(), Box<dyn std::error::Error>> {
grin_node_url: grin_node_url.unwrap_or("127.0.0.1:3413").parse()?, grin_node_url: grin_node_url.unwrap_or("127.0.0.1:3413").parse()?,
grin_node_secret_path: match grin_node_secret_path { grin_node_secret_path: match grin_node_secret_path {
Some(p) => Some(p.to_owned()), 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_url: wallet_owner_url.unwrap_or("127.0.0.1:3420").parse()?,
wallet_owner_secret_path: match wallet_owner_secret_path { wallet_owner_secret_path: match wallet_owner_secret_path {
Some(p) => Some(p.to_owned()), Some(p) => Some(p.to_owned()),
None => config::wallet_owner_secret_path() None => config::wallet_owner_secret_path(&chain_type)
.to_str() .to_str()
.map(|p| p.to_owned()), .map(|p| p.to_owned()),
}, },