fix: rosetta block tx sql query not using index_block_hash (#938)

This commit is contained in:
Matthew Little
2021-12-22 17:30:55 +01:00
committed by GitHub
parent 009e4c3a1c
commit 1b2c19d2c7
2 changed files with 13 additions and 4 deletions

View File

@@ -2845,14 +2845,20 @@ export class PgDataStore
}
async getBlockTxsRows(blockHash: string) {
return this.query(async client => {
return this.queryTx(async client => {
const blockQuery = await this.getBlockInternal(client, { hash: blockHash });
if (!blockQuery.found) {
throw new Error(`Could not find block by hash ${blockHash}`);
}
const result = await client.query<ContractTxQueryResult>(
`
-- getBlockTxsRows
SELECT ${TX_COLUMNS}, ${abiColumn()}
FROM txs
WHERE block_hash = $1 AND canonical = true AND microblock_canonical = true
WHERE index_block_hash = $1 AND canonical = true AND microblock_canonical = true
ORDER BY microblock_sequence ASC, tx_index ASC
`,
[hexToBuffer(blockHash)]
[hexToBuffer(blockQuery.result.index_block_hash)]
);
if (result.rowCount === 0) {
return { found: false } as const;

View File

@@ -5042,7 +5042,10 @@ describe('api tests', () => {
const blockTxsRows = await api.datastore.getBlockTxsRows(block.block_hash);
expect(blockTxsRows.found).toBe(true);
const blockTxsRowsResult = blockTxsRows.result as DbTx[];
expect(blockTxsRowsResult[6]).toEqual({ ...contractCall, ...{ abi: contractJsonAbi } });
expect(blockTxsRowsResult.find(tx => tx.tx_id === contractCall.tx_id)).toEqual({
...contractCall,
...{ abi: contractJsonAbi },
});
const searchResult8 = await supertest(api.server).get(
`/extended/v1/search/0x1232000000000000000000000000000000000000000000000000000000000000?include_metadata`