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
1 change: 1 addition & 0 deletions src/services/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const WEBHOOK_EVENT_TYPES = [
"expense.created",
"expense.settled",
"settlement.completed",
"settlement.confirmed",
"settlement.failed",
"treasury.proposal.created",
"treasury.proposal.signed",
Expand Down
9 changes: 9 additions & 0 deletions src/services/settlement-reconciliation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
verifyPaymentOperation,
getTransactionPayments,
} from "./horizonService";
import { dispatchEvent } from "./webhook";

const log = pino({ name: "settlement-reconciliation" });

Expand Down Expand Up @@ -64,6 +65,7 @@ export async function reconcileSettlements(
await reconcileSingleSettlement(
{
id: row.id,
groupId: row.groupId,
stellarTxHash: row.stellarTxHash,
retryCount: row.retryCount,
shortCode: row.shortCode,
Expand Down Expand Up @@ -93,6 +95,7 @@ export async function reconcileSettlements(
*/
export interface ReconcilableSettlement {
id: string;
groupId?: string;
stellarTxHash: string | null;
retryCount: number;
/** Settlement short code, used to derive the expected memo (MP:<code>). */
Expand Down Expand Up @@ -178,6 +181,8 @@ export async function reconcileSingleSettlement(
entityId: settlement.id,
metadata: { stellarTxHash: hash, reason: err.message },
});
void dispatchEvent("settlement.failed", { settlementId: settlement.id, reason: err.message }, settlement.groupId)
.catch(() => undefined);
recLog.error(
{ id: settlement.id, hash, reason: err.message },
"settlement transaction verification failed"
Expand All @@ -204,6 +209,8 @@ export async function reconcileSingleSettlement(
entityId: settlement.id,
metadata: { stellarTxHash: hash },
});
void dispatchEvent("settlement.confirmed", { settlementId: settlement.id, stellarTxHash: hash }, settlement.groupId)
.catch(() => undefined);
recLog.info({ id: settlement.id, hash }, "settlement completed");
} else {
await applySettlementTransition({
Expand All @@ -222,6 +229,8 @@ export async function reconcileSingleSettlement(
entityId: settlement.id,
metadata: { stellarTxHash: hash, reason: "transaction_failed" },
});
void dispatchEvent("settlement.failed", { settlementId: settlement.id, reason: "transaction_failed" }, settlement.groupId)
.catch(() => undefined);
recLog.error({ id: settlement.id, hash }, "settlement transaction failed on Stellar");
}
}
Expand Down