Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/indexer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Use Node.js 18
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'yarn'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface GetTotalCountParams {
export interface GetCrossChainTransferByPactIdParams {
pactId: string;
amount: string;
requestKey: string;
}

export type TransferOutput = Omit<Transfer, 'block' | 'transaction' | 'crossChainTransfer'> & {
Expand All @@ -43,6 +44,6 @@ export default interface TransferRepository {
}>;
getCrossChainTransferByPactId(
params: GetCrossChainTransferByPactIdParams,
): Promise<TransferOutput>;
): Promise<TransferOutput | null>;
getTotalCountOfTransfers(params: GetTotalCountParams): Promise<number>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,25 @@ export default class TransferDbRepository implements TransferRepository {
return pageInfo;
}

async getCrossChainTransferByPactId({ amount, pactId }: GetCrossChainTransferByPactIdParams) {
async getCrossChainTransferByPactId({
amount,
pactId,
requestKey,
}: GetCrossChainTransferByPactIdParams) {
let requestKeyParam = pactId;

if (pactId === requestKey) {
const query = `
SELECT requestkey
FROM "Transactions" t
JOIN "TransactionDetails" td ON t.id = td."transactionId"
WHERE td.pactid = $1 AND requestkey != $1
`;
const { rows } = await rootPgPool.query(query, [requestKey]);
const row = rows[0];
requestKeyParam = row.requestkey;
}

const query = `
select transfers.id as id,
transfers.amount as "transferAmount",
Expand All @@ -234,9 +252,10 @@ export default class TransferDbRepository implements TransferRepository {
and transfers.amount = $2
`;

const { rows } = await rootPgPool.query(query, [pactId, amount]);
const { rows } = await rootPgPool.query(query, [requestKeyParam, amount]);

const [row] = rows;
if (!row) return null;
const output = transferSchemaValidator.validate(row);
return output;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import { buildTransferOutput } from '../../output/build-transfer-output';

const schema = zod.object({
pactId: zod.string().nullable(),
requestKey: zod.string(),
amount: zod.string(),
});

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

const output = await context.transferRepository.getCrossChainTransferByPactId({
pactId,
requestKey,
amount,
});

if (!output) return null;

return buildTransferOutput(output);
};