mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Reconcile config file with command line switches (#113)
* allowing mix of command line and config file values * rustfmt check
This commit is contained in:
parent
66255dfe83
commit
301e9a6e98
1 changed files with 73 additions and 40 deletions
|
@ -50,7 +50,16 @@ fn start_from_config_file(mut global_config: GlobalConfig) {
|
||||||
global_config.config_file_path.unwrap().to_str().unwrap()
|
global_config.config_file_path.unwrap().to_str().unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
global::set_mining_mode(global_config.members.as_mut().unwrap().server.clone().mining_parameter_mode.unwrap());
|
global::set_mining_mode(
|
||||||
|
global_config
|
||||||
|
.members
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.server
|
||||||
|
.clone()
|
||||||
|
.mining_parameter_mode
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
grin::Server::start(global_config.members.as_mut().unwrap().server.clone()).unwrap();
|
grin::Server::start(global_config.members.as_mut().unwrap().server.clone()).unwrap();
|
||||||
loop {
|
loop {
|
||||||
|
@ -61,6 +70,42 @@ fn start_from_config_file(mut global_config: GlobalConfig) {
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init().unwrap();
|
env_logger::init().unwrap();
|
||||||
|
|
||||||
|
// First, load a global config object,
|
||||||
|
// then modify that object with any switches
|
||||||
|
// found so that the switches override the
|
||||||
|
// global config file
|
||||||
|
|
||||||
|
// This will return a global config object,
|
||||||
|
// which will either contain defaults for all // of the config structures or a
|
||||||
|
// configuration
|
||||||
|
// read from a config file
|
||||||
|
|
||||||
|
let mut global_config = GlobalConfig::new(None).unwrap_or_else(|e| {
|
||||||
|
panic!("Error parsing config file: {}", e);
|
||||||
|
});
|
||||||
|
|
||||||
|
if global_config.using_config_file {
|
||||||
|
info!(
|
||||||
|
"Using configuration file at: {}",
|
||||||
|
global_config
|
||||||
|
.config_file_path
|
||||||
|
.clone()
|
||||||
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
);
|
||||||
|
global::set_mining_mode(
|
||||||
|
global_config
|
||||||
|
.members
|
||||||
|
.as_mut()
|
||||||
|
.unwrap()
|
||||||
|
.server
|
||||||
|
.clone()
|
||||||
|
.mining_parameter_mode
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let args = App::new("Grin")
|
let args = App::new("Grin")
|
||||||
.version("0.1")
|
.version("0.1")
|
||||||
.author("The Grin Team")
|
.author("The Grin Team")
|
||||||
|
@ -118,7 +163,8 @@ fn main() {
|
||||||
.arg(Arg::with_name("data_dir")
|
.arg(Arg::with_name("data_dir")
|
||||||
.short("dd")
|
.short("dd")
|
||||||
.long("data_dir")
|
.long("data_dir")
|
||||||
.help("Directory in which to store wallet files (defaults to current directory)")
|
.help("Directory in which to store wallet files (defaults to current \
|
||||||
|
directory)")
|
||||||
.takes_value(true))
|
.takes_value(true))
|
||||||
.arg(Arg::with_name("port")
|
.arg(Arg::with_name("port")
|
||||||
.short("r")
|
.short("r")
|
||||||
|
@ -128,17 +174,23 @@ fn main() {
|
||||||
.arg(Arg::with_name("api_server_address")
|
.arg(Arg::with_name("api_server_address")
|
||||||
.short("a")
|
.short("a")
|
||||||
.long("api_server_address")
|
.long("api_server_address")
|
||||||
.help("The api address of a running node on which to check inputs and post transactions")
|
.help("The api address of a running node on which to check inputs and \
|
||||||
|
post transactions")
|
||||||
.takes_value(true))
|
.takes_value(true))
|
||||||
.subcommand(SubCommand::with_name("receive")
|
.subcommand(SubCommand::with_name("receive")
|
||||||
.about("Run the wallet in receiving mode. If an input file is provided, will process it, otherwise runs in server mode waiting for send requests.")
|
.about("Run the wallet in receiving mode. If an input file is \
|
||||||
|
provided, will process it, otherwise runs in server mode waiting \
|
||||||
|
for send requests.")
|
||||||
.arg(Arg::with_name("input")
|
.arg(Arg::with_name("input")
|
||||||
.help("Partial transaction to receive, expects as a JSON file.")
|
.help("Partial transaction to receive, expects as a JSON file.")
|
||||||
.short("i")
|
.short("i")
|
||||||
.long("input")
|
.long("input")
|
||||||
.takes_value(true)))
|
.takes_value(true)))
|
||||||
.subcommand(SubCommand::with_name("send")
|
.subcommand(SubCommand::with_name("send")
|
||||||
.about("Builds a transaction to send someone some coins. By default, the transaction will just be printed to stdout. If a destination is provided, the command will attempt to contact the receiver at that address and send the transaction directly.")
|
.about("Builds a transaction to send someone some coins. By default, \
|
||||||
|
the transaction will just be printed to stdout. If a destination is \
|
||||||
|
provided, the command will attempt to contact the receiver at that \
|
||||||
|
address and send the transaction directly.")
|
||||||
.arg(Arg::with_name("amount")
|
.arg(Arg::with_name("amount")
|
||||||
.help("Amount to send in the smallest denomination")
|
.help("Amount to send in the smallest denomination")
|
||||||
.index(1))
|
.index(1))
|
||||||
|
@ -152,7 +204,7 @@ fn main() {
|
||||||
match args.subcommand() {
|
match args.subcommand() {
|
||||||
// server commands and options
|
// server commands and options
|
||||||
("server", Some(server_args)) => {
|
("server", Some(server_args)) => {
|
||||||
server_command(server_args);
|
server_command(server_args, global_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// client commands and options
|
// client commands and options
|
||||||
|
@ -170,20 +222,12 @@ fn main() {
|
||||||
wallet_command(wallet_args);
|
wallet_command(wallet_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If nothing is specified, try to load up and use a config file instead
|
// If nothing is specified, try to just use the config file instead
|
||||||
// this should possibly become the way to configure most things
|
// this could possibly become the way to configure most things
|
||||||
// with most command line options being phased out
|
// with most command line options being phased out
|
||||||
_ => {
|
_ => {
|
||||||
// This will return a global config object,
|
if global_config.using_config_file {
|
||||||
// which will either contain defaults for all
|
start_from_config_file(global_config);
|
||||||
// of the config structures or a configuration
|
|
||||||
// read from a config file
|
|
||||||
|
|
||||||
let global_config = GlobalConfig::new(None);
|
|
||||||
match global_config {
|
|
||||||
Ok(gc) => {
|
|
||||||
if gc.using_config_file {
|
|
||||||
start_from_config_file(gc);
|
|
||||||
} else {
|
} else {
|
||||||
// won't attempt to just start with defaults,
|
// won't attempt to just start with defaults,
|
||||||
// and will reject
|
// and will reject
|
||||||
|
@ -191,13 +235,6 @@ fn main() {
|
||||||
println!("Use 'grin help' for a list of all commands.");
|
println!("Use 'grin help' for a list of all commands.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
println!("{}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,11 +242,11 @@ fn main() {
|
||||||
/// stopping the Grin blockchain server. Processes all the command line
|
/// stopping the Grin blockchain server. Processes all the command line
|
||||||
/// arguments
|
/// arguments
|
||||||
/// to build a proper configuration and runs Grin with that configuration.
|
/// to build a proper configuration and runs Grin with that configuration.
|
||||||
fn server_command(server_args: &ArgMatches) {
|
fn server_command(server_args: &ArgMatches, global_config: GlobalConfig) {
|
||||||
info!("Starting the Grin server...");
|
info!("Starting the Grin server...");
|
||||||
|
|
||||||
// just get defaults from the global config
|
// just get defaults from the global config
|
||||||
let mut server_config = GlobalConfig::default().members.unwrap().server;
|
let mut server_config = global_config.members.unwrap().server;
|
||||||
|
|
||||||
if let Some(port) = server_args.value_of("port") {
|
if let Some(port) = server_args.value_of("port") {
|
||||||
server_config.p2p_config.as_mut().unwrap().port = port.parse().unwrap();
|
server_config.p2p_config.as_mut().unwrap().port = port.parse().unwrap();
|
||||||
|
@ -237,10 +274,6 @@ fn server_command(server_args: &ArgMatches) {
|
||||||
server_config.seeds = Some(seeds.map(|s| s.to_string()).collect());
|
server_config.seeds = Some(seeds.map(|s| s.to_string()).collect());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*let mut sc = GlobalConfig::default();
|
|
||||||
sc.members.as_mut().unwrap().server = server_config.clone();
|
|
||||||
println!("{}", sc.ser_config().unwrap());*/
|
|
||||||
|
|
||||||
// start the server in the different run modes (interactive or daemon)
|
// start the server in the different run modes (interactive or daemon)
|
||||||
match server_args.subcommand() {
|
match server_args.subcommand() {
|
||||||
("run", _) => {
|
("run", _) => {
|
||||||
|
|
Loading…
Reference in a new issue