diff options
Diffstat (limited to 'internal/game/money.go')
| -rw-r--r-- | internal/game/money.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/game/money.go b/internal/game/money.go index 6317df8..6965859 100644 --- a/internal/game/money.go +++ b/internal/game/money.go @@ -48,6 +48,20 @@ func removePendingWager(p *player.Player, id string) bool { return removed } +// countUniqueNonEmpty returns the number of distinct non-empty IDs in ids. +// PayCredits/PayPoker use it to fail closed when a payout names a stake that +// is not present (or names one twice): paying it anyway would double-pay with +// no ledger entry left for startup recovery. +func countUniqueNonEmpty(ids []string) int { + seen := make(map[string]bool, len(ids)) + for _, id := range ids { + if id != "" { + seen[id] = true + } + } + return len(seen) +} + // takePendingWagers removes and returns the pending stakes whose IDs are // listed, leaving the rest. It is used by a settlement that returns a // specific set of stakes (a table hand). |
