grin/src/bin/grin.rs

161 lines
4.3 KiB
Rust
Raw Normal View History

// 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.
#[macro_use]
extern crate clap;
#[macro_use]
extern crate log;
use crate::config::config::SERVER_CONFIG_FILE_NAME;
use crate::core::global;
use crate::util::init_logger;
use clap::App;
use grin_api as api;
use grin_config as config;
use grin_core as core;
use grin_p2p as p2p;
use grin_servers as servers;
use grin_util as util;
mod cmd;
pub mod tui;
// include build information
pub mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}
pub fn info_strings() -> (String, String) {
(
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,
built_info::RUSTC_VERSION,
)
.to_string(),
format!(
"Built with profile \"{}\", features \"{}\".",
built_info::PROFILE,
built_info::FEATURES_STR,
)
.to_string(),
)
}
fn log_build_info() {
let (basic_info, detailed_info) = info_strings();
info!("{}", basic_info);
debug!("{}", detailed_info);
}
2017-04-06 09:41:49 +03:00
fn main() {
let exit_code = real_main();
std::process::exit(exit_code);
}
fn real_main() -> i32 {
let yml = load_yaml!("grin.yml");
let args = App::from_yaml(yml).get_matches();
let node_config;
Re-launch floonet (#2249) * Fix secondary scaling bugs; rename is_testnet -> is_floonet (#2215) * add global::is_mainnet() * use it to change pre-genesis pow type * rename is_testnet -> is_floonet * Support multiple chain configurations (#2217) * Support multiple chain configurations Supports generating the proper configuration for each chain type (mainnet, floonet, usernet). Will run them by default under their respective root directory (~/.grin/main, ~/.grin/floo, etc). Assigned default ports for mainnet, overriding them to keep Floonet ports unchanged. For now, starting on mainnet will abort. * Fixed usernet command line help message. Fixes #2217 * Differing magic numbers for each chain type (#2208) * stick to e=H(R|P|m) when use schnorr signature (#2200) * stick to e=H(R|P|m) when use schnorr signature * (1)add verify_slate_messages for wallet receive (2)log the message content * remove debug log on verify_slate_messages * verify the sender's message signature when receive_tx in wallet listen * Revert "remove debug log on verify_slate_messages" This reverts commit 65ea32a407bfd57d02bf169803f1483ba611962e. * Revert "rustfmt" This reverts commit c380ab91856344b73595bb04eef1fc087dedd84d. * Revert "(1)add verify_slate_messages for wallet receive (2)log the message content" This reverts commit 9584ca7a893b22a768dea061039140033c07e8eb. * [re-floonet] Keychain Floonet BIP32 version/network option (#2235) * add 'is_floonet' property to keychain * fix hex encoding and tests * Fix couple floonet loose ends (#2230) * Fix couple floonet loose ends. Fixes #2216 * Doc fix for sig message * Refuse unkown kernel features (#2244) * Minor: magic number change for re-floonet * Set pre genesis is_secondary to true (#2247) * Minor: tx validation error display underlying * New floonet genesis * genesis rustfmt * Use chain-specific config for wallet toml gen * Fix default wallet_listener_url * New more reasonable genesis block, bumped version * genesis rustfmt * Couple minor fixes to genesis generation script
2018-12-29 01:46:21 +03:00
let chain_type = if args.is_present("floonet") {
global::ChainTypes::Floonet
} else if args.is_present("usernet") {
global::ChainTypes::UserTesting
} else {
global::ChainTypes::Mainnet
};
// 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() {
Re-launch floonet (#2249) * Fix secondary scaling bugs; rename is_testnet -> is_floonet (#2215) * add global::is_mainnet() * use it to change pre-genesis pow type * rename is_testnet -> is_floonet * Support multiple chain configurations (#2217) * Support multiple chain configurations Supports generating the proper configuration for each chain type (mainnet, floonet, usernet). Will run them by default under their respective root directory (~/.grin/main, ~/.grin/floo, etc). Assigned default ports for mainnet, overriding them to keep Floonet ports unchanged. For now, starting on mainnet will abort. * Fixed usernet command line help message. Fixes #2217 * Differing magic numbers for each chain type (#2208) * stick to e=H(R|P|m) when use schnorr signature (#2200) * stick to e=H(R|P|m) when use schnorr signature * (1)add verify_slate_messages for wallet receive (2)log the message content * remove debug log on verify_slate_messages * verify the sender's message signature when receive_tx in wallet listen * Revert "remove debug log on verify_slate_messages" This reverts commit 65ea32a407bfd57d02bf169803f1483ba611962e. * Revert "rustfmt" This reverts commit c380ab91856344b73595bb04eef1fc087dedd84d. * Revert "(1)add verify_slate_messages for wallet receive (2)log the message content" This reverts commit 9584ca7a893b22a768dea061039140033c07e8eb. * [re-floonet] Keychain Floonet BIP32 version/network option (#2235) * add 'is_floonet' property to keychain * fix hex encoding and tests * Fix couple floonet loose ends (#2230) * Fix couple floonet loose ends. Fixes #2216 * Doc fix for sig message * Refuse unkown kernel features (#2244) * Minor: magic number change for re-floonet * Set pre genesis is_secondary to true (#2247) * Minor: tx validation error display underlying * New floonet genesis * genesis rustfmt * Use chain-specific config for wallet toml gen * Fix default wallet_listener_url * New more reasonable genesis block, bumped version * genesis rustfmt * Couple minor fixes to genesis generation script
2018-12-29 01:46:21 +03:00
cmd::config_command_server(&chain_type, SERVER_CONFIG_FILE_NAME);
return 0;
}
}
_ => {}
}
// Load relevant config
match args.subcommand() {
// When the subscommand is 'server' take into account the 'config_file' flag
("server", Some(server_args)) => {
if let Some(_path) = server_args.value_of("config_file") {
node_config = Some(config::GlobalConfig::new(_path).unwrap_or_else(|e| {
panic!("Error loading server configuration: {}", e);
}));
} else {
node_config = Some(
config::initial_setup_server(&chain_type).unwrap_or_else(|e| {
panic!("Error loading server configuration: {}", e);
}),
);
}
}
// Otherwise load up the node config as usual
_ => {
node_config = Some(
config::initial_setup_server(&chain_type).unwrap_or_else(|e| {
panic!("Error loading server configuration: {}", e);
}),
);
}
}
if let Some(mut config) = node_config.clone() {
let mut l = config.members.as_mut().unwrap().logging.clone().unwrap();
let run_tui = config.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(config.members.unwrap().server.clone().chain_type);
if let Some(file_path) = &config.config_file_path {
info!(
"Using configuration file at {}",
file_path.to_str().unwrap()
);
} else {
info!("Node configuration file not found, using default");
}
}
log_build_info();
// Execute subcommand
2017-06-01 00:44:44 +03:00
match args.subcommand() {
// server commands and options
("server", Some(server_args)) => {
cmd::server_command(Some(server_args), node_config.unwrap())
2017-06-01 00:44:44 +03:00
}
// client commands and options
("client", Some(client_args)) => cmd::client_command(client_args, node_config.unwrap()),
2017-06-01 00:44:44 +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
_ => cmd::server_command(None, node_config.unwrap()),
}
}