Skip to content

Commit

Permalink
repair status error
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Dec 14, 2023
1 parent eb2a003 commit 5e3d11b
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions apollo/src/xtoken/xtoken.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5e3d11b

Please sign in to comment.