Config + Default directories (#1433)
* config file can now be generated by executable * rustfmt * remove now-unnecessary config defaults test * set up paths and config file creation in user's home directory * rustfmt * remove default grin.toml * add grin configuration command to spit out config file * Split configuration into wallet and server * rustfmt * Restore logging to wallet configurations * rustfmt
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
// Copyright 2018 The Grin Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/// Grin configuation file output command
|
||||
use config::{GlobalConfig, GlobalWalletConfig};
|
||||
use std::env;
|
||||
|
||||
/// Create a config file in the current directory
|
||||
pub fn config_command_server(file_name: &str) {
|
||||
let mut default_config = GlobalConfig::default();
|
||||
let current_dir = env::current_dir().unwrap_or_else(|e| {
|
||||
panic!("Error creating config file: {}", e);
|
||||
});
|
||||
let mut config_file_name = current_dir.clone();
|
||||
config_file_name.push(file_name);
|
||||
if config_file_name.exists() {
|
||||
panic!(
|
||||
"{} already exists in the current directory. Please remove it first",
|
||||
file_name
|
||||
);
|
||||
}
|
||||
default_config.update_paths(¤t_dir);
|
||||
default_config
|
||||
.write_to_file(config_file_name.to_str().unwrap())
|
||||
.unwrap_or_else(|e| {
|
||||
panic!("Error creating config file: {}", e);
|
||||
});
|
||||
|
||||
println!(
|
||||
"{} file configured and created in current directory",
|
||||
file_name
|
||||
);
|
||||
}
|
||||
|
||||
/// Create a config file in the current directory
|
||||
pub fn config_command_wallet(file_name: &str) {
|
||||
let mut default_config = GlobalWalletConfig::default();
|
||||
let current_dir = env::current_dir().unwrap_or_else(|e| {
|
||||
panic!("Error creating config file: {}", e);
|
||||
});
|
||||
let mut config_file_name = current_dir.clone();
|
||||
config_file_name.push(file_name);
|
||||
if config_file_name.exists() {
|
||||
panic!(
|
||||
"{} already exists in the target directory. Please remove it first",
|
||||
file_name
|
||||
);
|
||||
}
|
||||
default_config.update_paths(¤t_dir);
|
||||
default_config
|
||||
.write_to_file(config_file_name.to_str().unwrap())
|
||||
.unwrap_or_else(|e| {
|
||||
panic!("Error creating config file: {}", e);
|
||||
});
|
||||
|
||||
println!(
|
||||
"File {} configured and created",
|
||||
config_file_name.to_str().unwrap(),
|
||||
);
|
||||
}
|
||||
+3
-1
@@ -13,9 +13,11 @@
|
||||
// limitations under the License.
|
||||
|
||||
mod client;
|
||||
mod config;
|
||||
mod server;
|
||||
mod wallet;
|
||||
|
||||
pub use self::client::client_command;
|
||||
pub use self::config::{config_command_server, config_command_wallet};
|
||||
pub use self::server::server_command;
|
||||
pub use self::wallet::wallet_command;
|
||||
pub use self::wallet::{seed_exists, wallet_command};
|
||||
|
||||
@@ -123,7 +123,7 @@ pub fn server_command(server_args: Option<&ArgMatches>, mut global_config: Globa
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(true) = server_config.run_wallet_listener {
|
||||
/*if let Some(true) = server_config.run_wallet_listener {
|
||||
let mut wallet_config = global_config.members.as_ref().unwrap().wallet.clone();
|
||||
wallet::init_wallet_seed(wallet_config.clone());
|
||||
let wallet = wallet::instantiate_wallet(wallet_config.clone(), "");
|
||||
@@ -155,7 +155,7 @@ pub fn server_command(server_args: Option<&ArgMatches>, mut global_config: Globa
|
||||
)
|
||||
});
|
||||
});
|
||||
}
|
||||
}*/
|
||||
|
||||
// start the server in the different run modes (interactive or daemon)
|
||||
if let Some(a) = server_args {
|
||||
|
||||
+16
-5
@@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::path::PathBuf;
|
||||
/// Wallet commands processing
|
||||
use std::process::exit;
|
||||
use std::sync::{Arc, Mutex};
|
||||
@@ -20,7 +21,7 @@ use std::time::Duration;
|
||||
|
||||
use clap::ArgMatches;
|
||||
|
||||
use config::GlobalConfig;
|
||||
use config::GlobalWalletConfig;
|
||||
use core::core;
|
||||
use grin_wallet::{self, controller, display, libwallet};
|
||||
use grin_wallet::{HTTPWalletClient, LMDBBackend, WalletConfig, WalletInst, WalletSeed};
|
||||
@@ -28,12 +29,22 @@ use keychain;
|
||||
use servers::start_webwallet_server;
|
||||
use util::LOGGER;
|
||||
|
||||
pub fn init_wallet_seed(wallet_config: WalletConfig) {
|
||||
pub fn _init_wallet_seed(wallet_config: WalletConfig) {
|
||||
if let Err(_) = WalletSeed::from_file(&wallet_config) {
|
||||
WalletSeed::init_file(&wallet_config).expect("Failed to create wallet seed file.");
|
||||
};
|
||||
}
|
||||
|
||||
pub fn seed_exists(wallet_config: WalletConfig) -> bool {
|
||||
let mut data_file_dir = PathBuf::new();
|
||||
data_file_dir.push(wallet_config.data_file_dir);
|
||||
data_file_dir.push(grin_wallet::SEED_FILE);
|
||||
if data_file_dir.exists() {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
pub fn instantiate_wallet(
|
||||
wallet_config: WalletConfig,
|
||||
passphrase: &str,
|
||||
@@ -49,7 +60,7 @@ pub fn instantiate_wallet(
|
||||
warn!(LOGGER, "Migration successful. Using LMDB Wallet backend");
|
||||
}
|
||||
warn!(LOGGER, "Please check the results of the migration process using `grin wallet info` and `grin wallet outputs`");
|
||||
warn!(LOGGER, "If anything went wrong, you can try again by deleting the `wallet_data` directory and running a wallet command");
|
||||
warn!(LOGGER, "If anything went wrong, you can try again by deleting the `db` directory and running a wallet command");
|
||||
warn!(LOGGER, "If all is okay, you can move/backup/delete all files in the wallet directory EXCEPT FOR wallet.seed");
|
||||
}
|
||||
let client = HTTPWalletClient::new(&wallet_config.check_node_api_http_addr);
|
||||
@@ -63,9 +74,9 @@ pub fn instantiate_wallet(
|
||||
Box::new(db_wallet)
|
||||
}
|
||||
|
||||
pub fn wallet_command(wallet_args: &ArgMatches, global_config: GlobalConfig) {
|
||||
pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
// just get defaults from the global config
|
||||
let mut wallet_config = global_config.members.unwrap().wallet;
|
||||
let mut wallet_config = config.members.unwrap().wallet;
|
||||
|
||||
if wallet_args.is_present("external") {
|
||||
wallet_config.api_listen_interface = "0.0.0.0".to_string();
|
||||
|
||||
Reference in New Issue
Block a user