diff --git a/src/api.rs b/src/api.rs index 296835c..b55e4b8 100644 --- a/src/api.rs +++ b/src/api.rs @@ -123,6 +123,14 @@ pub struct AddressTxsSummary { pub tx_count: u32, } +#[derive(Deserialize, Clone, Debug, PartialEq)] +pub struct MempoolInfo { + pub count: u32, + pub vsize: u64, + pub total_fee: u64, + pub fee_histogram: Vec<(f32, u64)>, +} + impl Tx { pub fn to_tx(&self) -> Transaction { Transaction { diff --git a/src/async.rs b/src/async.rs index b72988b..77056a2 100644 --- a/src/async.rs +++ b/src/async.rs @@ -28,7 +28,7 @@ use log::{debug, error, info, trace}; use reqwest::{header, Client, Response}; -use crate::api::AddressStats; +use crate::api::{AddressStats, MempoolInfo}; use crate::{ BlockStatus, BlockSummary, Builder, Error, MerkleProof, OutputStatus, Tx, TxStatus, BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES, @@ -432,6 +432,10 @@ impl AsyncClient { self.get_response_json("/fee-estimates").await } + pub async fn get_mempool_info(&self) -> Result { + self.get_response_json("/mempool").await + } + /// Gets some recent block summaries starting at the tip or at `height` if /// provided. /// diff --git a/src/blocking.rs b/src/blocking.rs index fe6be6c..d2d5bf4 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -29,7 +29,7 @@ use bitcoin::{ block::Header as BlockHeader, Block, BlockHash, MerkleBlock, Script, Transaction, Txid, }; -use crate::api::AddressStats; +use crate::api::{AddressStats, MempoolInfo}; use crate::{ BlockStatus, BlockSummary, Builder, Error, MerkleProof, OutputStatus, Tx, TxStatus, BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES, @@ -319,6 +319,10 @@ impl BlockingClient { self.get_response_json("/fee-estimates") } + pub fn get_mempool_info(&self) -> Result { + self.get_response_json("/mempool") + } + /// Get information about a specific address, includes confirmed balance and transactions in /// the mempool. pub fn get_address_stats(&self, address: &Address) -> Result {