File tree Expand file tree Collapse file tree 2 files changed +34
-16
lines changed Expand file tree Collapse file tree 2 files changed +34
-16
lines changed Original file line number Diff line number Diff line change @@ -563,22 +563,13 @@ export class PgStore {
563
563
const microblockQuery = await sql <
564
564
( MicroblockQueryResult & { tx_id ?: string | null ; tx_index ?: number | null } ) [ ]
565
565
> `
566
- SELECT microblocks.*, tx_id FROM (
567
- SELECT ${ sql ( MICROBLOCK_COLUMNS ) }
568
- FROM microblocks
569
- WHERE canonical = true AND microblock_canonical = true
570
- ORDER BY block_height DESC, microblock_sequence DESC
571
- LIMIT ${ args . limit }
572
- OFFSET ${ args . offset }
573
- ) microblocks
574
- LEFT JOIN (
575
- SELECT tx_id, tx_index, microblock_hash
576
- FROM txs
577
- WHERE canonical = true AND microblock_canonical = true
578
- ORDER BY tx_index DESC
579
- ) txs
580
- ON microblocks.microblock_hash = txs.microblock_hash
581
- ORDER BY microblocks.block_height DESC, microblocks.microblock_sequence DESC, txs.tx_index DESC
566
+ SELECT microblocks.*, txs.tx_id
567
+ FROM microblocks LEFT JOIN txs USING(microblock_hash)
568
+ WHERE microblocks.canonical = true AND microblocks.microblock_canonical = true AND
569
+ txs.canonical = true AND txs.microblock_canonical = true
570
+ ORDER BY microblocks.block_height DESC, microblocks.microblock_sequence DESC, txs.tx_index DESC
571
+ LIMIT ${ args . limit }
572
+ OFFSET ${ args . offset } ;
582
573
` ;
583
574
const microblocks : { microblock : DbMicroblock ; txs : string [ ] } [ ] = [ ] ;
584
575
microblockQuery . forEach ( row => {
Original file line number Diff line number Diff line change @@ -10847,6 +10847,33 @@ describe('api tests', () => {
10847
10847
expect ( result . body . txs ) . toHaveLength ( 1 ) ;
10848
10848
expect ( result . body . txs [ 0 ] ) . toEqual ( tx_id ) ;
10849
10849
} ) ;
10850
+ test ( '/microblock' , async ( ) => {
10851
+ const microblock_hash = '0x0fff' ;
10852
+ const block = new TestBlockBuilder ( { block_hash : '0x1234' , block_height : 1 } ) . build ( ) ;
10853
+ await db . update ( block ) ;
10854
+
10855
+ const microblock = new TestMicroblockStreamBuilder ( )
10856
+ . addMicroblock ( { microblock_hash, parent_index_block_hash : block . block . index_block_hash } )
10857
+ . addTx ( {
10858
+ tx_id : '0xffff' ,
10859
+ } )
10860
+ . addTx ( {
10861
+ tx_id : '0x1234' ,
10862
+ canonical : false ,
10863
+ microblock_canonical : false ,
10864
+ } )
10865
+ . build ( ) ;
10866
+ await db . updateMicroblocks ( microblock ) ;
10867
+ const microblockResult = await supertest ( api . server ) . get ( `/extended/v1/microblock/` ) ;
10868
+ const response = microblockResult . body ;
10869
+ const expectedTxs = [ '0xffff' ] ;
10870
+
10871
+ expect ( response . total ) . toEqual ( 1 ) ;
10872
+ expect ( response . results ) . toHaveLength ( 1 ) ;
10873
+ expect ( response . results [ 0 ] . microblock_hash ) . toEqual ( microblock_hash ) ;
10874
+ expect ( response . results [ 0 ] . txs ) . toHaveLength ( 1 ) ;
10875
+ expect ( response . results [ 0 ] . txs ) . toEqual ( expectedTxs ) ;
10876
+ } ) ;
10850
10877
10851
10878
test ( '/block' , async ( ) => {
10852
10879
const block_hash = '0x1234' ,
You can’t perform that action at this time.
0 commit comments