From 165328abed4a0648e944f9a44355a9e81edcf824 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 17 Sep 2019 20:27:50 -0700 Subject: [PATCH] Address command --- Cargo.toml | 2 +- src/commands.rs | 24 ++++++++++++++++++++++++ src/lightclient.rs | 21 +++++++++++++++++++-- src/main.rs | 2 +- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 60ecca8..86681c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rust-lightclient" +name = "zeclite-cli" version = "0.1.0" edition = "2018" diff --git a/src/commands.rs b/src/commands.rs index 9ab62e8..ba22de2 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -141,10 +141,33 @@ impl Command for BalanceCommand { fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String { lightclient.do_sync(true); + format!("{}", lightclient.do_balance().pretty(2)) + } +} + + +struct AddressCommand {} +impl Command for AddressCommand { + fn help(&self) -> String { + let mut h = vec![]; + h.push("List current addresses in the wallet"); + h.push("Usage:"); + h.push("address"); + h.push(""); + + h.join("\n") + } + + fn short_help(&self) -> String { + "List all addresses in the wallet".to_string() + } + + fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String { format!("{}", lightclient.do_address().pretty(2)) } } + struct SendCommand {} impl Command for SendCommand { fn help(&self) -> String { @@ -327,6 +350,7 @@ pub fn get_commands() -> Box>> { map.insert("rescan".to_string(), Box::new(RescanCommand{})); map.insert("help".to_string(), Box::new(HelpCommand{})); map.insert("balance".to_string(), Box::new(BalanceCommand{})); + map.insert("address".to_string(), Box::new(AddressCommand{})); map.insert("info".to_string(), Box::new(InfoCommand{})); map.insert("send".to_string(), Box::new(SendCommand{})); map.insert("save".to_string(), Box::new(SaveCommand{})); diff --git a/src/lightclient.rs b/src/lightclient.rs index 295ad4e..f9c22b2 100644 --- a/src/lightclient.rs +++ b/src/lightclient.rs @@ -26,7 +26,7 @@ use tower_hyper::{client, util}; use tower_util::MakeService; use futures::stream::Stream; -use crate::grpc_client::{ChainSpec, BlockId, BlockRange, RawTransaction, TransparentAddress, +use crate::grpc_client::{ChainSpec, BlockId, BlockRange, RawTransaction, TransparentAddressBlockFilter, TxFilter, Empty}; use crate::grpc_client::client::CompactTxStreamer; @@ -160,7 +160,24 @@ impl LightClient { self.wallet.last_scanned_height() as u64 } - pub fn do_address(&self) -> json::JsonValue { + pub fn do_address(&self) -> json::JsonValue { + // Collect z addresses + let z_addresses = self.wallet.address.iter().map( |ad| { + encode_payment_address(HRP_SAPLING_PAYMENT_ADDRESS, &ad) + }).collect::>(); + + // Collect t addresses + let t_addresses = self.wallet.tkeys.iter().map( |sk| { + LightWallet::address_from_sk(&sk) + }).collect::>(); + + object!{ + "z_addresses" => z_addresses, + "t_addresses" => t_addresses, + } + } + + pub fn do_balance(&self) -> json::JsonValue { // Collect z addresses let z_addresses = self.wallet.address.iter().map( |ad| { let address = encode_payment_address(HRP_SAPLING_PAYMENT_ADDRESS, &ad); diff --git a/src/main.rs b/src/main.rs index baf012b..4123617 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,7 +41,7 @@ pub fn main() { // Get command line arguments let matches = App::new("ZecLite CLI") - .version("1.0") + .version("0.1.0") .arg(Arg::with_name("seed") .short("s") .long("seed")