add coinsupply rpc call
This commit is contained in:
@@ -57,6 +57,15 @@ message LightdInfo {
|
|||||||
uint64 notarized = 10;
|
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 {
|
message TransparentAddress {
|
||||||
string address = 1;
|
string address = 1;
|
||||||
}
|
}
|
||||||
@@ -81,4 +90,5 @@ service CompactTxStreamer {
|
|||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
rpc GetLightdInfo(Empty) returns (LightdInfo) {}
|
rpc GetLightdInfo(Empty) returns (LightdInfo) {}
|
||||||
|
rpc GetCoinsupply(Empty) returns (Coinsupply) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {}
|
struct BalanceCommand {}
|
||||||
impl Command for BalanceCommand {
|
impl Command for BalanceCommand {
|
||||||
fn help(&self) -> String {
|
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("height".to_string(), Box::new(HeightCommand{}));
|
||||||
map.insert("export".to_string(), Box::new(ExportCommand{}));
|
map.insert("export".to_string(), Box::new(ExportCommand{}));
|
||||||
map.insert("info".to_string(), Box::new(InfoCommand{}));
|
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("send".to_string(), Box::new(SendCommand{}));
|
||||||
map.insert("save".to_string(), Box::new(SaveCommand{}));
|
map.insert("save".to_string(), Box::new(SaveCommand{}));
|
||||||
map.insert("quit".to_string(), Box::new(QuitCommand{}));
|
map.insert("quit".to_string(), Box::new(QuitCommand{}));
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use tokio::net::tcp::TcpStream;
|
|||||||
use zcash_primitives::transaction::{TxId};
|
use zcash_primitives::transaction::{TxId};
|
||||||
|
|
||||||
use crate::grpc_client::{ChainSpec, BlockId, BlockRange, RawTransaction,
|
use crate::grpc_client::{ChainSpec, BlockId, BlockRange, RawTransaction,
|
||||||
TransparentAddressBlockFilter, TxFilter, Empty, LightdInfo};
|
TransparentAddressBlockFilter, TxFilter, Empty, LightdInfo,Coinsupply};
|
||||||
use crate::grpc_client::client::CompactTxStreamer;
|
use crate::grpc_client::client::CompactTxStreamer;
|
||||||
|
|
||||||
mod danger {
|
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)
|
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)
|
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) {
|
where F : FnMut(&[u8], u64) {
|
||||||
|
|||||||
@@ -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> {
|
pub fn do_seed_phrase(&self) -> Result<JsonValue, &str> {
|
||||||
if !self.wallet.read().unwrap().is_unlocked_for_spending() {
|
if !self.wallet.read().unwrap().is_unlocked_for_spending() {
|
||||||
error!("Wallet is locked");
|
error!("Wallet is locked");
|
||||||
|
|||||||
Reference in New Issue
Block a user