mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-02-12 02:05:47 +00:00
Make lightclient not mut
This commit is contained in:
parent
194c6b2780
commit
d21c87acef
@ -7,7 +7,7 @@ pub trait Command {
|
|||||||
|
|
||||||
fn short_help(&self) -> String;
|
fn short_help(&self) -> String;
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &mut LightClient);
|
fn exec(&self, _args: &[&str], lightclient: &LightClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SyncCommand {}
|
struct SyncCommand {}
|
||||||
@ -20,7 +20,7 @@ impl Command for SyncCommand {
|
|||||||
"Download CompactBlocks and sync to the server".to_string()
|
"Download CompactBlocks and sync to the server".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &mut LightClient) {
|
fn exec(&self, _args: &[&str], lightclient: &LightClient) {
|
||||||
lightclient.do_sync();
|
lightclient.do_sync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ impl Command for RescanCommand {
|
|||||||
"Rescan the wallet, downloading and scanning all blocks and transactions".to_string()
|
"Rescan the wallet, downloading and scanning all blocks and transactions".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &mut LightClient) {
|
fn exec(&self, _args: &[&str], lightclient: &LightClient) {
|
||||||
lightclient.do_rescan();
|
lightclient.do_rescan();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ impl Command for HelpCommand {
|
|||||||
"Lists all available commands".to_string()
|
"Lists all available commands".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], _: &mut LightClient) {
|
fn exec(&self, _args: &[&str], _: &LightClient) {
|
||||||
// Print a list of all commands
|
// Print a list of all commands
|
||||||
println!("Available commands:");
|
println!("Available commands:");
|
||||||
get_commands().iter().for_each(| (cmd, obj) | {
|
get_commands().iter().for_each(| (cmd, obj) | {
|
||||||
@ -70,7 +70,7 @@ impl Command for InfoCommand {
|
|||||||
"Get the lightwalletd server's info".to_string()
|
"Get the lightwalletd server's info".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &mut LightClient) {
|
fn exec(&self, _args: &[&str], lightclient: &LightClient) {
|
||||||
lightclient.do_info();
|
lightclient.do_info();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ impl Command for AddressCommand {
|
|||||||
"List all current addresses".to_string()
|
"List all current addresses".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &mut LightClient) {
|
fn exec(&self, _args: &[&str], lightclient: &LightClient) {
|
||||||
let res = lightclient.do_address();
|
let res = lightclient.do_address();
|
||||||
println!("{}", res.pretty(2));
|
println!("{}", res.pretty(2));
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ impl Command for SendCommand {
|
|||||||
"Send ZEC to the given address".to_string()
|
"Send ZEC to the given address".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, args: &[&str], lightclient: &mut LightClient) {
|
fn exec(&self, args: &[&str], lightclient: &LightClient) {
|
||||||
// Parse the args.
|
// Parse the args.
|
||||||
// 1 - Destination address. T or Z address
|
// 1 - Destination address. T or Z address
|
||||||
if args.len() < 2 || args.len() > 3 {
|
if args.len() < 2 || args.len() > 3 {
|
||||||
@ -136,7 +136,7 @@ impl Command for SaveCommand {
|
|||||||
"Save wallet file to disk".to_string()
|
"Save wallet file to disk".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &mut LightClient) {
|
fn exec(&self, _args: &[&str], lightclient: &LightClient) {
|
||||||
lightclient.do_save();
|
lightclient.do_save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ impl Command for SeedCommand {
|
|||||||
"Display the seed phrase".to_string()
|
"Display the seed phrase".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &mut LightClient) {
|
fn exec(&self, _args: &[&str], lightclient: &LightClient) {
|
||||||
let phrase = lightclient.do_seed_phrase();
|
let phrase = lightclient.do_seed_phrase();
|
||||||
|
|
||||||
println!("PLEASE SAVE YOUR SEED PHRASE CAREFULLY AND DO NOT SHARE IT");
|
println!("PLEASE SAVE YOUR SEED PHRASE CAREFULLY AND DO NOT SHARE IT");
|
||||||
@ -171,7 +171,7 @@ impl Command for TransactionsCommand {
|
|||||||
"List all transactions in the wallet".to_string()
|
"List all transactions in the wallet".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &mut LightClient) {
|
fn exec(&self, _args: &[&str], lightclient: &LightClient) {
|
||||||
let txns = lightclient.do_list_transactions();
|
let txns = lightclient.do_list_transactions();
|
||||||
println!("{}", txns.pretty(2));
|
println!("{}", txns.pretty(2));
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ impl Command for NotesCommand {
|
|||||||
"List all sapling notes in the wallet".to_string()
|
"List all sapling notes in the wallet".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, args: &[&str], lightclient: &mut LightClient) {
|
fn exec(&self, args: &[&str], lightclient: &LightClient) {
|
||||||
// Parse the args.
|
// Parse the args.
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
self.help();
|
self.help();
|
||||||
@ -222,7 +222,7 @@ impl Command for QuitCommand {
|
|||||||
"Quit the lightwallet, saving state to disk".to_string()
|
"Quit the lightwallet, saving state to disk".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &mut LightClient) {
|
fn exec(&self, _args: &[&str], lightclient: &LightClient) {
|
||||||
lightclient.do_save();
|
lightclient.do_save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -248,7 +248,7 @@ pub fn get_commands() -> Box<HashMap<String, Box<dyn Command>>> {
|
|||||||
Box::new(map)
|
Box::new(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn do_user_command(cmd: &str, args: &Vec<&str>, lightclient: &mut LightClient) {
|
pub fn do_user_command(cmd: &str, args: &Vec<&str>, lightclient: &LightClient) {
|
||||||
match get_commands().get(cmd) {
|
match get_commands().get(cmd) {
|
||||||
Some(cmd) => cmd.exec(args, lightclient),
|
Some(cmd) => cmd.exec(args, lightclient),
|
||||||
None => {
|
None => {
|
||||||
|
@ -4,6 +4,8 @@ mod address;
|
|||||||
mod prover;
|
mod prover;
|
||||||
mod commands;
|
mod commands;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use lightclient::LightClient;
|
use lightclient::LightClient;
|
||||||
|
|
||||||
use rustyline::error::ReadlineError;
|
use rustyline::error::ReadlineError;
|
||||||
@ -30,23 +32,28 @@ pub fn main() {
|
|||||||
|
|
||||||
let seed: Option<String> = matches.value_of("seed").map(|s| s.to_string());
|
let seed: Option<String> = matches.value_of("seed").map(|s| s.to_string());
|
||||||
|
|
||||||
|
let lightclient = match LightClient::new(seed) {
|
||||||
|
Ok(lc) => Arc::new(lc),
|
||||||
|
Err(e) => { eprintln!("Failed to start wallet. Error was:\n{}", e); return; }
|
||||||
|
};
|
||||||
|
|
||||||
let (command_tx, command_rx) = std::sync::mpsc::channel::<(String, Vec<String>)>();
|
let (command_tx, command_rx) = std::sync::mpsc::channel::<(String, Vec<String>)>();
|
||||||
let (resp_tx, resp_rx) = std::sync::mpsc::channel::<String>();
|
let (resp_tx, resp_rx) = std::sync::mpsc::channel::<String>();
|
||||||
|
|
||||||
|
let lc = lightclient.clone();
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let mut lightclient = match LightClient::new(seed) {
|
|
||||||
Ok(lc) => lc,
|
|
||||||
Err(e) => { eprintln!("Failed to start wallet. Error was:\n{}", e); return; }
|
|
||||||
};
|
|
||||||
|
|
||||||
println!("Starting Light Client");
|
println!("Starting Light Client");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match command_rx.recv() {
|
match command_rx.recv() {
|
||||||
Ok((cmd, args)) => {
|
Ok((cmd, args)) => {
|
||||||
let args = args.iter().map(|s| s.as_ref()).collect();
|
let args = args.iter().map(|s| s.as_ref()).collect();
|
||||||
commands::do_user_command(&cmd, &args, &mut lightclient);
|
commands::do_user_command(&cmd, &args, &lc);
|
||||||
resp_tx.send("Finished command".to_string()).unwrap();
|
resp_tx.send("Finished command".to_string()).unwrap();
|
||||||
|
|
||||||
|
if cmd == "quit" {
|
||||||
|
break;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@ -62,7 +69,7 @@ pub fn main() {
|
|||||||
println!("Ready!");
|
println!("Ready!");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let readline = rl.readline(">>"); //&format!("Block:{} (type 'help') >> ", lightclient.last_scanned_height()));
|
let readline = rl.readline(&format!("Block:{} (type 'help') >> ", lightclient.last_scanned_height()));
|
||||||
match readline {
|
match readline {
|
||||||
Ok(line) => {
|
Ok(line) => {
|
||||||
rl.add_history_entry(line.as_str());
|
rl.add_history_entry(line.as_str());
|
||||||
@ -97,12 +104,12 @@ pub fn main() {
|
|||||||
},
|
},
|
||||||
Err(ReadlineError::Interrupted) => {
|
Err(ReadlineError::Interrupted) => {
|
||||||
println!("CTRL-C");
|
println!("CTRL-C");
|
||||||
//lightclient.do_save();
|
lightclient.do_save();
|
||||||
break
|
break
|
||||||
},
|
},
|
||||||
Err(ReadlineError::Eof) => {
|
Err(ReadlineError::Eof) => {
|
||||||
println!("CTRL-D");
|
println!("CTRL-D");
|
||||||
//lightclient.do_save();
|
lightclient.do_save();
|
||||||
break
|
break
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user