diff --git a/server/src/db/schema.ts b/server/src/db/schema.ts index 0e676df..605b414 100644 --- a/server/src/db/schema.ts +++ b/server/src/db/schema.ts @@ -73,7 +73,7 @@ export const payments = sqliteTable('payments', { amountSats: integer('amount_sats').notNull(), method: text('method', { enum: ['lightning', 'cashu'] }).notNull(), status: text('status', { - enum: ['pending', 'confirmed', 'failed', 'refunded'], + enum: ['pending', 'confirmed', 'consumed', 'failed', 'refunded'], }).notNull().default('pending'), invoice: text('invoice'), preimage: text('preimage'), diff --git a/server/src/engine/payments.ts b/server/src/engine/payments.ts index 01926f6..eb22fbb 100644 --- a/server/src/engine/payments.ts +++ b/server/src/engine/payments.ts @@ -589,10 +589,11 @@ export async function redeemCashuToken(token: string, botId: string): Promise<{ /** Recover orphaned payments on startup */ export async function recoverOrphanedPayments(): Promise { - // Find confirmed entry payments without a fight — refund them + // Find confirmed/consumed entry payments without a fight — refund them + // 'consumed' payments were in the queue when server restarted const orphaned = await db.select().from(schema.payments) .where(and( - eq(schema.payments.status, 'confirmed'), + sql`${schema.payments.status} IN ('confirmed', 'consumed')`, eq(schema.payments.direction, 'in'), isNull(schema.payments.fightId), ))