Crash fixes, reorg handling, and sync performance improvements
Some checks failed
Rust / Build on macOS-latest (push) Has been cancelled
Rust / Build on ubuntu-16.04 (push) Has been cancelled
Rust / Build on windows-latest (push) Has been cancelled
Rust / Linux ARMv7 (push) Has been cancelled
Rust / Linux ARM64 (push) Has been cancelled
Rust / Build on ubuntu-latest (push) Has been cancelled
Some checks failed
Rust / Build on macOS-latest (push) Has been cancelled
Rust / Build on ubuntu-16.04 (push) Has been cancelled
Rust / Build on windows-latest (push) Has been cancelled
Rust / Linux ARMv7 (push) Has been cancelled
Rust / Linux ARM64 (push) Has been cancelled
Rust / Build on ubuntu-latest (push) Has been cancelled
- Fix FFI panics with catch_unwind and safe CString construction - Handle poisoned mutex/RwLock after prior panics instead of crashing - Fix empty block list panics in clear_blocks and invalidate_block - Reuse Tokio runtime across block fetch batches to reduce overhead - Add fetch_blocks_with_runtime for caller-managed runtime lifecycle - Update branding, dependencies, and checkpoints for DragonX
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
[package]
|
||||
name = "silentdragonxlite-cli"
|
||||
version = "1.0.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
rustyline = "5.0.2"
|
||||
clap = "2.33"
|
||||
log = "0.4"
|
||||
log4rs = "0.8.3"
|
||||
shellwords = "1.0.0"
|
||||
json = "0.12.0"
|
||||
http = "0.2"
|
||||
byteorder = "1"
|
||||
tiny-bip39 = "0.6.2"
|
||||
|
||||
silentdragonxlitelib = { path = "../lib/" }
|
||||
|
||||
[package]
|
||||
name = "silentdragonxlite-cli"
|
||||
version = "1.0.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
rustyline = "5.0.2"
|
||||
clap = "2.33"
|
||||
log = "0.4"
|
||||
log4rs = "0.8.3"
|
||||
shellwords = "1.0.0"
|
||||
json = "0.12.0"
|
||||
http = "0.2"
|
||||
byteorder = "1"
|
||||
tiny-bip39 = "0.6.2"
|
||||
|
||||
silentdragonxlitelib = { path = "../lib/" }
|
||||
|
||||
|
||||
524
cli/src/lib.rs
524
cli/src/lib.rs
@@ -1,262 +1,262 @@
|
||||
use std::io::{self};
|
||||
use std::sync::Arc;
|
||||
use std::sync::mpsc::{channel, Sender, Receiver};
|
||||
|
||||
use log::{info, error};
|
||||
|
||||
use silentdragonxlitelib::{commands,
|
||||
lightclient::{LightClient, LightClientConfig},
|
||||
};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! configure_clapapp {
|
||||
( $freshapp: expr ) => {
|
||||
$freshapp.version("1.0.0")
|
||||
.arg(Arg::with_name("dangerous")
|
||||
.long("dangerous")
|
||||
.help("Disable server TLS certificate verification. Use this if you're running a local lightwalletd with a self-signed certificate. WARNING: This is dangerous, don't use it with a server that is not your own.")
|
||||
.takes_value(false))
|
||||
.arg(Arg::with_name("nosync")
|
||||
.help("By default, Silentdragonlite-cli will sync the wallet at startup. Pass --nosync to prevent the automatic sync at startup.")
|
||||
.long("nosync")
|
||||
.short("n")
|
||||
.takes_value(false))
|
||||
.arg(Arg::with_name("recover")
|
||||
.long("recover")
|
||||
.help("Attempt to recover the seed from the wallet")
|
||||
.takes_value(false))
|
||||
.arg(Arg::with_name("password")
|
||||
.long("password")
|
||||
.help("When recovering seed, specify a password for the encrypted wallet")
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("seed")
|
||||
.short("s")
|
||||
.long("seed")
|
||||
.value_name("seed_phrase")
|
||||
.help("Create a new wallet with the given 24-word seed phrase. Will fail if wallet already exists")
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("birthday")
|
||||
.long("birthday")
|
||||
.value_name("birthday")
|
||||
.help("Specify wallet birthday when restoring from seed. This is the earlist block height where the wallet has a transaction.")
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("server")
|
||||
.long("server")
|
||||
.value_name("server")
|
||||
.help("Lightwalletd server to connect to.")
|
||||
.takes_value(true)
|
||||
.default_value(lightclient::DEFAULT_SERVER))
|
||||
.arg(Arg::with_name("COMMAND")
|
||||
.help("Command to execute. If a command is not specified, Silentdragonlite-cli will start in interactive mode.")
|
||||
.required(false)
|
||||
.index(1))
|
||||
.arg(Arg::with_name("PARAMS")
|
||||
.help("Params to execute command with. Run the 'help' command to get usage help.")
|
||||
.required(false)
|
||||
.multiple(true))
|
||||
};
|
||||
}
|
||||
|
||||
/// This function is only tested against Linux.
|
||||
pub fn report_permission_error() {
|
||||
let user = std::env::var("USER").expect(
|
||||
"Unexpected error reading value of $USER!");
|
||||
let home = std::env::var("HOME").expect(
|
||||
"Unexpected error reading value of $HOME!");
|
||||
let current_executable = std::env::current_exe()
|
||||
.expect("Unexpected error reporting executable path!");
|
||||
eprintln!("USER: {}", user);
|
||||
eprintln!("HOME: {}", home);
|
||||
eprintln!("Executable: {}", current_executable.display());
|
||||
if home == "/" {
|
||||
eprintln!("User {} must have permission to write to '{}.silentdragonxlite/' .",
|
||||
user,
|
||||
home);
|
||||
} else {
|
||||
eprintln!("User {} must have permission to write to '{}/.silentdragonxlite/' .",
|
||||
user,
|
||||
home);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn startup(server: http::Uri, dangerous: bool, seed: Option<String>, birthday: u64, first_sync: bool, print_updates: bool)
|
||||
-> io::Result<(Sender<(String, Vec<String>)>, Receiver<String>)> {
|
||||
// Try to get the configuration
|
||||
let (config, latest_block_height) = LightClientConfig::create(server.clone(), dangerous)?;
|
||||
|
||||
let lightclient = match seed {
|
||||
Some(phrase) => Arc::new(LightClient::new_from_phrase(phrase, &config, birthday,0, false)?),
|
||||
None => {
|
||||
if config.wallet_exists() {
|
||||
Arc::new(LightClient::read_from_disk(&config)?)
|
||||
} else {
|
||||
println!("Creating a new wallet");
|
||||
Arc::new(LightClient::new(&config, latest_block_height)?)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize logging
|
||||
lightclient.init_logging()?;
|
||||
|
||||
// Print startup Messages
|
||||
info!(""); // Blank line
|
||||
info!("Starting Silentdragonlite-CLI");
|
||||
info!("Light Client config {:?}", config);
|
||||
|
||||
if print_updates {
|
||||
println!("Lightclient connecting to {}", config.server);
|
||||
}
|
||||
|
||||
// At startup, run a sync.
|
||||
if first_sync {
|
||||
let update = lightclient.do_sync(true);
|
||||
if print_updates {
|
||||
match update {
|
||||
Ok(j) => {
|
||||
println!("{}", j.pretty(2));
|
||||
},
|
||||
Err(e) => println!("{}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start the command loop
|
||||
let (command_tx, resp_rx) = command_loop(lightclient.clone());
|
||||
|
||||
Ok((command_tx, resp_rx))
|
||||
}
|
||||
|
||||
pub fn start_interactive(command_tx: Sender<(String, Vec<String>)>, resp_rx: Receiver<String>) {
|
||||
// `()` can be used when no completer is required
|
||||
let mut rl = rustyline::Editor::<()>::new();
|
||||
|
||||
println!("Ready!");
|
||||
|
||||
let send_command = |cmd: String, args: Vec<String>| -> String {
|
||||
command_tx.send((cmd.clone(), args)).unwrap();
|
||||
match resp_rx.recv() {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
let e = format!("Error executing command {}: {}", cmd, e);
|
||||
eprintln!("{}", e);
|
||||
error!("{}", e);
|
||||
return "".to_string()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let info = send_command("info".to_string(), vec![]);
|
||||
let chain_name = json::parse(&info).unwrap()["chain_name"].as_str().unwrap().to_string();
|
||||
|
||||
loop {
|
||||
// Read the height first
|
||||
let height = json::parse(&send_command("height".to_string(), vec!["false".to_string()])).unwrap()["height"].as_i64().unwrap();
|
||||
|
||||
let readline = rl.readline(&format!("({}) Block:{} (type 'help') >> ",
|
||||
chain_name, height));
|
||||
match readline {
|
||||
Ok(line) => {
|
||||
rl.add_history_entry(line.as_str());
|
||||
// Parse command line arguments
|
||||
let mut cmd_args = match shellwords::split(&line) {
|
||||
Ok(args) => args,
|
||||
Err(_) => {
|
||||
println!("Mismatched Quotes");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
if cmd_args.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let cmd = cmd_args.remove(0);
|
||||
let args: Vec<String> = cmd_args;
|
||||
|
||||
println!("{}", send_command(cmd, args));
|
||||
|
||||
// Special check for Quit command.
|
||||
if line == "quit" {
|
||||
break;
|
||||
}
|
||||
},
|
||||
Err(rustyline::error::ReadlineError::Interrupted) => {
|
||||
println!("CTRL-C");
|
||||
info!("CTRL-C");
|
||||
println!("{}", send_command("save".to_string(), vec![]));
|
||||
break
|
||||
},
|
||||
Err(rustyline::error::ReadlineError::Eof) => {
|
||||
println!("CTRL-D");
|
||||
info!("CTRL-D");
|
||||
println!("{}", send_command("save".to_string(), vec![]));
|
||||
break
|
||||
},
|
||||
Err(err) => {
|
||||
println!("Error: {:?}", err);
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn command_loop(lightclient: Arc<LightClient>) -> (Sender<(String, Vec<String>)>, Receiver<String>) {
|
||||
let (command_tx, command_rx) = channel::<(String, Vec<String>)>();
|
||||
let (resp_tx, resp_rx) = channel::<String>();
|
||||
|
||||
let lc = lightclient.clone();
|
||||
std::thread::spawn(move || {
|
||||
//start mempool_monitor
|
||||
match LightClient::start_mempool_monitor(lc.clone()) {
|
||||
Ok(_) => {},
|
||||
Err(e) => {
|
||||
|
||||
error!("Error starting mempool: {:?}", e);
|
||||
}
|
||||
}
|
||||
loop {
|
||||
match command_rx.recv_timeout(std::time::Duration::from_secs(5 * 60)) {
|
||||
Ok((cmd, args)) => {
|
||||
let args = args.iter().map(|s| s.as_ref()).collect();
|
||||
|
||||
let cmd_response = commands::do_user_command(&cmd, &args, lc.as_ref());
|
||||
resp_tx.send(cmd_response).unwrap();
|
||||
|
||||
if cmd == "quit" {
|
||||
info!("Quit");
|
||||
break;
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
// Timeout. Do a sync to keep the wallet up-to-date. False to whether to print updates on the console
|
||||
info!("Timeout, doing a sync");
|
||||
match lc.do_sync(false) {
|
||||
Ok(_) => {},
|
||||
Err(e) => {error!("{}", e)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
(command_tx, resp_rx)
|
||||
}
|
||||
|
||||
pub fn attempt_recover_seed(password: Option<String>) {
|
||||
// Create a Light Client Config in an attempt to recover the file.
|
||||
let config = LightClientConfig {
|
||||
server: "0.0.0.0:0".parse().unwrap(),
|
||||
chain_name: "main".to_string(),
|
||||
sapling_activation_height: 0,
|
||||
consensus_branch_id: "000000".to_string(),
|
||||
anchor_offset: 0,
|
||||
no_cert_verification: false,
|
||||
data_dir: None,
|
||||
};
|
||||
|
||||
match LightClient::attempt_recover_seed(&config, password) {
|
||||
Ok(_seed) => println!("Recovered seed "),
|
||||
Err(e) => eprintln!("Failed to recover seed. Error: {}", e)
|
||||
};
|
||||
}
|
||||
use std::io::{self};
|
||||
use std::sync::Arc;
|
||||
use std::sync::mpsc::{channel, Sender, Receiver};
|
||||
|
||||
use log::{info, error};
|
||||
|
||||
use silentdragonxlitelib::{commands,
|
||||
lightclient::{LightClient, LightClientConfig},
|
||||
};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! configure_clapapp {
|
||||
( $freshapp: expr ) => {
|
||||
$freshapp.version("1.0.0")
|
||||
.arg(Arg::with_name("dangerous")
|
||||
.long("dangerous")
|
||||
.help("Disable server TLS certificate verification. Use this if you're running a local lightwalletd with a self-signed certificate. WARNING: This is dangerous, don't use it with a server that is not your own.")
|
||||
.takes_value(false))
|
||||
.arg(Arg::with_name("nosync")
|
||||
.help("By default, Silentdragonlite-cli will sync the wallet at startup. Pass --nosync to prevent the automatic sync at startup.")
|
||||
.long("nosync")
|
||||
.short("n")
|
||||
.takes_value(false))
|
||||
.arg(Arg::with_name("recover")
|
||||
.long("recover")
|
||||
.help("Attempt to recover the seed from the wallet")
|
||||
.takes_value(false))
|
||||
.arg(Arg::with_name("password")
|
||||
.long("password")
|
||||
.help("When recovering seed, specify a password for the encrypted wallet")
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("seed")
|
||||
.short("s")
|
||||
.long("seed")
|
||||
.value_name("seed_phrase")
|
||||
.help("Create a new wallet with the given 24-word seed phrase. Will fail if wallet already exists")
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("birthday")
|
||||
.long("birthday")
|
||||
.value_name("birthday")
|
||||
.help("Specify wallet birthday when restoring from seed. This is the earlist block height where the wallet has a transaction.")
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("server")
|
||||
.long("server")
|
||||
.value_name("server")
|
||||
.help("Lightwalletd server to connect to.")
|
||||
.takes_value(true)
|
||||
.default_value(lightclient::DEFAULT_SERVER))
|
||||
.arg(Arg::with_name("COMMAND")
|
||||
.help("Command to execute. If a command is not specified, Silentdragonlite-cli will start in interactive mode.")
|
||||
.required(false)
|
||||
.index(1))
|
||||
.arg(Arg::with_name("PARAMS")
|
||||
.help("Params to execute command with. Run the 'help' command to get usage help.")
|
||||
.required(false)
|
||||
.multiple(true))
|
||||
};
|
||||
}
|
||||
|
||||
/// This function is only tested against Linux.
|
||||
pub fn report_permission_error() {
|
||||
let user = std::env::var("USER").expect(
|
||||
"Unexpected error reading value of $USER!");
|
||||
let home = std::env::var("HOME").expect(
|
||||
"Unexpected error reading value of $HOME!");
|
||||
let current_executable = std::env::current_exe()
|
||||
.expect("Unexpected error reporting executable path!");
|
||||
eprintln!("USER: {}", user);
|
||||
eprintln!("HOME: {}", home);
|
||||
eprintln!("Executable: {}", current_executable.display());
|
||||
if home == "/" {
|
||||
eprintln!("User {} must have permission to write to '{}.silentdragonxlite/' .",
|
||||
user,
|
||||
home);
|
||||
} else {
|
||||
eprintln!("User {} must have permission to write to '{}/.silentdragonxlite/' .",
|
||||
user,
|
||||
home);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn startup(server: http::Uri, dangerous: bool, seed: Option<String>, birthday: u64, first_sync: bool, print_updates: bool)
|
||||
-> io::Result<(Sender<(String, Vec<String>)>, Receiver<String>)> {
|
||||
// Try to get the configuration
|
||||
let (config, latest_block_height) = LightClientConfig::create(server.clone(), dangerous)?;
|
||||
|
||||
let lightclient = match seed {
|
||||
Some(phrase) => Arc::new(LightClient::new_from_phrase(phrase, &config, birthday,0, false)?),
|
||||
None => {
|
||||
if config.wallet_exists() {
|
||||
Arc::new(LightClient::read_from_disk(&config)?)
|
||||
} else {
|
||||
println!("Creating a new wallet");
|
||||
Arc::new(LightClient::new(&config, latest_block_height)?)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize logging
|
||||
lightclient.init_logging()?;
|
||||
|
||||
// Print startup Messages
|
||||
info!(""); // Blank line
|
||||
info!("Starting Silentdragonlite-CLI");
|
||||
info!("Light Client config {:?}", config);
|
||||
|
||||
if print_updates {
|
||||
println!("Lightclient connecting to {}", config.server);
|
||||
}
|
||||
|
||||
// At startup, run a sync.
|
||||
if first_sync {
|
||||
let update = lightclient.do_sync(true);
|
||||
if print_updates {
|
||||
match update {
|
||||
Ok(j) => {
|
||||
println!("{}", j.pretty(2));
|
||||
},
|
||||
Err(e) => println!("{}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start the command loop
|
||||
let (command_tx, resp_rx) = command_loop(lightclient.clone());
|
||||
|
||||
Ok((command_tx, resp_rx))
|
||||
}
|
||||
|
||||
pub fn start_interactive(command_tx: Sender<(String, Vec<String>)>, resp_rx: Receiver<String>) {
|
||||
// `()` can be used when no completer is required
|
||||
let mut rl = rustyline::Editor::<()>::new();
|
||||
|
||||
println!("Ready!");
|
||||
|
||||
let send_command = |cmd: String, args: Vec<String>| -> String {
|
||||
command_tx.send((cmd.clone(), args)).unwrap();
|
||||
match resp_rx.recv() {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
let e = format!("Error executing command {}: {}", cmd, e);
|
||||
eprintln!("{}", e);
|
||||
error!("{}", e);
|
||||
return "".to_string()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let info = send_command("info".to_string(), vec![]);
|
||||
let chain_name = json::parse(&info).unwrap()["chain_name"].as_str().unwrap().to_string();
|
||||
|
||||
loop {
|
||||
// Read the height first
|
||||
let height = json::parse(&send_command("height".to_string(), vec!["false".to_string()])).unwrap()["height"].as_i64().unwrap();
|
||||
|
||||
let readline = rl.readline(&format!("({}) Block:{} (type 'help') >> ",
|
||||
chain_name, height));
|
||||
match readline {
|
||||
Ok(line) => {
|
||||
rl.add_history_entry(line.as_str());
|
||||
// Parse command line arguments
|
||||
let mut cmd_args = match shellwords::split(&line) {
|
||||
Ok(args) => args,
|
||||
Err(_) => {
|
||||
println!("Mismatched Quotes");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
if cmd_args.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let cmd = cmd_args.remove(0);
|
||||
let args: Vec<String> = cmd_args;
|
||||
|
||||
println!("{}", send_command(cmd, args));
|
||||
|
||||
// Special check for Quit command.
|
||||
if line == "quit" {
|
||||
break;
|
||||
}
|
||||
},
|
||||
Err(rustyline::error::ReadlineError::Interrupted) => {
|
||||
println!("CTRL-C");
|
||||
info!("CTRL-C");
|
||||
println!("{}", send_command("save".to_string(), vec![]));
|
||||
break
|
||||
},
|
||||
Err(rustyline::error::ReadlineError::Eof) => {
|
||||
println!("CTRL-D");
|
||||
info!("CTRL-D");
|
||||
println!("{}", send_command("save".to_string(), vec![]));
|
||||
break
|
||||
},
|
||||
Err(err) => {
|
||||
println!("Error: {:?}", err);
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn command_loop(lightclient: Arc<LightClient>) -> (Sender<(String, Vec<String>)>, Receiver<String>) {
|
||||
let (command_tx, command_rx) = channel::<(String, Vec<String>)>();
|
||||
let (resp_tx, resp_rx) = channel::<String>();
|
||||
|
||||
let lc = lightclient.clone();
|
||||
std::thread::spawn(move || {
|
||||
//start mempool_monitor
|
||||
match LightClient::start_mempool_monitor(lc.clone()) {
|
||||
Ok(_) => {},
|
||||
Err(e) => {
|
||||
|
||||
error!("Error starting mempool: {:?}", e);
|
||||
}
|
||||
}
|
||||
loop {
|
||||
match command_rx.recv_timeout(std::time::Duration::from_secs(5 * 60)) {
|
||||
Ok((cmd, args)) => {
|
||||
let args = args.iter().map(|s| s.as_ref()).collect();
|
||||
|
||||
let cmd_response = commands::do_user_command(&cmd, &args, lc.as_ref());
|
||||
resp_tx.send(cmd_response).unwrap();
|
||||
|
||||
if cmd == "quit" {
|
||||
info!("Quit");
|
||||
break;
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
// Timeout. Do a sync to keep the wallet up-to-date. False to whether to print updates on the console
|
||||
info!("Timeout, doing a sync");
|
||||
match lc.do_sync(false) {
|
||||
Ok(_) => {},
|
||||
Err(e) => {error!("{}", e)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
(command_tx, resp_rx)
|
||||
}
|
||||
|
||||
pub fn attempt_recover_seed(password: Option<String>) {
|
||||
// Create a Light Client Config in an attempt to recover the file.
|
||||
let config = LightClientConfig {
|
||||
server: "0.0.0.0:0".parse().unwrap(),
|
||||
chain_name: "main".to_string(),
|
||||
sapling_activation_height: 0,
|
||||
consensus_branch_id: "000000".to_string(),
|
||||
anchor_offset: 0,
|
||||
no_cert_verification: false,
|
||||
data_dir: None,
|
||||
};
|
||||
|
||||
match LightClient::attempt_recover_seed(&config, password) {
|
||||
Ok(_seed) => println!("Recovered seed "),
|
||||
Err(e) => eprintln!("Failed to recover seed. Error: {}", e)
|
||||
};
|
||||
}
|
||||
|
||||
186
cli/src/main.rs
186
cli/src/main.rs
@@ -1,93 +1,93 @@
|
||||
use silentdragonxlitelib::lightclient::{self, LightClientConfig};
|
||||
use silentdragonxlite_cli::{configure_clapapp,
|
||||
report_permission_error,
|
||||
startup,
|
||||
start_interactive,
|
||||
attempt_recover_seed};
|
||||
//version::VERSION
|
||||
use log::error;
|
||||
|
||||
pub fn main() {
|
||||
// Get command line arguments
|
||||
use clap::{App, Arg};
|
||||
let fresh_app = App::new("SilentDragonXLite CLI");
|
||||
let configured_app = configure_clapapp!(fresh_app);
|
||||
let matches = configured_app.get_matches();
|
||||
|
||||
if matches.is_present("recover") {
|
||||
// Create a Light Client Config in an attempt to recover the file.
|
||||
attempt_recover_seed(matches.value_of("password").map(|s| s.to_string()));
|
||||
return;
|
||||
}
|
||||
|
||||
let command = matches.value_of("COMMAND");
|
||||
let params = matches.values_of("PARAMS").map(|v| v.collect()).or(Some(vec![])).unwrap();
|
||||
|
||||
let maybe_server = matches.value_of("server").map(|s| s.to_string());
|
||||
|
||||
let seed = matches.value_of("seed").map(|s| s.to_string());
|
||||
let maybe_birthday = matches.value_of("birthday");
|
||||
|
||||
if seed.is_some() && maybe_birthday.is_none() {
|
||||
eprintln!("ERROR!");
|
||||
eprintln!("Please specify the wallet birthday (eg. '--birthday 600000') to restore from seed.");
|
||||
eprintln!("This should be the block height where the wallet was created. If you don't remember the block height, you can pass '--birthday 0' to scan from the start of the blockchain.");
|
||||
return;
|
||||
}
|
||||
|
||||
let birthday = match maybe_birthday.unwrap_or("0").parse::<u64>() {
|
||||
Ok(b) => b,
|
||||
Err(e) => {
|
||||
eprintln!("Couldn't parse birthday. This should be a block number. Error={}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let server = LightClientConfig::get_server_or_default(maybe_server);
|
||||
|
||||
// Test to make sure the server has all of scheme, host and port
|
||||
if server.scheme_str().is_none() || server.host().is_none() || server.port().is_none() {
|
||||
eprintln!("Please provide the --server parameter as [scheme]://[host]:[port].\nYou provided: {}", server);
|
||||
return;
|
||||
}
|
||||
|
||||
let dangerous = matches.is_present("dangerous");
|
||||
let nosync = matches.is_present("nosync");
|
||||
let (command_tx, resp_rx) = match startup(server, dangerous, seed, birthday, !nosync, command.is_none()) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
let emsg = format!("Error during startup:{}\nIf you repeatedly run into this issue, you might have to restore your wallet from your seed phrase.", e);
|
||||
eprintln!("{}", emsg);
|
||||
error!("{}", emsg);
|
||||
if cfg!(target_os = "unix" ) {
|
||||
match e.raw_os_error() {
|
||||
Some(13) => report_permission_error(),
|
||||
_ => {},
|
||||
}
|
||||
};
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if command.is_none() {
|
||||
start_interactive(command_tx, resp_rx);
|
||||
} else {
|
||||
command_tx.send(
|
||||
(command.unwrap().to_string(),
|
||||
params.iter().map(|s| s.to_string()).collect::<Vec<String>>()))
|
||||
.unwrap();
|
||||
|
||||
match resp_rx.recv() {
|
||||
Ok(s) => println!("{}", s),
|
||||
Err(e) => {
|
||||
let e = format!("Error executing command {}: {}", command.unwrap(), e);
|
||||
eprintln!("{}", e);
|
||||
error!("{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Save before exit
|
||||
command_tx.send(("save".to_string(), vec![])).unwrap();
|
||||
resp_rx.recv().unwrap();
|
||||
}
|
||||
}
|
||||
use silentdragonxlitelib::lightclient::{self, LightClientConfig};
|
||||
use silentdragonxlite_cli::{configure_clapapp,
|
||||
report_permission_error,
|
||||
startup,
|
||||
start_interactive,
|
||||
attempt_recover_seed};
|
||||
//version::VERSION
|
||||
use log::error;
|
||||
|
||||
pub fn main() {
|
||||
// Get command line arguments
|
||||
use clap::{App, Arg};
|
||||
let fresh_app = App::new("SilentDragonXLite CLI");
|
||||
let configured_app = configure_clapapp!(fresh_app);
|
||||
let matches = configured_app.get_matches();
|
||||
|
||||
if matches.is_present("recover") {
|
||||
// Create a Light Client Config in an attempt to recover the file.
|
||||
attempt_recover_seed(matches.value_of("password").map(|s| s.to_string()));
|
||||
return;
|
||||
}
|
||||
|
||||
let command = matches.value_of("COMMAND");
|
||||
let params = matches.values_of("PARAMS").map(|v| v.collect()).or(Some(vec![])).unwrap();
|
||||
|
||||
let maybe_server = matches.value_of("server").map(|s| s.to_string());
|
||||
|
||||
let seed = matches.value_of("seed").map(|s| s.to_string());
|
||||
let maybe_birthday = matches.value_of("birthday");
|
||||
|
||||
if seed.is_some() && maybe_birthday.is_none() {
|
||||
eprintln!("ERROR!");
|
||||
eprintln!("Please specify the wallet birthday (eg. '--birthday 600000') to restore from seed.");
|
||||
eprintln!("This should be the block height where the wallet was created. If you don't remember the block height, you can pass '--birthday 0' to scan from the start of the blockchain.");
|
||||
return;
|
||||
}
|
||||
|
||||
let birthday = match maybe_birthday.unwrap_or("0").parse::<u64>() {
|
||||
Ok(b) => b,
|
||||
Err(e) => {
|
||||
eprintln!("Couldn't parse birthday. This should be a block number. Error={}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let server = LightClientConfig::get_server_or_default(maybe_server);
|
||||
|
||||
// Test to make sure the server has all of scheme, host and port
|
||||
if server.scheme_str().is_none() || server.host().is_none() || server.port().is_none() {
|
||||
eprintln!("Please provide the --server parameter as [scheme]://[host]:[port].\nYou provided: {}", server);
|
||||
return;
|
||||
}
|
||||
|
||||
let dangerous = matches.is_present("dangerous");
|
||||
let nosync = matches.is_present("nosync");
|
||||
let (command_tx, resp_rx) = match startup(server, dangerous, seed, birthday, !nosync, command.is_none()) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
let emsg = format!("Error during startup:{}\nIf you repeatedly run into this issue, you might have to restore your wallet from your seed phrase.", e);
|
||||
eprintln!("{}", emsg);
|
||||
error!("{}", emsg);
|
||||
if cfg!(target_os = "unix" ) {
|
||||
match e.raw_os_error() {
|
||||
Some(13) => report_permission_error(),
|
||||
_ => {},
|
||||
}
|
||||
};
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if command.is_none() {
|
||||
start_interactive(command_tx, resp_rx);
|
||||
} else {
|
||||
command_tx.send(
|
||||
(command.unwrap().to_string(),
|
||||
params.iter().map(|s| s.to_string()).collect::<Vec<String>>()))
|
||||
.unwrap();
|
||||
|
||||
match resp_rx.recv() {
|
||||
Ok(s) => println!("{}", s),
|
||||
Err(e) => {
|
||||
let e = format!("Error executing command {}: {}", command.unwrap(), e);
|
||||
eprintln!("{}", e);
|
||||
error!("{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Save before exit
|
||||
command_tx.send(("save".to_string(), vec![])).unwrap();
|
||||
resp_rx.recv().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
pub const VERSION:&str = "1.1.2";
|
||||
pub const VERSION:&str = "1.1.2";
|
||||
|
||||
Reference in New Issue
Block a user