Skip to content

Commit bafd562

Browse files
committed
feat(client): add get_mempool_txids
1 parent 57605e7 commit bafd562

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

src/async.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,13 @@ impl<S: Sleeper> AsyncClient<S> {
463463
self.get_response_json("/mempool/recent").await
464464
}
465465

466+
/// Get the full list of [`Txid`]s in the mempool.
467+
///
468+
/// The order of the [`Txid`]s is arbitrary.
469+
pub async fn get_mempool_txids(&self) -> Result<Vec<Txid>, Error> {
470+
self.get_response_json("/mempool/txids").await
471+
}
472+
466473
/// Get an map where the key is the confirmation target (in number of
467474
/// blocks) and the value is the estimated feerate (in sat/vB).
468475
pub async fn get_fee_estimates(&self) -> Result<HashMap<u16, f64>, Error> {

src/blocking.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,13 @@ impl BlockingClient {
326326
self.get_response_json("/mempool/recent")
327327
}
328328

329+
/// Get the full list of [`Txid`]s in the mempool.
330+
///
331+
/// The order of the txids is arbitrary and does not match bitcoind's.
332+
pub fn get_mempool_txids(&self) -> Result<Vec<Txid>, Error> {
333+
self.get_response_json("/mempool/txids")
334+
}
335+
329336
/// Get an map where the key is the confirmation target (in number of
330337
/// blocks) and the value is the estimated feerate (in sat/vB).
331338
pub fn get_fee_estimates(&self) -> Result<HashMap<u16, f64>, Error> {

src/lib.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,47 @@ mod test {
956956
}
957957
}
958958

959+
#[cfg(all(feature = "blocking", feature = "async"))]
960+
#[tokio::test]
961+
async fn test_get_mempool_txids() {
962+
let (blocking_client, async_client) = setup_clients().await;
963+
964+
let address = BITCOIND
965+
.client
966+
.new_address_with_type(AddressType::Legacy)
967+
.unwrap();
968+
969+
let _miner = MINER.lock().await;
970+
971+
let mut expected_txids = Vec::new();
972+
for _ in 0..5 {
973+
let txid = BITCOIND
974+
.client
975+
.send_to_address(&address, Amount::from_sat(1000))
976+
.unwrap()
977+
.txid()
978+
.unwrap();
979+
expected_txids.push(txid);
980+
}
981+
982+
// Sleep for 5 seconds so the transaction has time to propagate to electrs' mempool.
983+
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
984+
985+
let txids_blocking = blocking_client.get_mempool_txids().unwrap();
986+
let txids_async = async_client.get_mempool_txids().await.unwrap();
987+
988+
assert_eq!(txids_blocking, txids_async);
989+
assert!(txids_blocking.len() >= 5);
990+
991+
for expected_txid in &expected_txids {
992+
assert!(
993+
txids_blocking.contains(expected_txid),
994+
"Txid {} not found in mempool",
995+
expected_txid
996+
);
997+
}
998+
}
999+
9591000
#[cfg(all(feature = "blocking", feature = "async"))]
9601001
#[tokio::test]
9611002
async fn test_get_fee_estimates() {

0 commit comments

Comments
 (0)