2018-03-05 22:33:44 +03:00
|
|
|
// Copyright 2018 The Grin Developers
|
2017-04-06 09:41:49 +03:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
//! Main for building the binary of a Grin peer-to-peer node.
|
|
|
|
|
2017-11-01 02:32:33 +03:00
|
|
|
extern crate blake2_rfc as blake2;
|
2018-08-04 01:39:54 +03:00
|
|
|
extern crate chrono;
|
2018-03-27 00:21:03 +03:00
|
|
|
#[macro_use]
|
2017-04-28 08:07:25 +03:00
|
|
|
extern crate clap;
|
2018-06-21 06:16:02 +03:00
|
|
|
extern crate ctrlc;
|
2018-03-09 20:16:31 +03:00
|
|
|
extern crate cursive;
|
2017-04-28 08:07:25 +03:00
|
|
|
extern crate daemonize;
|
2018-12-07 20:18:33 +03:00
|
|
|
extern crate rpassword;
|
2017-04-25 04:55:01 +03:00
|
|
|
extern crate serde;
|
|
|
|
extern crate serde_json;
|
2017-11-01 02:32:33 +03:00
|
|
|
#[macro_use]
|
2018-10-21 23:30:56 +03:00
|
|
|
extern crate log;
|
2018-12-06 15:04:02 +03:00
|
|
|
extern crate failure;
|
2018-08-04 01:39:54 +03:00
|
|
|
extern crate term;
|
2017-04-25 04:55:01 +03:00
|
|
|
|
2017-05-25 02:08:39 +03:00
|
|
|
extern crate grin_api as api;
|
2017-07-13 20:30:33 +03:00
|
|
|
extern crate grin_config as config;
|
2017-08-09 19:40:23 +03:00
|
|
|
extern crate grin_core as core;
|
2017-11-01 02:32:33 +03:00
|
|
|
extern crate grin_keychain as keychain;
|
2018-02-03 03:37:35 +03:00
|
|
|
extern crate grin_p2p as p2p;
|
2018-04-24 11:18:24 +03:00
|
|
|
extern crate grin_servers as servers;
|
2017-10-12 19:56:44 +03:00
|
|
|
extern crate grin_util as util;
|
2018-08-04 01:39:54 +03:00
|
|
|
extern crate grin_wallet;
|
2017-04-25 04:55:01 +03:00
|
|
|
|
2018-08-04 01:39:54 +03:00
|
|
|
mod cmd;
|
2018-03-13 21:10:45 +03:00
|
|
|
pub mod tui;
|
2017-12-22 21:46:28 +03:00
|
|
|
|
2018-12-07 20:18:33 +03:00
|
|
|
pub use cmd::wallet_args;
|
|
|
|
|
2018-09-19 00:59:41 +03:00
|
|
|
use std::process::exit;
|
|
|
|
|
2018-12-06 18:25:05 +03:00
|
|
|
use clap::App;
|
2017-04-28 08:07:25 +03:00
|
|
|
|
2018-08-30 12:10:40 +03:00
|
|
|
use config::config::{SERVER_CONFIG_FILE_NAME, WALLET_CONFIG_FILE_NAME};
|
2018-05-30 19:48:32 +03:00
|
|
|
use core::global;
|
2018-10-21 23:30:56 +03:00
|
|
|
use util::init_logger;
|
2017-06-16 19:47:29 +03:00
|
|
|
|
2018-03-23 13:28:15 +03:00
|
|
|
// include build information
|
|
|
|
pub mod built_info {
|
|
|
|
include!(concat!(env!("OUT_DIR"), "/built.rs"));
|
|
|
|
}
|
|
|
|
|
2018-10-26 03:44:50 +03:00
|
|
|
pub fn info_strings() -> (String, String) {
|
2018-03-23 13:28:15 +03:00
|
|
|
(
|
|
|
|
format!(
|
|
|
|
"This is Grin version {}{}, built for {} by {}.",
|
|
|
|
built_info::PKG_VERSION,
|
|
|
|
built_info::GIT_VERSION.map_or_else(|| "".to_owned(), |v| format!(" (git {})", v)),
|
|
|
|
built_info::TARGET,
|
2018-10-26 03:44:50 +03:00
|
|
|
built_info::RUSTC_VERSION,
|
2018-03-23 13:28:15 +03:00
|
|
|
).to_string(),
|
|
|
|
format!(
|
2018-10-26 03:44:50 +03:00
|
|
|
"Built with profile \"{}\", features \"{}\".",
|
2018-03-23 13:28:15 +03:00
|
|
|
built_info::PROFILE,
|
|
|
|
built_info::FEATURES_STR,
|
|
|
|
).to_string(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn log_build_info() {
|
2018-10-26 03:44:50 +03:00
|
|
|
let (basic_info, detailed_info) = info_strings();
|
2018-10-21 23:30:56 +03:00
|
|
|
info!("{}", basic_info);
|
|
|
|
debug!("{}", detailed_info);
|
2018-03-23 13:28:15 +03:00
|
|
|
}
|
|
|
|
|
2017-04-06 09:41:49 +03:00
|
|
|
fn main() {
|
2018-11-04 23:26:46 +03:00
|
|
|
let exit_code = real_main();
|
|
|
|
std::process::exit(exit_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn real_main() -> i32 {
|
2018-12-06 18:25:05 +03:00
|
|
|
let yml = load_yaml!("grin.yml");
|
|
|
|
let args = App::from_yaml(yml).get_matches();
|
2018-08-30 12:10:40 +03:00
|
|
|
let mut wallet_config = None;
|
|
|
|
let mut node_config = None;
|
2017-04-28 08:07:25 +03:00
|
|
|
|
2018-08-30 12:10:40 +03:00
|
|
|
// Deal with configuration file creation
|
|
|
|
match args.subcommand() {
|
|
|
|
("server", Some(server_args)) => {
|
|
|
|
// If it's just a server config command, do it and exit
|
|
|
|
if let ("config", Some(_)) = server_args.subcommand() {
|
|
|
|
cmd::config_command_server(SERVER_CONFIG_FILE_NAME);
|
2018-11-04 23:26:46 +03:00
|
|
|
return 0;
|
2018-08-30 12:10:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
("wallet", Some(wallet_args)) => {
|
|
|
|
// wallet init command should spit out its config file then continue
|
|
|
|
// (if desired)
|
|
|
|
if let ("init", Some(init_args)) = wallet_args.subcommand() {
|
|
|
|
if init_args.is_present("here") {
|
|
|
|
cmd::config_command_wallet(WALLET_CONFIG_FILE_NAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
2018-07-30 03:48:24 +03:00
|
|
|
}
|
2018-03-21 23:48:56 +03:00
|
|
|
|
2018-08-30 12:10:40 +03:00
|
|
|
match args.subcommand() {
|
|
|
|
// If it's a wallet command, try and load a wallet config file
|
|
|
|
("wallet", Some(wallet_args)) => {
|
|
|
|
let mut w = config::initial_setup_wallet().unwrap_or_else(|e| {
|
|
|
|
panic!("Error loading wallet configuration: {}", e);
|
|
|
|
});
|
|
|
|
if !cmd::seed_exists(w.members.as_ref().unwrap().wallet.clone()) {
|
2018-11-24 13:03:09 +03:00
|
|
|
if "init" == wallet_args.subcommand().0 || "recover" == wallet_args.subcommand().0 {
|
2018-08-30 12:10:40 +03:00
|
|
|
} else {
|
2018-11-24 13:03:09 +03:00
|
|
|
println!("Wallet seed file doesn't exist. Run `grin wallet init` first");
|
2018-09-19 00:59:41 +03:00
|
|
|
exit(1);
|
2018-08-30 12:10:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
let mut l = w.members.as_mut().unwrap().logging.clone().unwrap();
|
|
|
|
l.tui_running = Some(false);
|
|
|
|
init_logger(Some(l));
|
2018-10-31 02:12:30 +03:00
|
|
|
info!(
|
2018-08-30 12:10:40 +03:00
|
|
|
"Using wallet configuration file at {}",
|
|
|
|
w.config_file_path.as_ref().unwrap().to_str().unwrap()
|
|
|
|
);
|
|
|
|
wallet_config = Some(w);
|
|
|
|
}
|
|
|
|
// Otherwise load up the node config as usual
|
|
|
|
_ => {
|
|
|
|
let mut s = config::initial_setup_server().unwrap_or_else(|e| {
|
|
|
|
panic!("Error loading server configuration: {}", e);
|
|
|
|
});
|
|
|
|
let mut l = s.members.as_mut().unwrap().logging.clone().unwrap();
|
|
|
|
let run_tui = s.members.as_mut().unwrap().server.run_tui;
|
|
|
|
if let Some(true) = run_tui {
|
|
|
|
l.log_to_stdout = false;
|
|
|
|
l.tui_running = Some(true);
|
|
|
|
}
|
|
|
|
init_logger(Some(l));
|
|
|
|
global::set_mining_mode(s.members.as_mut().unwrap().server.clone().chain_type);
|
|
|
|
if let Some(file_path) = &s.config_file_path {
|
|
|
|
info!(
|
|
|
|
"Using configuration file at {}",
|
|
|
|
file_path.to_str().unwrap()
|
|
|
|
);
|
|
|
|
} else {
|
2018-10-21 23:30:56 +03:00
|
|
|
info!("Node configuration file not found, using default");
|
2018-08-30 12:10:40 +03:00
|
|
|
}
|
|
|
|
node_config = Some(s);
|
|
|
|
}
|
2018-07-31 13:14:13 +03:00
|
|
|
}
|
|
|
|
|
2018-08-30 12:10:40 +03:00
|
|
|
log_build_info();
|
|
|
|
|
2017-06-01 00:44:44 +03:00
|
|
|
match args.subcommand() {
|
|
|
|
// server commands and options
|
|
|
|
("server", Some(server_args)) => {
|
2018-11-04 23:26:46 +03:00
|
|
|
cmd::server_command(Some(server_args), node_config.unwrap())
|
2017-06-01 00:44:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// client commands and options
|
2018-11-04 23:26:46 +03:00
|
|
|
("client", Some(client_args)) => cmd::client_command(client_args, node_config.unwrap()),
|
2017-06-01 00:44:44 +03:00
|
|
|
|
|
|
|
// client commands and options
|
2018-11-04 23:26:46 +03:00
|
|
|
("wallet", Some(wallet_args)) => cmd::wallet_command(wallet_args, wallet_config.unwrap()),
|
2017-06-01 00:44:44 +03:00
|
|
|
|
2017-09-05 04:34:24 +03:00
|
|
|
// If nothing is specified, try to just use the config file instead
|
|
|
|
// this could possibly become the way to configure most things
|
2017-07-26 04:43:17 +03:00
|
|
|
// with most command line options being phased out
|
2018-11-04 23:26:46 +03:00
|
|
|
_ => cmd::server_command(None, node_config.unwrap()),
|
2017-12-22 21:46:28 +03:00
|
|
|
}
|
|
|
|
}
|