This commit is contained in:
Dorian
2026-04-11 19:46:37 +01:00
parent 52752a92bf
commit 32e6c19f72
44 changed files with 5511 additions and 39 deletions
+4 -1
View File
@@ -115,6 +115,7 @@ export function lockBets(fightId: string): void {
* Settle all bets for a completed fight.
* Winners get their payout as new Cashu tokens.
* Losers forfeit their tokens.
* Uses a try/finally pattern to ensure escrow is only cleared on success.
*/
export async function settleBets(
fightId: string,
@@ -125,6 +126,7 @@ export async function settleBets(
const settlements: BetSettlement[] = []
// Process all bets before clearing escrow — if minting fails, escrow stays intact
for (const bet of pool.bets) {
// Draw: refund all bets
if (!winnerId) {
@@ -159,7 +161,8 @@ export async function settleBets(
}
}
// Clean up escrow
// Only clear escrow after all settlements succeeded
// If any mintCashuToken call threw, we never reach here and escrow remains intact
escrow.delete(fightId)
return settlements