use crate::client::Client;
use crate::command::request::request;
use crate::command::CallableCommand;
use crate::Blockhash;
use crate::BlockhashHexEncoded;
use serde::Deserialize;
use serde::Serialize;
use serde_json::value::{to_raw_value, RawValue};
pub struct GetChainTxStatsCommand {
n_blocks: Option<u64>, blockhash: Option<Blockhash>, }
impl GetChainTxStatsCommand {
pub fn new() -> Self {
GetChainTxStatsCommand {
n_blocks: None, blockhash: None,
}
}
pub fn set_n_blocks(&mut self, n_blocks: u64) -> &Self {
self.n_blocks = Some(n_blocks);
self
}
pub fn set_blockhash(&mut self, blockhash: Blockhash) -> &Self {
self.blockhash = Some(blockhash);
self
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct GetChainTxStatsCommandResponse {
pub time: u64, pub txcount: u64, pub window_final_block_hash: String, pub window_final_block_height: u64, pub window_block_count: u64, pub window_tx_count: u64, pub window_interval: u64, pub txrate: f64, }
impl CallableCommand for GetChainTxStatsCommand {
type Response = GetChainTxStatsCommandResponse;
fn call(&self, client: &Client) -> Self::Response {
let command = "getchaintxstats";
let mut params: Vec<Box<RawValue>> = vec![];
if let Some(n_blocks) = &self.n_blocks {
let n_blocks_arg_raw_value = to_raw_value(&n_blocks).unwrap();
params.push(n_blocks_arg_raw_value)
}
if let Some(blockhash) = &self.blockhash {
let blockhash_str = &blockhash.0;
let blockhash_arg_raw_value = to_raw_value(&blockhash_str).unwrap();
params.push(blockhash_arg_raw_value)
}
let r = request(client, command, params);
let response: GetChainTxStatsCommandResponse = r.result().unwrap();
response
}
}