From 5e3d11b6141f4947e399cd23eb7369f4aa51f91b Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Thu, 14 Dec 2023 11:35:28 +0800 Subject: [PATCH] repair status error --- apollo/src/xtoken/xtoken.service.ts | 36 ++++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/apollo/src/xtoken/xtoken.service.ts b/apollo/src/xtoken/xtoken.service.ts index efa6d56a..0da9c221 100644 --- a/apollo/src/xtoken/xtoken.service.ts +++ b/apollo/src/xtoken/xtoken.service.ts @@ -205,7 +205,7 @@ export class xTokenService implements OnModuleInit { variables: null, }) .then((res) => res.data?.data?.messageDispatchedResult); - if (node === null || node.result === null) { + if (node === undefined || node.result === null) { continue; } let result = uncheckedRecord.result; @@ -226,20 +226,28 @@ export class xTokenService implements OnModuleInit { result = RecordStatus.success; responseTxHash = node.transactionHash; } - if (result !== uncheckedRecord.result) { - this.logger.log( - `${this.baseConfigure.name} [${uncheckedRecord.fromChain}-${uncheckedRecord.toChain}] status updated, id: ${id}, status ${uncheckedRecord.result}->${result}` - ); - await this.aggregationService.updateHistoryRecord({ - where: { id: uncheckedRecord.id }, - data: { - responseTxHash, - result, - endTime: Number(node.timestamp), - }, - }); + // only pending status for the transfer need to be updated by this dispatch result + if (uncheckedRecord.result === RecordStatus.pending || uncheckedRecord.result === RecordStatus.pendingToClaim) { + if (result !== uncheckedRecord.result) { + this.logger.log( + `${this.baseConfigure.name} [${uncheckedRecord.fromChain}-${uncheckedRecord.toChain}] status updated, id: ${id}, status ${uncheckedRecord.result}->${result}` + ); + await this.aggregationService.updateHistoryRecord({ + where: { id: uncheckedRecord.id }, + data: { + responseTxHash, + result, + endTime: Number(node.timestamp), + }, + }); + uncheckedRecord.result = result; + } } + // update refund status + // 1. pendingToRefund -> pendingToConfirmRefund: refund request sent, no result found + // 2. pendingToRefund/pendingToConfirmRefund -> refunded: any refund request's result confirmed and successed + // 3. pendingToConfirmRefund -> pendingToRefund: all refund request confirmed but failed if ( uncheckedRecord.result === RecordStatus.pendingToRefund || uncheckedRecord.result === RecordStatus.pendingToConfirmRefund @@ -290,7 +298,7 @@ export class xTokenService implements OnModuleInit { // some tx not confirmed -> RecordStatus.pendingToConfirmRefund if (uncheckedRecord.result != RecordStatus.pendingToConfirmRefund) { this.logger.log( - `${this.baseConfigure.name} waiting for refund confirmed, id: ${uncheckedRecord.id} old status ${uncheckedRecord.result}` + `${this.baseConfigure.name} [${uncheckedRecord.fromChain}->${uncheckedRecord.toChain}] waiting for refund confirmed, id: ${uncheckedRecord.id} old status ${uncheckedRecord.result}` ); uncheckedRecord.result = RecordStatus.pendingToConfirmRefund; // update db