mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-02-21 05:45:46 +00:00
add command prompt
This commit is contained in:
parent
4d8bab394a
commit
698c65a284
3
rust-lightclient/.gitignore
vendored
3
rust-lightclient/.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
target/
|
target/
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
.vscode/
|
.vscode/
|
||||||
|
history.txt
|
||||||
|
@ -19,6 +19,7 @@ tower-service = "0.2"
|
|||||||
tower-util = "0.1"
|
tower-util = "0.1"
|
||||||
hex = "0.3"
|
hex = "0.3"
|
||||||
protobuf = "2"
|
protobuf = "2"
|
||||||
|
rustyline = "5.0.2"
|
||||||
|
|
||||||
|
|
||||||
[dependencies.bellman]
|
[dependencies.bellman]
|
||||||
|
@ -151,7 +151,11 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let hash = match hex::decode(hash) {
|
let hash = match hex::decode(hash) {
|
||||||
Ok(hash) => BlockHash::from_slice(&hash),
|
Ok(hash) => {
|
||||||
|
let mut r = hash;
|
||||||
|
r.reverse();
|
||||||
|
BlockHash::from_slice(&r)
|
||||||
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("{}", e);
|
eprintln!("{}", e);
|
||||||
return false;
|
return false;
|
||||||
@ -263,7 +267,7 @@ impl Client {
|
|||||||
// If the last scanned block is rescanned, check it still matches.
|
// If the last scanned block is rescanned, check it still matches.
|
||||||
if let Some(hash) = self.blocks.read().unwrap().last().map(|block| block.hash) {
|
if let Some(hash) = self.blocks.read().unwrap().last().map(|block| block.hash) {
|
||||||
if block.hash() != hash {
|
if block.hash() != hash {
|
||||||
eprintln!("Block hash does not match");
|
eprintln!("Block hash does not match for block {}. {} vs {}", height, block.hash(), hash);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,9 @@ mod lightclient;
|
|||||||
mod address;
|
mod address;
|
||||||
mod prover;
|
mod prover;
|
||||||
|
|
||||||
|
use rustyline::error::ReadlineError;
|
||||||
|
use rustyline::Editor;
|
||||||
|
|
||||||
use crate::grpc_client::{ChainSpec, BlockId, BlockRange};
|
use crate::grpc_client::{ChainSpec, BlockId, BlockRange};
|
||||||
|
|
||||||
pub mod grpc_client {
|
pub mod grpc_client {
|
||||||
@ -23,6 +26,43 @@ pub mod grpc_client {
|
|||||||
|
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
// `()` can be used when no completer is required
|
||||||
|
let mut rl = Editor::<()>::new();
|
||||||
|
if rl.load_history("history.txt").is_err() {
|
||||||
|
println!("No previous history.");
|
||||||
|
}
|
||||||
|
loop {
|
||||||
|
let readline = rl.readline(">> ");
|
||||||
|
match readline {
|
||||||
|
Ok(line) => {
|
||||||
|
rl.add_history_entry(line.as_str());
|
||||||
|
do_user_command(line);
|
||||||
|
},
|
||||||
|
Err(ReadlineError::Interrupted) => {
|
||||||
|
println!("CTRL-C");
|
||||||
|
break
|
||||||
|
},
|
||||||
|
Err(ReadlineError::Eof) => {
|
||||||
|
println!("CTRL-D");
|
||||||
|
break
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
|
println!("Error: {:?}", err);
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rl.save_history("history.txt").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn do_user_command(cmd: String) {
|
||||||
|
match cmd.as_ref() {
|
||||||
|
"sync" => { do_sync() }
|
||||||
|
_ => { println!("Unknown command {}", cmd); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn do_sync() {
|
||||||
let lightclient = Arc::new(lightclient::Client::new());
|
let lightclient = Arc::new(lightclient::Client::new());
|
||||||
lightclient.set_initial_block(500000,
|
lightclient.set_initial_block(500000,
|
||||||
"004fada8d4dbc5e80b13522d2c6bd0116113c9b7197f0c6be69bc7a62f2824cd",
|
"004fada8d4dbc5e80b13522d2c6bd0116113c9b7197f0c6be69bc7a62f2824cd",
|
||||||
@ -47,7 +87,7 @@ pub fn main() {
|
|||||||
let simple_callback = move |encoded_block: &[u8]| {
|
let simple_callback = move |encoded_block: &[u8]| {
|
||||||
local_lightclient.scan_block(encoded_block);
|
local_lightclient.scan_block(encoded_block);
|
||||||
|
|
||||||
println!("Block Height: {}, Balance = {}", local_lightclient.last_scanned_height(), local_lightclient.balance());
|
print!("Block Height: {}, Balance = {}\r", local_lightclient.last_scanned_height(), local_lightclient.balance());
|
||||||
};
|
};
|
||||||
|
|
||||||
read_blocks(last_scanned_height, end_height, simple_callback);
|
read_blocks(last_scanned_height, end_height, simple_callback);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user