mirror of
https://github.com/mimblewimble/mwixnet.git
synced 2025-01-20 19:11:09 +03:00
add testnet config option
This commit is contained in:
parent
f4c6e91eb4
commit
1d9e59b7d6
3 changed files with 22 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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<Se
|
|||
})
|
||||
}
|
||||
|
||||
pub fn get_grin_path() -> 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
|
||||
}
|
||||
|
|
14
src/main.rs
14
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<dyn std::error::Error>> {
|
||||
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<dyn std::error::Error>> {
|
|||
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()),
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue