Browse Source

Merge pull request #14 from DenioD/master

add coinsupply rpc call
checkpoints
Duke Leto 5 years ago
committed by GitHub
parent
commit
b5534d6f83
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      lib/proto/service.proto
  2. 22
      lib/src/commands.rs
  3. 19
      lib/src/grpcconnector.rs
  4. 18
      lib/src/lightclient.rs

10
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) {}
}

22
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<HashMap<String, Box<dyn Command>>> {
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{}));

19
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<LightdInfo, String> {
tokio::runtime::current_thread::Runtime::new().unwrap().block_on(runner)
}
pub fn get_coinsupply(uri: http::Uri, no_cert: bool) -> Result<Coinsupply, String> {
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<F : 'static + std::marker::Send>(uri: &http::Uri, start_height: u64, end_height: u64, no_cert: bool, mut c: F)
where F : FnMut(&[u8], u64) {

18
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<JsonValue, &str> {
if !self.wallet.read().unwrap().is_unlocked_for_spending() {
error!("Wallet is locked");

Loading…
Cancel
Save