@@ -218,8 +218,9 @@ export class PgStore {
218218 return { found : false } ;
219219 }
220220 let txs : DbTx [ ] | null = null ;
221- let microblocksAccepted : DbMicroblock [ ] | null = null ;
222- let microblocksStreamed : DbMicroblock [ ] | null = null ;
221+ const microblocksAccepted : DbMicroblock [ ] = [ ] ;
222+ const microblocksStreamed : DbMicroblock [ ] = [ ] ;
223+ const microblock_tx_count : Record < string , number > = { } ;
223224 if ( metadata ?. txs ) {
224225 const txQuery = await sql < ContractTxQueryResult [ ] > `
225226 SELECT ${ unsafeCols ( sql , [ ...TX_COLUMNS , abiColumn ( ) ] ) }
@@ -231,21 +232,32 @@ export class PgStore {
231232 txs = txQuery . map ( r => parseTxQueryResult ( r ) ) ;
232233 }
233234 if ( metadata ?. microblocks ) {
234- const microblocksQuery = await sql < MicroblockQueryResult [ ] > `
235- SELECT ${ sql ( MICROBLOCK_COLUMNS ) }
235+ const microblocksQuery = await sql <
236+ ( MicroblockQueryResult & { transaction_count : number } ) [ ]
237+ > `
238+ SELECT ${ sql ( MICROBLOCK_COLUMNS ) } , (
239+ SELECT COUNT(tx_id)::integer as transaction_count
240+ FROM txs
241+ WHERE txs.microblock_hash = microblocks.microblock_hash
242+ AND canonical = true AND microblock_canonical = true
243+ )
236244 FROM microblocks
237245 WHERE parent_index_block_hash
238246 IN ${ sql ( [ block . result . index_block_hash , block . result . parent_index_block_hash ] ) }
239247 AND microblock_canonical = true
240248 ORDER BY microblock_sequence DESC
241249 ` ;
242- const parsedMicroblocks = microblocksQuery . map ( r => parseMicroblockQueryResult ( r ) ) ;
243- microblocksAccepted = parsedMicroblocks . filter (
244- mb => mb . parent_index_block_hash === block . result . parent_index_block_hash
245- ) ;
246- microblocksStreamed = parsedMicroblocks . filter (
247- mb => mb . parent_index_block_hash === block . result . index_block_hash
248- ) ;
250+ for ( const mb of microblocksQuery ) {
251+ const parsedMicroblock = parseMicroblockQueryResult ( mb ) ;
252+ const count = mb . transaction_count ;
253+ if ( parsedMicroblock . parent_index_block_hash === block . result . parent_index_block_hash ) {
254+ microblocksAccepted . push ( parsedMicroblock ) ;
255+ microblock_tx_count [ parsedMicroblock . microblock_hash ] = count ;
256+ }
257+ if ( parsedMicroblock . parent_index_block_hash === block . result . index_block_hash ) {
258+ microblocksStreamed . push ( parsedMicroblock ) ;
259+ }
260+ }
249261 }
250262 type ResultType = DbGetBlockWithMetadataResponse < TWithTxs , TWithMicroblocks > ;
251263 const result : ResultType = {
@@ -255,6 +267,7 @@ export class PgStore {
255267 accepted : microblocksAccepted ,
256268 streamed : microblocksStreamed ,
257269 } as ResultType [ 'microblocks' ] ,
270+ microblock_tx_count,
258271 } ;
259272 return {
260273 found : true ,
0 commit comments