Skip to content

Commit 86f69a3

Browse files
committed
fix: cross-chain-transfer field
1 parent 06b1799 commit 86f69a3

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

.github/workflows/indexer.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313

1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v4
1717

1818
- name: Use Node.js 18
19-
uses: actions/setup-node@v2
19+
uses: actions/setup-node@v4
2020
with:
2121
node-version: '18'
2222
cache: 'yarn'

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface GetTotalCountParams {
2424
export interface GetCrossChainTransferByPactIdParams {
2525
pactId: string;
2626
amount: string;
27+
requestKey: string;
2728
}
2829

2930
export type TransferOutput = Omit<Transfer, 'block' | 'transaction' | 'crossChainTransfer'> & {
@@ -43,6 +44,6 @@ export default interface TransferRepository {
4344
}>;
4445
getCrossChainTransferByPactId(
4546
params: GetCrossChainTransferByPactIdParams,
46-
): Promise<TransferOutput>;
47+
): Promise<TransferOutput | null>;
4748
getTotalCountOfTransfers(params: GetTotalCountParams): Promise<number>;
4849
}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,25 @@ export default class TransferDbRepository implements TransferRepository {
210210
return pageInfo;
211211
}
212212

213-
async getCrossChainTransferByPactId({ amount, pactId }: GetCrossChainTransferByPactIdParams) {
213+
async getCrossChainTransferByPactId({
214+
amount,
215+
pactId,
216+
requestKey,
217+
}: GetCrossChainTransferByPactIdParams) {
218+
let requestKeyParam = pactId;
219+
220+
if (pactId === requestKey) {
221+
const query = `
222+
SELECT requestkey
223+
FROM "Transactions" t
224+
JOIN "TransactionDetails" td ON t.id = td."transactionId"
225+
WHERE td.pactid = $1 AND requestkey != $1
226+
`;
227+
const { rows } = await rootPgPool.query(query, [requestKey]);
228+
const row = rows[0];
229+
requestKeyParam = row.requestkey;
230+
}
231+
214232
const query = `
215233
select transfers.id as id,
216234
transfers.amount as "transferAmount",
@@ -234,9 +252,10 @@ export default class TransferDbRepository implements TransferRepository {
234252
and transfers.amount = $2
235253
`;
236254

237-
const { rows } = await rootPgPool.query(query, [pactId, amount]);
255+
const { rows } = await rootPgPool.query(query, [requestKeyParam, amount]);
238256

239257
const [row] = rows;
258+
if (!row) return null;
240259
const output = transferSchemaValidator.validate(row);
241260
return output;
242261
}

indexer/src/kadena-server/resolvers/fields/transfer/cross-chain-transfer-transfer-resolver.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ import { buildTransferOutput } from '../../output/build-transfer-output';
55

66
const schema = zod.object({
77
pactId: zod.string().nullable(),
8+
requestKey: zod.string(),
89
amount: zod.string(),
910
});
1011

1112
export const crossChainTransferTransferResolver: TransferResolvers<ResolverContext>['crossChainTransfer'] =
1213
async (parent, _args, context) => {
13-
const { pactId, amount } = schema.parse(parent);
14+
const { pactId, requestKey, amount } = schema.parse(parent);
1415
if (!pactId) return null;
1516

1617
const output = await context.transferRepository.getCrossChainTransferByPactId({
1718
pactId,
19+
requestKey,
1820
amount,
1921
});
2022

23+
if (!output) return null;
24+
2125
return buildTransferOutput(output);
2226
};

0 commit comments

Comments
 (0)