87 lines
2.5 KiB
Rust
Raw Normal View History

2019-09-03 12:03:00 -07:00
mod lightclient;
mod lightwallet;
2019-09-03 12:03:00 -07:00
mod address;
mod prover;
mod commands;
use lightclient::LightClient;
2019-09-03 12:03:00 -07:00
2019-09-03 17:01:34 -07:00
use rustyline::error::ReadlineError;
use rustyline::Editor;
2019-09-01 14:29:53 -07:00
pub mod grpc_client {
include!(concat!(env!("OUT_DIR"), "/cash.z.wallet.sdk.rpc.rs"));
}
2019-09-03 12:03:00 -07:00
2019-09-01 14:29:53 -07:00
pub fn main() {
2019-09-08 19:52:25 -07:00
use clap::{Arg, App};
let matches = App::new("Light Client")
.version("1.0")
.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))
.get_matches();
2019-09-08 21:17:54 -07:00
let mut lightclient = match LightClient::new(matches.value_of("seed")) {
Ok(lc) => lc,
Err(e) => {
eprintln!("Failed to start wallet. Error was:\n{}", e);
return;
}
};
2019-09-08 19:52:25 -07:00
2019-09-06 14:25:14 -07:00
println!("Starting Light Client");
2019-09-06 14:09:12 -07:00
2019-09-03 17:01:34 -07:00
// `()` can be used when no completer is required
let mut rl = Editor::<()>::new();
2019-09-06 14:25:14 -07:00
let _ = rl.load_history("history.txt");
println!("Ready!");
2019-09-03 17:01:34 -07:00
loop {
2019-09-06 14:25:14 -07:00
let readline = rl.readline(&format!("Block:{} (type 'help') >> ", lightclient.last_scanned_height()));
2019-09-03 17:01:34 -07:00
match readline {
Ok(line) => {
rl.add_history_entry(line.as_str());
2019-09-10 14:19:52 -07:00
// Parse command line arguments
let mut cmd_args = match shellwords::split(&line) {
Ok(args) => args,
Err(_) => {
println!("Mismatched Quotes");
continue;
}
};
let cmd = cmd_args.remove(0);
let args: Vec<&str> = cmd_args.iter().map(|s| s.as_ref()).collect();
commands::do_user_command(&cmd, &args, &mut lightclient);
2019-09-06 14:09:12 -07:00
// Special check for Quit command.
if line == "quit" {
break;
}
2019-09-03 17:01:34 -07:00
},
Err(ReadlineError::Interrupted) => {
println!("CTRL-C");
2019-09-06 14:09:12 -07:00
lightclient.do_save();
2019-09-03 17:01:34 -07:00
break
},
Err(ReadlineError::Eof) => {
println!("CTRL-D");
2019-09-06 14:09:12 -07:00
lightclient.do_save();
2019-09-03 17:01:34 -07:00
break
},
Err(err) => {
println!("Error: {:?}", err);
break
}
}
}
rl.save_history("history.txt").unwrap();
2019-09-01 14:29:53 -07:00
}