Skip to content

Commit 1d8a50b

Browse files
committed
Support for getchaintxstats RPC
1 parent d0f2f8b commit 1d8a50b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

client/src/client.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,12 @@ pub trait RpcApi: Sized {
955955
self.call("getchaintips", &[])
956956
}
957957

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

json/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,26 @@ pub enum GetChainTipsResultStatus {
18171817
Active,
18181818
}
18191819

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

0 commit comments

Comments
 (0)