first add of getrawmempool - work in progress

This commit is contained in:
DenioD
2020-05-12 00:19:51 +02:00
parent 1da0f0e321
commit 431847ab49
4 changed files with 58 additions and 1 deletions

View File

@@ -223,6 +223,27 @@ impl Command for CoinsupplyCommand {
}
}
struct RawMempoolCommand {}
impl Command for RawMempoolCommand {
fn help(&self) -> String {
let mut h = vec![];
h.push("Get info about the actual raw of Hush");
h.push("Usage:");
h.push("rawmempool");
h.push("");
h.join("\n")
}
fn short_help(&self) -> String {
"Get the RawMemPool info".to_string()
}
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
lightclient.do_rawmempool()
}
}
struct BalanceCommand {}
impl Command for BalanceCommand {
fn help(&self) -> String {
@@ -856,6 +877,7 @@ pub fn get_commands() -> Box<HashMap<String, Box<dyn Command>>> {
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("rawmempool".to_string(), Box::new(RawMempoolCommand{}));
map.insert("send".to_string(), Box::new(SendCommand{}));
map.insert("save".to_string(), Box::new(SaveCommand{}));
map.insert("quit".to_string(), Box::new(QuitCommand{}));

View File

@@ -3,7 +3,7 @@ use std::sync::Arc;
use zcash_primitives::transaction::{TxId};
use crate::grpc_client::{ChainSpec, BlockId, BlockRange, RawTransaction,
TransparentAddressBlockFilter, TxFilter, Empty, LightdInfo, Coinsupply};
TransparentAddressBlockFilter, TxFilter, Empty, LightdInfo, Coinsupply, RawMempool};
use tonic::transport::{Channel, ClientTlsConfig};
use tokio_rustls::{rustls::ClientConfig};
use tonic::{Request};
@@ -95,6 +95,23 @@ pub fn get_coinsupply(uri: http::Uri, no_cert: bool) -> Result<Coinsupply, Strin
// tokio::runtime::current_thread::Runtime::new().unwrap().block_on(runner)
}
async fn get_rawmempool_info(uri: &http::Uri, no_cert: bool) -> Result<RawMempool, Box<dyn std::error::Error>> {
let mut client = get_client(uri, no_cert).await?;
let request = Request::new(Empty {});
let response = client.get_raw_mempool(request).await?;
Ok(response.into_inner())
}
pub fn get_rawmempool(uri: http::Uri, no_cert: bool) -> Result<RawMempool, String> {
let mut rt = tokio::runtime::Runtime::new().map_err(|e| e.to_string())?;
rt.block_on(get_rawmempool_info(&uri, no_cert)).map_err( |e| e.to_string())
// tokio::runtime::current_thread::Runtime::new().unwrap().block_on(runner)
}
async fn get_block_range<F : 'static + std::marker::Send>(uri: &http::Uri, start_height: u64, end_height: u64, no_cert: bool, mut c: F)
-> Result<(), Box<dyn std::error::Error>>
where F : FnMut(&[u8], u64) {

View File

@@ -652,6 +652,19 @@ impl LightClient {
}
}
pub fn do_rawmempool(&self) -> String {
match get_rawmempool(self.get_server_uri(), self.config.no_cert_verification) {
Ok(i) => {
let o = object!{
"ID" => i.id
};
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");