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 @@ -464,6 +464,13 @@ impl<S: Sleeper> AsyncClient<S> {
464464 self . get_response_json ( "/mempool" ) . await
465465 }
466466
467+ /// Get the full list of transaction IDs in the mempool.
468+ ///
469+ /// The order of the txids is arbitrary and does not match bitcoind's.
470+ pub async fn get_mempool_txids ( & self ) -> Result < Vec < Txid > , Error > {
471+ self . get_response_json ( "/mempool/txids" ) . await
472+ }
473+
467474 /// Get an map where the key is the confirmation target (in number of
468475 /// blocks) and the value is the estimated feerate (in sat/vB).
469476 pub async fn get_fee_estimates ( & self ) -> Result < HashMap < u16 , f64 > , Error > {
Original file line number Diff line number Diff line change @@ -321,6 +321,13 @@ impl BlockingClient {
321321 self . get_response_json ( "/mempool" )
322322 }
323323
324+ /// Get the full list of transaction IDs in the mempool.
325+ ///
326+ /// The order of the txids is arbitrary and does not match bitcoind's.
327+ pub fn get_mempool_txids ( & self ) -> Result < Vec < Txid > , Error > {
328+ self . get_response_json ( "/mempool/txids" )
329+ }
330+
324331 /// Get an map where the key is the confirmation target (in number of
325332 /// blocks) and the value is the estimated feerate (in sat/vB).
326333 pub fn get_fee_estimates ( & self ) -> Result < HashMap < u16 , f64 > , Error > {
Original file line number Diff line number Diff line change @@ -908,6 +908,47 @@ mod test {
908908 }
909909 }
910910
911+ #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
912+ #[ tokio:: test]
913+ async fn test_get_mempool_txids ( ) {
914+ let ( blocking_client, async_client) = setup_clients ( ) . await ;
915+
916+ let address = BITCOIND
917+ . client
918+ . new_address_with_type ( AddressType :: Legacy )
919+ . unwrap ( ) ;
920+
921+ let _miner = MINER . lock ( ) . await ;
922+
923+ let mut expected_txids = Vec :: new ( ) ;
924+ for _ in 0 ..5 {
925+ let txid = BITCOIND
926+ . client
927+ . send_to_address ( & address, Amount :: from_sat ( 1000 ) )
928+ . unwrap ( )
929+ . txid ( )
930+ . unwrap ( ) ;
931+ expected_txids. push ( txid) ;
932+ }
933+
934+ // Sleep for 5 seconds so the transaction has time to propagate to electrs' mempool.
935+ tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 5 ) ) . await ;
936+
937+ let txids_blocking = blocking_client. get_mempool_txids ( ) . unwrap ( ) ;
938+ let txids_async = async_client. get_mempool_txids ( ) . await . unwrap ( ) ;
939+
940+ assert_eq ! ( txids_blocking, txids_async) ;
941+ assert ! ( txids_blocking. len( ) >= 5 ) ;
942+
943+ for expected_txid in & expected_txids {
944+ assert ! (
945+ txids_blocking. contains( expected_txid) ,
946+ "Txid {} not found in mempool" ,
947+ expected_txid
948+ ) ;
949+ }
950+ }
951+
911952 #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
912953 #[ tokio:: test]
913954 async fn test_get_fee_estimates ( ) {
You can’t perform that action at this time.
0 commit comments