diff options
Diffstat (limited to 'internal/casino/machine.go')
| -rw-r--r-- | internal/casino/machine.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/internal/casino/machine.go b/internal/casino/machine.go index 5c73b6f..97b846d 100644 --- a/internal/casino/machine.go +++ b/internal/casino/machine.go @@ -277,7 +277,9 @@ func (m *Machine) finishSpin() []Event { payFailed := false if payNow > 0 && m.player.Wallet != nil { - if err := m.player.Wallet.PayCredits(payNow); err != nil { + // Credit the payout and consume the triggering stake in ONE save: a + // crash can then never pay the win AND refund the same stake. + if err := m.player.Wallet.PayCredits(payNow, m.stakeID); err != nil { // The payout could not be made durable. Do not announce the win as // paid, stop any autobet chain, and keep the stake PENDING // (stakeFailed): the settlement was never durable, so the stake is @@ -334,10 +336,9 @@ func (m *Machine) finishSpin() []Event { } else { m.inFreeSpins = false if !payFailed && m.player.Wallet != nil { - // The paid round fully resolved (the feature either never - // started or just completed; free spins wager nothing): consume - // ONLY this round's stake, leaving an older failed-payout stake - // pending. + // A win already consumed this round's stake inside PayCredits; a + // loss (payNow == 0) has not, so consume it here. Either way the + // round is over and the stake must not be refunded. m.player.Wallet.ResolveStake(m.stakeID) m.stakeID = "" m.stakeFailed = false |
