diff --git a/rust-lightclient/proto/service.proto b/rust-lightclient/proto/service.proto index 2ae46d2..3beee7a 100644 --- a/rust-lightclient/proto/service.proto +++ b/rust-lightclient/proto/service.proto @@ -40,10 +40,13 @@ message SendResponse { // Empty placeholder. Someday we may want to specify e.g. a particular chain fork. message ChainSpec {} +message Empty {} + service CompactTxStreamer { rpc GetLatestBlock(ChainSpec) returns (BlockID) {} rpc GetBlock(BlockID) returns (CompactBlock) {} rpc GetBlockRange(BlockRange) returns (stream CompactBlock) {} rpc GetTransaction(TxFilter) returns (RawTransaction) {} rpc SendTransaction(RawTransaction) returns (SendResponse) {} + rpc GetLightdInfo(Empty) returns (SendResponse) {} } diff --git a/rust-lightclient/src/commands.rs b/rust-lightclient/src/commands.rs index 7874117..1441be3 100644 --- a/rust-lightclient/src/commands.rs +++ b/rust-lightclient/src/commands.rs @@ -45,6 +45,21 @@ impl Command for HelpCommand { } } +struct InfoCommand {} +impl Command for InfoCommand { + fn help(&self) { + println!("Gets server info"); + } + + fn short_help(&self) -> String { + "Get the lightwalletd server's info".to_string() + } + + fn exec(&self, args: &[String], lightclient: &LightClient) { + lightclient.do_info(); + } +} + struct AddressCommand {} impl Command for AddressCommand { fn help(&self) { @@ -60,12 +75,32 @@ impl Command for AddressCommand { } } +struct SendCommand {} +impl Command for SendCommand { + fn help(&self) { + println!("Send ZEC"); + } + + fn short_help(&self) -> String { + "Send ZEC to the given address".to_string() + } + + fn exec(&self, args: &[String], lightclient: &LightClient) { + lightclient.do_send( + "ztestsapling1x65nq4dgp0qfywgxcwk9n0fvm4fysmapgr2q00p85ju252h6l7mmxu2jg9cqqhtvzd69jwhgv8d".to_string(), + 1500000, + Some("Hello from the command".to_string())); + } +} + pub fn get_commands() -> Box>> { let mut map: HashMap> = HashMap::new(); map.insert("sync".to_string(), Box::new(SyncCommand{})); map.insert("help".to_string(), Box::new(HelpCommand{})); map.insert("address".to_string(), Box::new(AddressCommand{})); + map.insert("info".to_string(), Box::new(InfoCommand{})); + map.insert("send".to_string(), Box::new(SendCommand{})); Box::new(map) } @@ -77,4 +112,4 @@ pub fn do_user_command(cmd: String, lightclient: &LightClient) { println!("Unknown command : {}. Type 'help' for a list of commands", cmd); } } -} \ No newline at end of file +} diff --git a/rust-lightclient/src/lightclient.rs b/rust-lightclient/src/lightclient.rs index 93bb2f7..5124eb6 100644 --- a/rust-lightclient/src/lightclient.rs +++ b/rust-lightclient/src/lightclient.rs @@ -17,7 +17,7 @@ use tower_hyper::{client, util}; use tower_util::MakeService; use futures::stream::Stream; -use crate::grpc_client::{ChainSpec, BlockId, BlockRange, RawTransaction, TxFilter}; +use crate::grpc_client::{ChainSpec, BlockId, BlockRange, RawTransaction, TxFilter, Empty}; use crate::grpc_client::client::CompactTxStreamer; // Used below to return the grpc "Client" type to calling methods @@ -60,6 +60,26 @@ impl LightClient { println!("Balance: {}", self.wallet.balance()); } + pub fn do_info(&self) { + let uri: http::Uri = format!("http://127.0.0.1:9067").parse().unwrap(); + + let say_hello = self.make_grpc_client(uri).unwrap() + .and_then(move |mut client| { + client.get_lightd_info(Request::new(Empty{})) + }) + .and_then(move |response| { + //let tx = Transaction::read(&response.into_inner().data[..]).unwrap(); + println!("{:?}", response.into_inner()); + + Ok(()) + }) + .map_err(|e| { + println!("ERR = {:?}", e); + }); + + tokio::runtime::current_thread::Runtime::new().unwrap().block_on(say_hello).unwrap() + } + pub fn do_sync(&self) { // Sync is 3 parts // 1. Get the latest block