Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,7 @@ describe('EscrowCompletionService', () => {
);
expect(mockEscrowCompletionRepository.updateOne).toHaveBeenCalledWith({
...paidPayoutsRecord,
failureDetail: 'Error message: Webhook url is no set for oracle',
status: 'failed',
status: 'completed',
});
});

Expand Down Expand Up @@ -988,10 +987,7 @@ describe('EscrowCompletionService', () => {
);
expect(mockEscrowCompletionRepository.updateOne).toHaveBeenCalledWith({
...paidPayoutsRecord,
failureDetail: expect.stringContaining(
'Failed to create outgoing webhook for oracle. Address: 0x',
),
status: 'failed',
status: 'completed',
});
});
});
Expand Down Expand Up @@ -1177,8 +1173,7 @@ describe('EscrowCompletionService', () => {
expect(mockEscrowCompletionRepository.updateOne).toHaveBeenCalledTimes(1);
expect(mockEscrowCompletionRepository.updateOne).toHaveBeenCalledWith({
...paidPayoutsRecord,
failureDetail: 'Error message: Oracle data is missing',
status: 'failed',
status: 'completed',
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ export class EscrowCompletionService {
);
}

escrowCompletionEntity.status = EscrowCompletionStatus.COMPLETED;
await this.escrowCompletionRepository.updateOne(escrowCompletionEntity);

const oracleAddresses: string[] = [
escrowData.launcher as string,
escrowData.exchangeOracle as string,
Expand All @@ -282,19 +285,26 @@ export class EscrowCompletionService {
: OutgoingWebhookEventType.ESCROW_COMPLETED,
};

let allWebhooksCreated = true;
for (const oracleAddress of oracleAddresses) {
const oracleData = await OperatorUtils.getOperator(
chainId,
oracleAddress,
);
if (!oracleData) {
throw new Error('Oracle data is missing');
this.logger.error('Oracle data is missing', {
escrowCompletionEntityId: escrowCompletionEntity.id,
oracleAddress,
});
continue;
}

const { webhookUrl } = oracleData;
if (!webhookUrl) {
throw new Error('Webhook url is no set for oracle');
this.logger.error('Webhook url is no set for oracle', {
escrowCompletionEntityId: escrowCompletionEntity.id,
oracleAddress,
});
continue;
}

try {
Expand All @@ -308,32 +318,14 @@ export class EscrowCompletionService {
* Already created. Noop.
*/
continue;
} else {
this.logger.error(
'Failed to create outgoing webhook for oracle',
{
error,
escrowCompletionEntityId: escrowCompletionEntity.id,
oracleAddress,
},
);

await this.handleEscrowCompletionError(
escrowCompletionEntity,
`Failed to create outgoing webhook for oracle. Address: ${oracleAddress}.`,
);
allWebhooksCreated = false;
break;
}
}
}

// Only set the status to COMPLETED if all webhooks were created successfully
if (allWebhooksCreated) {
escrowCompletionEntity.status = EscrowCompletionStatus.COMPLETED;
await this.escrowCompletionRepository.updateOne(
escrowCompletionEntity,
);
this.logger.error('Failed to create outgoing webhook for oracle', {
error,
escrowCompletionEntityId: escrowCompletionEntity.id,
oracleAddress,
});
}
}
} catch (error) {
this.logger.error('Failed to process paid escrow completion', {
Expand Down
Loading