Skip to content

Commit 9c930da

Browse files
committed
implemented /mempool endpoint, can now access mempool info such as the fee historgram
1 parent ecea653 commit 9c930da

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/api.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ pub struct AddressTxsSummary {
123123
pub tx_count: u32,
124124
}
125125

126+
#[derive(Deserialize, Clone, Debug, PartialEq)]
127+
pub struct MempoolInfo {
128+
pub count: u32,
129+
pub vsize: u64,
130+
pub total_fee: u64,
131+
pub fee_histogram: Vec<(f32, u64)>,
132+
}
133+
126134
impl Tx {
127135
pub fn to_tx(&self) -> Transaction {
128136
Transaction {

src/async.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use log::{debug, error, info, trace};
2828

2929
use reqwest::{header, Client, Response};
3030

31-
use crate::api::AddressStats;
31+
use crate::api::{AddressStats, MempoolInfo};
3232
use crate::{
3333
BlockStatus, BlockSummary, Builder, Error, MerkleProof, OutputStatus, Tx, TxStatus,
3434
BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES,
@@ -432,6 +432,10 @@ impl<S: Sleeper> AsyncClient<S> {
432432
self.get_response_json("/fee-estimates").await
433433
}
434434

435+
pub async fn get_mempool_info(&self) -> Result<MempoolInfo, Error> {
436+
self.get_response_json("/mempool").await
437+
}
438+
435439
/// Gets some recent block summaries starting at the tip or at `height` if
436440
/// provided.
437441
///

src/blocking.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use bitcoin::{
2929
block::Header as BlockHeader, Block, BlockHash, MerkleBlock, Script, Transaction, Txid,
3030
};
3131

32-
use crate::api::AddressStats;
32+
use crate::api::{AddressStats, MempoolInfo};
3333
use crate::{
3434
BlockStatus, BlockSummary, Builder, Error, MerkleProof, OutputStatus, Tx, TxStatus,
3535
BASE_BACKOFF_MILLIS, RETRYABLE_ERROR_CODES,
@@ -319,6 +319,10 @@ impl BlockingClient {
319319
self.get_response_json("/fee-estimates")
320320
}
321321

322+
pub fn get_mempool_info(&self) -> Result<MempoolInfo, Error> {
323+
self.get_response_json("/mempool")
324+
}
325+
322326
/// Get information about a specific address, includes confirmed balance and transactions in
323327
/// the mempool.
324328
pub fn get_address_stats(&self, address: &Address) -> Result<AddressStats, Error> {

0 commit comments

Comments
 (0)