stuff
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user