File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff 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 > {
Original file line number Diff line number Diff 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 > {
Original file line number Diff line number Diff line change @@ -958,6 +958,47 @@ mod test {
958958 }
959959 }
960960
961+ #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
962+ #[ tokio:: test]
963+ async fn test_get_mempool_txids ( ) {
964+ let ( blocking_client, async_client) = setup_clients ( ) . await ;
965+
966+ let address = BITCOIND
967+ . client
968+ . new_address_with_type ( AddressType :: Legacy )
969+ . unwrap ( ) ;
970+
971+ let _miner = MINER . lock ( ) . await ;
972+
973+ let mut expected_txids = Vec :: new ( ) ;
974+ for _ in 0 ..5 {
975+ let txid = BITCOIND
976+ . client
977+ . send_to_address ( & address, Amount :: from_sat ( 1000 ) )
978+ . unwrap ( )
979+ . txid ( )
980+ . unwrap ( ) ;
981+ expected_txids. push ( txid) ;
982+ }
983+
984+ // Sleep for 5 seconds so the transaction has time to propagate to electrs' mempool.
985+ tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 5 ) ) . await ;
986+
987+ let txids_blocking = blocking_client. get_mempool_txids ( ) . unwrap ( ) ;
988+ let txids_async = async_client. get_mempool_txids ( ) . await . unwrap ( ) ;
989+
990+ assert_eq ! ( txids_blocking, txids_async) ;
991+ assert ! ( txids_blocking. len( ) >= 5 ) ;
992+
993+ for expected_txid in & expected_txids {
994+ assert ! (
995+ txids_blocking. contains( expected_txid) ,
996+ "Txid {} not found in mempool" ,
997+ expected_txid
998+ ) ;
999+ }
1000+ }
1001+
9611002 #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
9621003 #[ tokio:: test]
9631004 async fn test_get_fee_estimates ( ) {
You can’t perform that action at this time.
0 commit comments