Skip to content

Commit 74f8168

Browse files
committed
fix: use isCoinbase flag in transactions counter; use an auxiliary filter if only chainId was provided in transactions query; adjust query logic when only first or last was provided
1 parent 0fa85a7 commit 74f8168

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

indexer/src/kadena-server/repository/infra/query-builders/transaction-query-builder.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ export default class TransactionQueryBuilder {
4444
blocksConditions += `${op} b.hash = $${blockParams.length}`;
4545
}
4646

47-
// Add chain ID condition if specified
48-
if (chainId) {
49-
blockParams.push(chainId);
50-
const op = this.operator(blockParams.length);
51-
blocksConditions += `${op} b."chainId" = $${blockParams.length}`;
52-
}
53-
5447
// Add maximum height condition if specified
5548
if (maxHeight) {
5649
blockParams.push(maxHeight);
@@ -65,6 +58,20 @@ export default class TransactionQueryBuilder {
6558
blocksConditions += `${op} b."height" >= $${blockParams.length}`;
6659
}
6760

61+
// Add chain ID condition if specified
62+
if (chainId) {
63+
blockParams.push(chainId);
64+
const op = this.operator(blockParams.length);
65+
blocksConditions += `${op} b."chainId" = $${blockParams.length}`;
66+
}
67+
68+
// Force query to retrieve a smaller set of blocks since only using chainId doesn't filter many rows
69+
if (chainId && !params.after && !params.before && !minHeight && !maxHeight) {
70+
blockParams.push(chainId);
71+
const op = this.operator(blockParams.length);
72+
blocksConditions += `${op} b."chainId" = $${blockParams.length} AND b."height" > 5980000`;
73+
}
74+
6875
return { blocksConditions, blockParams };
6976
}
7077

@@ -300,11 +307,16 @@ export default class TransactionQueryBuilder {
300307
let whereCondition = '';
301308
let queryParams: (string | number)[] = [params.limit];
302309

303-
if (!params.after && !params.before) {
310+
if (!params.after && !params.before && params.order === 'DESC') {
304311
const currentTime = Date.now() - 10000000;
305312
queryParams.push(currentTime, 0);
306313
whereCondition = ` WHERE t.creationtime > $2 AND t.id > $3`;
307314
}
315+
316+
if (!params.after && !params.before && params.order === 'ASC') {
317+
whereCondition = ` WHERE t.creationtime < '1578000000'`;
318+
}
319+
308320
if (params.after) {
309321
const [creationTime, id] = params.after.split(':');
310322
queryParams.push(creationTime, id);
@@ -346,6 +358,7 @@ export default class TransactionQueryBuilder {
346358
ORDER BY t.creationtime ${params.order}, t.id ${params.order}
347359
LIMIT $1
348360
`;
361+
349362
return { query, queryParams };
350363
}
351364
}

indexer/src/kadena-server/resolvers/fields/query-transactions-connection/total-count-query-transactions-connection-resolver.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const schema = zod.object({
1919
minHeight: zod.number().nullable().optional(),
2020
minimumDepth: zod.number().nullable().optional(),
2121
requestKey: zod.string().nullable().optional(),
22+
isCoinbase: zod.boolean().nullable().optional(),
2223
});
2324

2425
/**
@@ -41,6 +42,7 @@ export const totalCountQueryTransactionsConnectionResolver: QueryTransactionsCon
4142
minimumDepth,
4243
fungibleName,
4344
requestKey,
45+
isCoinbase,
4446
} = schema.parse(parent);
4547
const output = await context.transactionRepository.getTransactionsCount({
4648
accountName,
@@ -51,6 +53,7 @@ export const totalCountQueryTransactionsConnectionResolver: QueryTransactionsCon
5153
minHeight,
5254
minimumDepth,
5355
requestKey,
56+
isCoinbase,
5457
});
5558
return output;
5659
};

0 commit comments

Comments
 (0)