File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -483,6 +483,13 @@ impl<S: Sleeper> AsyncClient<S> {
483483 self . get_response_json ( & path) . await
484484 }
485485
486+ /// Get all [`Txid`]s that belong to a [`Block`] identified by it's [`BlockHash`].
487+ pub async fn get_block_txids ( & self , blockhash : & BlockHash ) -> Result < Vec < Txid > , Error > {
488+ let path = format ! ( "/block/{blockhash}/txids" ) ;
489+
490+ self . get_response_json ( & path) . await
491+ }
492+
486493 /// Gets some recent block summaries starting at the tip or at `height` if
487494 /// provided.
488495 ///
Original file line number Diff line number Diff line change @@ -411,6 +411,13 @@ impl BlockingClient {
411411 self . get_response_json ( & path)
412412 }
413413
414+ /// Get all [`Txid`]s that belong to a [`Block`] identified by it's [`BlockHash`].
415+ pub fn get_block_txids ( & self , blockhash : & BlockHash ) -> Result < Vec < Txid > , Error > {
416+ let path = format ! ( "/block/{blockhash}/txids" ) ;
417+
418+ self . get_response_json ( & path)
419+ }
420+
414421 /// Gets some recent block summaries starting at the tip or at `height` if
415422 /// provided.
416423 ///
Original file line number Diff line number Diff line change @@ -945,6 +945,45 @@ mod test {
945945 assert_eq ! ( block_info_async. previousblockhash, None ) ;
946946 }
947947
948+ #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
949+ #[ tokio:: test]
950+ async fn test_get_block_txids ( ) {
951+ let ( blocking_client, async_client) = setup_clients ( ) . await ;
952+
953+ let address = BITCOIND
954+ . client
955+ . new_address_with_type ( AddressType :: Legacy )
956+ . unwrap ( ) ;
957+
958+ // Create 5 transactions and mine a block.
959+ let txids: Vec < _ > = ( 0 ..5 )
960+ . map ( |_| {
961+ BITCOIND
962+ . client
963+ . send_to_address ( & address, Amount :: from_sat ( 1000 ) )
964+ . unwrap ( )
965+ . txid ( )
966+ . unwrap ( )
967+ } )
968+ . collect ( ) ;
969+
970+ let _miner = MINER . lock ( ) . await ;
971+ generate_blocks_and_wait ( 1 ) ;
972+
973+ // Get the block hash at the chain's tip.
974+ let blockhash = blocking_client. get_tip_hash ( ) . unwrap ( ) ;
975+
976+ let txids_async = async_client. get_block_txids ( & blockhash) . await . unwrap ( ) ;
977+ let txids_blocking = blocking_client. get_block_txids ( & blockhash) . unwrap ( ) ;
978+
979+ assert_eq ! ( txids_async, txids_blocking) ;
980+
981+ // Compare expected and received (skipping the coinbase TXID).
982+ for expected_txid in txids. iter ( ) {
983+ assert ! ( txids_async. contains( expected_txid) ) ;
984+ }
985+ }
986+
948987 #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
949988 #[ tokio:: test]
950989 async fn test_get_blocks ( ) {
You can’t perform that action at this time.
0 commit comments