Skip to content

Commit a5af9f8

Browse files
committed
feat(api): add MempoolStats and MempoolRecentTx structs
1 parent c910ab0 commit a5af9f8

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

src/api.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
//!
33
//! See: <https://github.com/Blockstream/esplora/blob/master/API.md>
44
5+
use bitcoin::hash_types;
6+
use serde::Deserialize;
7+
58
pub use bitcoin::consensus::{deserialize, serialize};
69
pub use bitcoin::hex::FromHex;
7-
use bitcoin::Weight;
810
pub use bitcoin::{
9-
transaction, Amount, BlockHash, OutPoint, ScriptBuf, Transaction, TxIn, TxOut, Txid, Witness,
11+
absolute, block, transaction, Amount, BlockHash, CompactTarget, OutPoint, ScriptBuf,
12+
ScriptHash, Transaction, TxIn, TxOut, Txid, Weight, Witness,
1013
};
1114

12-
use serde::Deserialize;
13-
1415
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
1516
pub struct PrevOut {
1617
pub value: u64,
@@ -215,6 +216,36 @@ pub struct Utxo {
215216
pub value: Amount,
216217
}
217218

219+
/// Statistics about the mempool.
220+
#[derive(Clone, Debug, PartialEq, Deserialize)]
221+
pub struct MempoolStats {
222+
/// The number of transactions in the mempool.
223+
pub count: usize,
224+
/// The total size of mempool transactions in virtual bytes.
225+
pub vsize: usize,
226+
/// The total fee paid by mempool transactions, in sats.
227+
pub total_fee: u64,
228+
/// The mempool's fee rate distribution histogram.
229+
///
230+
/// An array of `(feerate, vsize)` tuples, where each entry's `vsize` is the total vsize
231+
/// of transactions paying more than `feerate` but less than the previous entry's `feerate`
232+
/// (except for the first entry, which has no upper bound).
233+
pub fee_histogram: Vec<(f64, usize)>,
234+
}
235+
236+
/// A [`Transaction`] that recently entered the mempool.
237+
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
238+
pub struct MempoolRecentTx {
239+
/// Transaction ID as a [`Txid`].
240+
pub txid: Txid,
241+
/// [`Amount`] of fees paid by the transaction, in satoshis.
242+
pub fee: u64,
243+
/// The transaction size, in virtual bytes.
244+
pub vsize: usize,
245+
/// Combined [`Amount`] of the transaction, in satoshis.
246+
pub value: u64,
247+
}
248+
218249
impl Tx {
219250
pub fn to_tx(&self) -> Transaction {
220251
Transaction {

0 commit comments

Comments
 (0)