diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5c41512e..07d0c360 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -47,6 +47,8 @@ jobs: "0.20.0", "0.20.1", "0.21.0", + "22.0", + "23.0", ] steps: - name: Checkout Crate diff --git a/README.md b/README.md index 9cda95c3..723fa807 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ The following versions are officially supported and automatically tested: * 0.20.0 * 0.20.1 * 0.21.0 +* 22.0 +* 23.0 # Minimum Supported Rust Version (MSRV) This library should always compile with any combination of features on **Rust 1.41.1**. 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/integration_test/run.sh b/integration_test/run.sh index be15d005..6d4d4de0 100755 --- a/integration_test/run.sh +++ b/integration_test/run.sh @@ -28,7 +28,12 @@ if bitcoind -version | grep -q "v0\.2"; then FALLBACKFEEARG="-fallbackfee=0.00001000" fi -bitcoind -regtest $BLOCKFILTERARG $FALLBACKFEEARG \ +COINSTATSINDEXARG="" +if bitcoind -version | grep -q "v[2-9]"; then + COINSTATSINDEXARG="-coinstatsindex=1" +fi + +bitcoind -regtest $BLOCKFILTERARG $FALLBACKFEEARG $COINSTATSINDEXARG \ -datadir=${TESTDIR}/2 \ -connect=127.0.0.1:12348 \ -rpcport=12349 \ diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index d9f4dca7..a12b968b 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -1174,7 +1174,11 @@ fn test_create_wallet(cl: &Client) { } fn test_get_tx_out_set_info(cl: &Client) { - cl.get_tx_out_set_info(None, None, None).unwrap(); + if version() >= 220000 { + cl.get_tx_out_set_info(Some(json::TxOutSetHashType::Muhash), None, Some(true)).unwrap(); + } else { + cl.get_tx_out_set_info(None, None, None).unwrap(); + } } fn test_get_chain_tips(cl: &Client) { 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))