@@ -335,38 +335,37 @@ export class PgStoreV2 extends BasePgStoreModule {
335
335
return await this . sqlTransaction ( async sql => {
336
336
const limit = args . limit ?? TransactionLimitParamSchema . default ;
337
337
const offset = args . offset ?? 0 ;
338
- const filter =
339
- args . block . type === 'latest'
340
- ? sql `index_block_hash = (SELECT index_block_hash FROM blocks WHERE canonical = TRUE ORDER BY block_height DESC LIMIT 1)`
341
- : args . block . type === 'hash'
342
- ? sql `(
343
- block_hash = ${ normalizeHashString ( args . block . hash ) }
344
- OR index_block_hash = ${ normalizeHashString ( args . block . hash ) }
345
- )`
346
- : sql `block_height = ${ args . block . height } ` ;
347
- const blockCheck = await sql `SELECT index_block_hash FROM blocks WHERE ${ filter } LIMIT 1` ;
348
- if ( blockCheck . count === 0 )
349
- throw new InvalidRequestError ( `Block not found` , InvalidRequestErrorType . invalid_param ) ;
350
338
const txsQuery = await sql < ( TxQueryResult & { total : number } ) [ ] > `
351
- WITH tx_count AS (
352
- SELECT tx_count AS total FROM blocks WHERE canonical = TRUE AND ${ filter }
339
+ WITH block_ptr AS (
340
+ SELECT index_block_hash FROM blocks
341
+ WHERE ${
342
+ args . block . type === 'latest'
343
+ ? sql `canonical = TRUE ORDER BY block_height DESC`
344
+ : args . block . type === 'hash'
345
+ ? sql `(
346
+ block_hash = ${ normalizeHashString ( args . block . hash ) }
347
+ OR index_block_hash = ${ normalizeHashString ( args . block . hash ) }
348
+ ) AND canonical = TRUE`
349
+ : sql `block_height = ${ args . block . height } AND canonical = TRUE`
350
+ }
351
+ LIMIT 1
352
+ ),
353
+ tx_count AS (
354
+ SELECT tx_count AS total
355
+ FROM blocks
356
+ WHERE index_block_hash = (SELECT index_block_hash FROM block_ptr)
353
357
)
354
358
SELECT ${ sql ( TX_COLUMNS ) } , (SELECT total FROM tx_count)::int AS total
355
359
FROM txs
356
360
WHERE canonical = true
357
361
AND microblock_canonical = true
358
- AND ${ filter }
362
+ AND index_block_hash = (SELECT index_block_hash FROM block_ptr)
359
363
ORDER BY microblock_sequence ASC, tx_index ASC
360
364
LIMIT ${ limit }
361
365
OFFSET ${ offset }
362
366
` ;
363
367
if ( txsQuery . count === 0 )
364
- return {
365
- limit,
366
- offset,
367
- results : [ ] ,
368
- total : 0 ,
369
- } ;
368
+ throw new InvalidRequestError ( `Block not found` , InvalidRequestErrorType . invalid_param ) ;
370
369
return {
371
370
limit,
372
371
offset,
0 commit comments