Skip to content

Commit c189056

Browse files
committed
Support for getchaintxstats RPC
1 parent e874769 commit c189056

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

client/src/client.rs

+6
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,12 @@ pub trait RpcApi: Sized {
956956
self.call("getchaintips", &[])
957957
}
958958

959+
/// Compute statistics about the total number and rate of transactions in the chain.
960+
fn get_chain_tx_stats(&self, nblocks: Option<u64>, blockhash: Option<&bitcoin::BlockHash>)
961+
-> Result<json::GetChainTxStatsResult> {
962+
self.call("getchaintxstats", &[opt_into_json(nblocks)?, opt_into_json(blockhash)?])
963+
}
964+
959965
fn send_to_address(
960966
&self,
961967
address: &Address<NetworkChecked>,

json/src/lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,26 @@ pub enum GetChainTipsResultStatus {
18101810
Active,
18111811
}
18121812

1813+
#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
1814+
pub struct GetChainTxStatsResult {
1815+
/// The timestamp for the final block in the window, expressed in UNIX epoch time
1816+
pub time : u64,
1817+
/// The total number of transactions in the chain up to that point
1818+
pub txcount: u64,
1819+
/// The hash of the final block in the window
1820+
pub window_final_block_hash: bitcoin::BlockHash,
1821+
/// The height of the final block in the window.
1822+
pub window_final_block_height: u64,
1823+
/// Size of the window in number of blocks
1824+
pub window_block_count: u64,
1825+
/// The number of transactions in the window. Only returned if "window_block_count" is > 0
1826+
pub window_tx_count: Option<u64>,
1827+
/// The elapsed time in the window in seconds. Only returned if "window_block_count" is > 0
1828+
pub window_interval: Option<u64>,
1829+
/// The average rate of transactions per second in the window. Only returned if "window_interval" is > 0
1830+
pub txrate: Option<f64>,
1831+
}
1832+
18131833
impl FinalizePsbtResult {
18141834
pub fn transaction(&self) -> Option<Result<Transaction, encode::Error>> {
18151835
self.hex.as_ref().map(|h| encode::deserialize(h))

0 commit comments

Comments
 (0)