Skip to content

Commit

Permalink
Support for getchaintxstats RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkmoody committed Aug 25, 2023
1 parent e874769 commit c189056
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>, blockhash: Option<&bitcoin::BlockHash>)
-> Result<json::GetChainTxStatsResult> {
self.call("getchaintxstats", &[opt_into_json(nblocks)?, opt_into_json(blockhash)?])
}

fn send_to_address(
&self,
address: &Address<NetworkChecked>,
Expand Down
20 changes: 20 additions & 0 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
/// The elapsed time in the window in seconds. Only returned if "window_block_count" is > 0
pub window_interval: Option<u64>,
/// The average rate of transactions per second in the window. Only returned if "window_interval" is > 0
pub txrate: Option<f64>,
}

impl FinalizePsbtResult {
pub fn transaction(&self) -> Option<Result<Transaction, encode::Error>> {
self.hex.as_ref().map(|h| encode::deserialize(h))
Expand Down

0 comments on commit c189056

Please sign in to comment.