From a8fcc37a364059248a87198162dc3563e79f547b Mon Sep 17 00:00:00 2001 From: Ignotus Peverell Date: Sun, 11 Mar 2018 00:36:54 +0000 Subject: [PATCH] Automatically run wallet listener Convenience option, set to true by default in grin.toml, to fork a wallet listener thread by default. Should make it easier for people to get started on testnet2. People who want to configure a password for their wallet seed, run multiple listeners, change default address should set this to false and manually configure and start their wallet listener. This might break some tooling. Hopefully not. --- grin.toml | 3 +++ grin/src/types.rs | 4 ++++ src/bin/grin.rs | 36 ++++++++++++++++-------------------- src/bin/ui.rs | 2 +- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/grin.toml b/grin.toml index a16eb775e..425bcfecf 100644 --- a/grin.toml +++ b/grin.toml @@ -56,6 +56,9 @@ capabilities = [7] #will also disable logging to stdout run_tui = false +#Whether to run the wallet listener with the server by default +run_wallet_listener = true + #The P2P server details (i.e. the server that communicates with other #grin server nodes diff --git a/grin/src/types.rs b/grin/src/types.rs index 9c538e65e..130f4d3a5 100644 --- a/grin/src/types.rs +++ b/grin/src/types.rs @@ -151,6 +151,9 @@ pub struct ServerConfig { /// Whether to run the TUI /// if enabled, this will disable logging to stdout pub run_tui: Option, + + /// Whether to run the wallet listener with the server by default + pub run_wallet_listener: Option, } impl Default for ServerConfig { @@ -168,6 +171,7 @@ impl Default for ServerConfig { pool_config: pool::PoolConfig::default(), skip_sync_wait: None, run_tui: None, + run_wallet_listener: Some(false), } } } diff --git a/src/bin/grin.rs b/src/bin/grin.rs index b2d289f1b..bb86925b4 100644 --- a/src/bin/grin.rs +++ b/src/bin/grin.rs @@ -368,7 +368,7 @@ fn server_command(server_args: &ArgMatches, global_config: GlobalConfig) { info!(LOGGER, "Starting the Grin server..."); // just get defaults from the global config - let mut server_config = global_config.members.unwrap().server; + let mut server_config = global_config.members.as_ref().unwrap().server.clone(); if let Some(port) = server_args.value_of("port") { server_config.p2p_config.port = port.parse().unwrap(); @@ -396,6 +396,21 @@ fn server_command(server_args: &ArgMatches, global_config: GlobalConfig) { server_config.seeds = Some(seeds.map(|s| s.to_string()).collect()); } + if let Some(true) = server_config.run_wallet_listener { + let mut wallet_config = global_config.members.unwrap().wallet; + let wallet_seed = + wallet::WalletSeed::from_file(&wallet_config).expect("Failed to read wallet seed file."); + let mut keychain = wallet_seed + .derive_keychain("") + .expect("Failed to derive keychain from seed file and passphrase."); + + let _ = thread::Builder::new() + .name("wallet_listener".to_string()) + .spawn(move || { + wallet::server::start_rest_apis(wallet_config, keychain); + }); + } + // start the server in the different run modes (interactive or daemon) match server_args.subcommand() { ("run", _) => { @@ -513,25 +528,6 @@ fn wallet_command(wallet_args: &ArgMatches, global_config: GlobalConfig) { } wallet::server::start_rest_apis(wallet_config, keychain); } - // The following is gone for now, as a result of aggsig transactions - // being implemented - /*("receive", Some(receive_args)) => { - let input = receive_args.value_of("input").expect("Input file required"); - let mut file = File::open(input).expect("Unable to open transaction file."); - let mut contents = String::new(); - file.read_to_string(&mut contents).expect( - "Unable to read transaction file.", - ); - if let Err(e) = - wallet::receive_json_tx_str( - &wallet_config, &keychain, contents.as_str()) { - - println!("Error receiving transaction, the most likely reasons are:"); - println!(" * the transaction has already been sent"); - println!(" * your node isn't running or can't be reached"); - println!("\nDetailed error: {:?}", e); - } - }*/ ("send", Some(send_args)) => { let amount = send_args .value_of("amount") diff --git a/src/bin/ui.rs b/src/bin/ui.rs index 3b4f2000b..e81caf872 100644 --- a/src/bin/ui.rs +++ b/src/bin/ui.rs @@ -361,7 +361,7 @@ impl Controller { ) } else if stats.mining_stats.combined_gps == 0.0 { ( - "Mining Status: Starting miner and awating first solution...".to_string(), + "Mining Status: Starting miner and awaiting first solution...".to_string(), "".to_string(), ) } else {