2019-09-03 12:03:00 -07:00
|
|
|
mod lightclient;
|
2019-09-05 10:56:19 -07:00
|
|
|
mod lightwallet;
|
2019-09-03 12:03:00 -07:00
|
|
|
mod address;
|
|
|
|
mod prover;
|
2019-09-05 10:56:19 -07:00
|
|
|
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-06 14:25:14 -07:00
|
|
|
println!("Starting Light Client");
|
2019-09-06 14:09:12 -07:00
|
|
|
let mut lightclient = LightClient::new();
|
|
|
|
|
|
|
|
// At startup, read the wallet.dat
|
|
|
|
commands::do_user_command(&"read".to_string(), &mut lightclient);
|
2019-09-05 10:56:19 -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-06 14:09:12 -07:00
|
|
|
commands::do_user_command(&line, &mut lightclient);
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|