Address command

This commit is contained in:
Aditya Kulkarni 2019-09-17 20:27:50 -07:00
parent f93267507f
commit 165328abed
4 changed files with 45 additions and 4 deletions

View File

@ -1,5 +1,5 @@
[package] [package]
name = "rust-lightclient" name = "zeclite-cli"
version = "0.1.0" version = "0.1.0"
edition = "2018" edition = "2018"

View File

@ -141,10 +141,33 @@ impl Command for BalanceCommand {
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String { fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
lightclient.do_sync(true); 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)) format!("{}", lightclient.do_address().pretty(2))
} }
} }
struct SendCommand {} struct SendCommand {}
impl Command for SendCommand { impl Command for SendCommand {
fn help(&self) -> String { fn help(&self) -> String {
@ -327,6 +350,7 @@ pub fn get_commands() -> Box<HashMap<String, Box<dyn Command>>> {
map.insert("rescan".to_string(), Box::new(RescanCommand{})); map.insert("rescan".to_string(), Box::new(RescanCommand{}));
map.insert("help".to_string(), Box::new(HelpCommand{})); map.insert("help".to_string(), Box::new(HelpCommand{}));
map.insert("balance".to_string(), Box::new(BalanceCommand{})); 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("info".to_string(), Box::new(InfoCommand{}));
map.insert("send".to_string(), Box::new(SendCommand{})); map.insert("send".to_string(), Box::new(SendCommand{}));
map.insert("save".to_string(), Box::new(SaveCommand{})); map.insert("save".to_string(), Box::new(SaveCommand{}));

View File

@ -26,7 +26,7 @@ use tower_hyper::{client, util};
use tower_util::MakeService; use tower_util::MakeService;
use futures::stream::Stream; use futures::stream::Stream;
use crate::grpc_client::{ChainSpec, BlockId, BlockRange, RawTransaction, TransparentAddress, use crate::grpc_client::{ChainSpec, BlockId, BlockRange, RawTransaction,
TransparentAddressBlockFilter, TxFilter, Empty}; TransparentAddressBlockFilter, TxFilter, Empty};
use crate::grpc_client::client::CompactTxStreamer; use crate::grpc_client::client::CompactTxStreamer;
@ -161,6 +161,23 @@ impl LightClient {
} }
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::<Vec<String>>();
// Collect t addresses
let t_addresses = self.wallet.tkeys.iter().map( |sk| {
LightWallet::address_from_sk(&sk)
}).collect::<Vec<String>>();
object!{
"z_addresses" => z_addresses,
"t_addresses" => t_addresses,
}
}
pub fn do_balance(&self) -> json::JsonValue {
// Collect z addresses // Collect z addresses
let z_addresses = self.wallet.address.iter().map( |ad| { let z_addresses = self.wallet.address.iter().map( |ad| {
let address = encode_payment_address(HRP_SAPLING_PAYMENT_ADDRESS, &ad); let address = encode_payment_address(HRP_SAPLING_PAYMENT_ADDRESS, &ad);

View File

@ -41,7 +41,7 @@ pub fn main() {
// Get command line arguments // Get command line arguments
let matches = App::new("ZecLite CLI") let matches = App::new("ZecLite CLI")
.version("1.0") .version("0.1.0")
.arg(Arg::with_name("seed") .arg(Arg::with_name("seed")
.short("s") .short("s")
.long("seed") .long("seed")