diff --git a/lib/proto/service.proto b/lib/proto/service.proto index 322e56b..0e16896 100644 --- a/lib/proto/service.proto +++ b/lib/proto/service.proto @@ -57,6 +57,15 @@ message LightdInfo { uint64 notarized = 10; } +message Coinsupply { + string result = 1; + string coin = 2; + int64 height = 3; + int64 supply = 4; + int64 zfunds = 5; + int64 total = 6; +} + message TransparentAddress { string address = 1; } @@ -81,4 +90,5 @@ service CompactTxStreamer { // Misc rpc GetLightdInfo(Empty) returns (LightdInfo) {} + rpc GetCoinsupply(Empty) returns (Coinsupply) {} } diff --git a/lib/src/commands.rs b/lib/src/commands.rs index 8e0fa15..9fb69c6 100644 --- a/lib/src/commands.rs +++ b/lib/src/commands.rs @@ -202,6 +202,27 @@ impl Command for InfoCommand { } } +struct CoinsupplyCommand {} +impl Command for CoinsupplyCommand { + fn help(&self) -> String { + let mut h = vec![]; + h.push("Get info about the actual Coinsupply of Hush"); + h.push("Usage:"); + h.push("coinsupply"); + h.push(""); + + h.join("\n") + } + + fn short_help(&self) -> String { + "Get the Coinsupply info".to_string() + } + + fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String { + lightclient.do_coinsupply() + } +} + struct BalanceCommand {} impl Command for BalanceCommand { fn help(&self) -> String { @@ -803,6 +824,7 @@ pub fn get_commands() -> Box>> { map.insert("height".to_string(), Box::new(HeightCommand{})); map.insert("export".to_string(), Box::new(ExportCommand{})); map.insert("info".to_string(), Box::new(InfoCommand{})); + map.insert("coinsupply".to_string(), Box::new(CoinsupplyCommand{})); map.insert("send".to_string(), Box::new(SendCommand{})); map.insert("save".to_string(), Box::new(SaveCommand{})); map.insert("quit".to_string(), Box::new(QuitCommand{})); diff --git a/lib/src/grpcconnector.rs b/lib/src/grpcconnector.rs index 10d0d88..4b4b26e 100644 --- a/lib/src/grpcconnector.rs +++ b/lib/src/grpcconnector.rs @@ -20,7 +20,7 @@ use tokio::net::tcp::TcpStream; use zcash_primitives::transaction::{TxId}; use crate::grpc_client::{ChainSpec, BlockId, BlockRange, RawTransaction, - TransparentAddressBlockFilter, TxFilter, Empty, LightdInfo}; + TransparentAddressBlockFilter, TxFilter, Empty, LightdInfo,Coinsupply}; use crate::grpc_client::client::CompactTxStreamer; mod danger { @@ -169,6 +169,23 @@ pub fn get_info(uri: http::Uri, no_cert: bool) -> Result { tokio::runtime::current_thread::Runtime::new().unwrap().block_on(runner) } +pub fn get_coinsupply(uri: http::Uri, no_cert: bool) -> Result { + let runner = make_grpc_client!(uri.scheme_str().unwrap(), uri.host().unwrap(), uri.port_part().unwrap(), no_cert) + .and_then(move |mut client| { + client.get_coinsupply(Request::new(Empty{})) + .map_err(|e| { + format!("ERR = {:?}", e) + }) + .and_then(move |response| { + Ok(response.into_inner()) + }) + .map_err(|e| { + format!("ERR = {:?}", e) + }) + }); + + tokio::runtime::current_thread::Runtime::new().unwrap().block_on(runner) +} pub fn fetch_blocks(uri: &http::Uri, start_height: u64, end_height: u64, no_cert: bool, mut c: F) where F : FnMut(&[u8], u64) { diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index 57ed3ec..7075170 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -603,6 +603,24 @@ impl LightClient { } } + pub fn do_coinsupply(&self) -> String { + match get_coinsupply(self.get_server_uri(), self.config.no_cert_verification) { + Ok(i) => { + let o = object!{ + "result" => i.result, + "coin" => i.coin, + "height" => i.height, + "supply" => i.supply, + "zfunds" => i.zfunds, + "total" => i.total, + + }; + o.pretty(2) + }, + Err(e) => e + } + } + pub fn do_seed_phrase(&self) -> Result { if !self.wallet.read().unwrap().is_unlocked_for_spending() { error!("Wallet is locked");