diff --git a/client/src/client.rs b/client/src/client.rs index edb71e30..08fa34e7 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -956,6 +956,12 @@ pub trait RpcApi: Sized { self.call("getchaintips", &[]) } + /// Compute statistics about the total number and rate of transactions in the chain. + fn get_chain_tx_stats(&self, nblocks: Option, blockhash: Option<&bitcoin::BlockHash>) + -> Result { + self.call("getchaintxstats", &[opt_into_json(nblocks)?, opt_into_json(blockhash)?]) + } + fn send_to_address( &self, address: &Address, diff --git a/json/src/lib.rs b/json/src/lib.rs index f6b13675..98643c73 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -1810,6 +1810,26 @@ pub enum GetChainTipsResultStatus { Active, } +#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct GetChainTxStatsResult { + /// The timestamp for the final block in the window, expressed in UNIX epoch time + pub time : u64, + /// The total number of transactions in the chain up to that point + pub txcount: u64, + /// The hash of the final block in the window + pub window_final_block_hash: bitcoin::BlockHash, + /// The height of the final block in the window. + pub window_final_block_height: u64, + /// Size of the window in number of blocks + pub window_block_count: u64, + /// The number of transactions in the window. Only returned if "window_block_count" is > 0 + pub window_tx_count: Option, + /// The elapsed time in the window in seconds. Only returned if "window_block_count" is > 0 + pub window_interval: Option, + /// The average rate of transactions per second in the window. Only returned if "window_interval" is > 0 + pub txrate: Option, +} + impl FinalizePsbtResult { pub fn transaction(&self) -> Option> { self.hex.as_ref().map(|h| encode::deserialize(h))