mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-07-29 11:21:26 +00:00
List transactions
This commit is contained in:
@@ -124,6 +124,22 @@ impl Command for ReadCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TransactionsCommand {}
|
||||||
|
impl Command for TransactionsCommand {
|
||||||
|
fn help(&self) {
|
||||||
|
println!("Show transactions");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn short_help(&self) -> String {
|
||||||
|
"List all transactions in the wallet".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exec(&self, _args: &[String], lightclient: &mut LightClient) {
|
||||||
|
lightclient.do_list_transactions();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
struct QuitCommand {}
|
struct QuitCommand {}
|
||||||
impl Command for QuitCommand {
|
impl Command for QuitCommand {
|
||||||
fn help(&self) {
|
fn help(&self) {
|
||||||
@@ -151,6 +167,7 @@ pub fn get_commands() -> Box<HashMap<String, Box<dyn Command>>> {
|
|||||||
map.insert("save".to_string(), Box::new(SaveCommand{}));
|
map.insert("save".to_string(), Box::new(SaveCommand{}));
|
||||||
map.insert("read".to_string(), Box::new(ReadCommand{}));
|
map.insert("read".to_string(), Box::new(ReadCommand{}));
|
||||||
map.insert("quit".to_string(), Box::new(QuitCommand{}));
|
map.insert("quit".to_string(), Box::new(QuitCommand{}));
|
||||||
|
map.insert("list".to_string(), Box::new(TransactionsCommand{}));
|
||||||
|
|
||||||
Box::new(map)
|
Box::new(map)
|
||||||
}
|
}
|
||||||
|
@@ -114,6 +114,32 @@ impl LightClient {
|
|||||||
tokio::runtime::current_thread::Runtime::new().unwrap().block_on(say_hello).unwrap()
|
tokio::runtime::current_thread::Runtime::new().unwrap().block_on(say_hello).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn do_list_transactions(&self) {
|
||||||
|
// Go over all the transactions
|
||||||
|
self.wallet.txs.read().unwrap().iter().for_each(
|
||||||
|
| (k, v) | {
|
||||||
|
println!("Block {}", v.block);
|
||||||
|
println!("Txid {}", k);
|
||||||
|
v.notes.iter().for_each( |nd| {
|
||||||
|
println!("Spent in txid {}", match nd.spent {
|
||||||
|
Some(txid) => format!("{}", txid),
|
||||||
|
_ => "(not spent)".to_string()
|
||||||
|
});
|
||||||
|
println!("Value {}", nd.note.value);
|
||||||
|
println!("Memo {}", match &nd.memo {
|
||||||
|
Some(memo) => {
|
||||||
|
match memo.to_utf8() {
|
||||||
|
Some(Ok(memo_str)) => memo_str,
|
||||||
|
_ => "".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => "".to_string()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn do_sync(&self) {
|
pub fn do_sync(&self) {
|
||||||
// Sync is 3 parts
|
// Sync is 3 parts
|
||||||
// 1. Get the latest block
|
// 1. Get the latest block
|
||||||
@@ -185,7 +211,7 @@ impl LightClient {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<(TxId, Option<Memo>)>>();
|
.collect::<Vec<(TxId, Option<Memo>)>>();
|
||||||
|
|
||||||
println!("{:?}", txids_and_memos);
|
//println!("{:?}", txids_and_memos);
|
||||||
// TODO: Assert that all the memos here are None
|
// TODO: Assert that all the memos here are None
|
||||||
|
|
||||||
txids_to_fetch = txids_and_memos.iter()
|
txids_to_fetch = txids_and_memos.iter()
|
||||||
@@ -197,7 +223,7 @@ impl LightClient {
|
|||||||
// read the memos
|
// read the memos
|
||||||
for txid in txids_to_fetch {
|
for txid in txids_to_fetch {
|
||||||
let light_wallet_clone = self.wallet.clone();
|
let light_wallet_clone = self.wallet.clone();
|
||||||
println!("Scanning txid {}", txid);
|
println!("Fetching full Tx: {}", txid);
|
||||||
|
|
||||||
self.fetch_full_tx(txid, move |tx_bytes: &[u8] | {
|
self.fetch_full_tx(txid, move |tx_bytes: &[u8] | {
|
||||||
let tx = Transaction::read(tx_bytes).unwrap();
|
let tx = Transaction::read(tx_bytes).unwrap();
|
||||||
@@ -222,7 +248,7 @@ impl LightClient {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<Option<String>>>();
|
.collect::<Vec<Option<String>>>();
|
||||||
|
|
||||||
println!("All Wallet Txns {:?}", memos);
|
//println!("All Wallet Txns {:?}", memos);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn do_send(&self, addr: String, value: u64, memo: Option<String>) {
|
pub fn do_send(&self, addr: String, value: u64, memo: Option<String>) {
|
||||||
|
Reference in New Issue
Block a user