File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -490,6 +490,24 @@ impl<S: Sleeper> AsyncClient<S> {
490490 self . get_response_json ( & path) . await
491491 }
492492
493+ /// Get up to 25 [`Transaction`]s from a [`Block`], given it's [`BlockHash`],
494+ /// beginning at `start_index` (starts from 0 if `start_index` is `None`).
495+ ///
496+ /// The `start_index` value MUST be a multiple of 25,
497+ /// even though this is not documented on the Esplora specification.
498+ pub async fn get_block_txs (
499+ & self ,
500+ blockhash : & BlockHash ,
501+ start_index : Option < u32 > ,
502+ ) -> Result < Vec < Tx > , Error > {
503+ let path = match start_index {
504+ None => format ! ( "/block/{blockhash}/txs" ) ,
505+ Some ( start_index) => format ! ( "/block/{blockhash}/txs/{start_index}" ) ,
506+ } ;
507+
508+ self . get_response_json ( & path) . await
509+ }
510+
493511 /// Gets some recent block summaries starting at the tip or at `height` if
494512 /// provided.
495513 ///
Original file line number Diff line number Diff line change @@ -418,6 +418,24 @@ impl BlockingClient {
418418 self . get_response_json ( & path)
419419 }
420420
421+ /// Get up to 25 [`Transaction`]s from a [`Block`], given it's [`BlockHash`],
422+ /// beginning at `start_index` (starts from 0 if `start_index` is `None`).
423+ ///
424+ /// The `start_index` value MUST be a multiple of 25,
425+ /// even though this is not documented on the Esplora specification.
426+ pub fn get_block_txs (
427+ & self ,
428+ blockhash : & BlockHash ,
429+ start_index : Option < u32 > ,
430+ ) -> Result < Vec < Tx > , Error > {
431+ let path = match start_index {
432+ None => format ! ( "/block/{blockhash}/txs" ) ,
433+ Some ( start_index) => format ! ( "/block/{blockhash}/txs/{start_index}" ) ,
434+ } ;
435+
436+ self . get_response_json ( & path)
437+ }
438+
421439 /// Gets some recent block summaries starting at the tip or at `height` if
422440 /// provided.
423441 ///
Original file line number Diff line number Diff line change @@ -984,6 +984,21 @@ mod test {
984984 } ) ;
985985 }
986986
987+ #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
988+ #[ tokio:: test]
989+ async fn test_get_block_txs ( ) {
990+ let ( blocking_client, async_client) = setup_clients ( ) . await ;
991+
992+ let _miner = MINER . lock ( ) . await ;
993+ let blockhash = blocking_client. get_tip_hash ( ) . unwrap ( ) ;
994+
995+ let txs_blocking = blocking_client. get_block_txs ( & blockhash, None ) . unwrap ( ) ;
996+ let txs_async = async_client. get_block_txs ( & blockhash, None ) . await . unwrap ( ) ;
997+
998+ assert_ne ! ( txs_blocking. len( ) , 0 ) ;
999+ assert_eq ! ( txs_blocking. len( ) , txs_async. len( ) ) ;
1000+ }
1001+
9871002 #[ cfg( all( feature = "blocking" , feature = "async" ) ) ]
9881003 #[ tokio:: test]
9891004 async fn test_get_blocks ( ) {
You can’t perform that action at this time.
0 commit comments