Skip to content

Commit 0ae067b

Browse files
committed
fix: added badResult field to the transactions-by-pact-code query and changed the creationTime field to DateTime type
1 parent fd7d635 commit 0ae067b

File tree

6 files changed

+133
-75
lines changed

6 files changed

+133
-75
lines changed

indexer/src/kadena-server/config/graphql-types.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,13 +1400,14 @@ export type TransactionSignature = {
14001400

14011401
export type TransactionSummary = {
14021402
__typename?: 'TransactionSummary';
1403+
badResult?: Maybe<Scalars['String']['output']>;
14031404
canonical: Scalars['Boolean']['output'];
1404-
chainId: Scalars['String']['output'];
1405-
creationTime: Scalars['String']['output'];
1405+
chainId: Scalars['BigInt']['output'];
1406+
creationTime: Scalars['DateTime']['output'];
14061407
gas: Scalars['String']['output'];
14071408
gasLimit: Scalars['String']['output'];
14081409
gasPrice: Scalars['String']['output'];
1409-
height: Scalars['String']['output'];
1410+
height: Scalars['BigInt']['output'];
14101411
requestKey: Scalars['String']['output'];
14111412
sender: Scalars['String']['output'];
14121413
};
@@ -3672,13 +3673,14 @@ export type TransactionSummaryResolvers<
36723673
ParentType extends
36733674
ResolversParentTypes['TransactionSummary'] = ResolversParentTypes['TransactionSummary'],
36743675
> = {
3676+
badResult?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
36753677
canonical?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
3676-
chainId?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
3677-
creationTime?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
3678+
chainId?: Resolver<ResolversTypes['BigInt'], ParentType, ContextType>;
3679+
creationTime?: Resolver<ResolversTypes['DateTime'], ParentType, ContextType>;
36783680
gas?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
36793681
gasLimit?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
36803682
gasPrice?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
3681-
height?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
3683+
height?: Resolver<ResolversTypes['BigInt'], ParentType, ContextType>;
36823684
requestKey?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
36833685
sender?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
36843686
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;

indexer/src/kadena-server/config/schema.graphql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,11 @@ type QueryTransactionsByPactCodeConnectionEdge {
454454

455455
type TransactionSummary {
456456
requestKey: String!
457-
height: String!
458-
chainId: String!
457+
height: BigInt!
458+
chainId: BigInt!
459459
canonical: Boolean!
460-
creationTime: String!
460+
creationTime: DateTime!
461+
badResult: String
461462
sender: String!
462463
gas: String!
463464
gasLimit: String!

indexer/src/kadena-server/repository/application/transaction-repository.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,16 @@ export type TransactionOutput = Omit<Transaction, 'cmd'> & {
112112
};
113113

114114
export type TransactionByPactCodeOutput = {
115-
creationTime: string;
116115
requestKey: string;
117-
chainId: string;
118-
height: string;
116+
height: any;
117+
chainId: any;
119118
canonical: boolean;
119+
creationTime: Date;
120+
badResult: any;
121+
sender: string;
120122
gas: string;
121123
gasLimit: string;
122124
gasPrice: string;
123-
sender: string;
124125
};
125126

126127
/**

indexer/src/kadena-server/repository/infra/repository/transaction-db-repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { signerMetaValidator } from '../schema-validator/signer-schema-validator
3434
import BlockDbRepository from './block-db-repository';
3535
import TransactionQueryBuilder from '../query-builders/transaction-query-builder';
3636
import { isNullOrUndefined } from '@/utils/helpers';
37+
import { transactionSummaryValidator } from '@/kadena-server/repository/infra/schema-validator/transaction-summary-schema-validator';
3738

3839
/**
3940
* Database-specific implementation of the TransactionRepository interface.
@@ -279,10 +280,9 @@ export default class TransactionDbRepository implements TransactionRepository {
279280

280281
const { rows } = await rootPgPool.query(query, queryParams);
281282

282-
// Create edges for paginated result and apply sorting
283283
const edges = rows.slice(0, limit).map(tx => ({
284284
cursor: `${tx.creationTime.toString()}:${tx.id.toString()}`,
285-
node: tx,
285+
node: transactionSummaryValidator.validate(tx),
286286
}));
287287

288288
return getPageInfo({ edges, order, limit, after, before });
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { TransactionByPactCodeOutput } from '@/kadena-server/repository/application/transaction-repository';
2+
import { z } from 'zod';
3+
4+
const schema = z.object({
5+
requestKey: z.string(),
6+
height: z.number(),
7+
chainId: z.number(),
8+
canonical: z.boolean(),
9+
creationTime: z.string(),
10+
result: z.any(),
11+
sender: z.string(),
12+
gas: z.string(),
13+
gasLimit: z.string(),
14+
gasPrice: z.string(),
15+
});
16+
17+
function validate(row: any): TransactionByPactCodeOutput {
18+
const res = schema.parse(row);
19+
const isSuccess = row.result.status === 'success';
20+
return {
21+
requestKey: res.requestKey,
22+
height: res.height,
23+
chainId: res.chainId,
24+
canonical: res.canonical,
25+
creationTime: new Date(Number(res.creationTime) * 1000),
26+
badResult: !isSuccess ? JSON.stringify(res.result.error) : null,
27+
sender: res.sender,
28+
gas: res.gas,
29+
gasLimit: res.gasLimit,
30+
gasPrice: res.gasPrice,
31+
};
32+
}
33+
34+
export const transactionSummaryValidator = { validate };

0 commit comments

Comments
 (0)