Skip to content

feat: credits_buyback host function (wire revision 8)#71

Merged
BCook98 merged 1 commit into
mainfrom
credits-buyback-abi
Jul 3, 2026
Merged

feat: credits_buyback host function (wire revision 8)#71
BCook98 merged 1 commit into
mainfrom
credits-buyback-abi

Conversation

@BCook98

@BCook98 BCook98 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What

Adds a credits_buyback host function so casino-kind games can offer a broke player a mid-session rebuy without leaving the game. Guest surface:

Buyback(p Player) (int64, error) // returns the new balance, symmetric to Balance

The host owns the policy — it applies the rebuy only when the player is broke (balance below a platform floor, open stake excluded) and under a per-day rebuy limit, credits the platform's buyback amount to the account and makes it wagerable in the current seat. A refusal (solvent, or the daily limit reached) is CreditsErrInsufficient (-1) with the balance unchanged.

Why

Casino games (blackjack, pokies, scratchies, roulette) need an in-game rebuy when a player busts. The existing credits ABI (balance/wager/settle) has no path to trigger the platform's broke-relief buyback from inside a game — this adds it.

Shape

Additive minor (wire Revision 7 → 8, ABI major stays 2). The meta payload is unchanged — this is only a new host function the guest may import, so existing games are unaffected.

  • wire: FnCreditsBuyback, Revision = 8 + ledger entry; rust WIRE_REVISION = 8; scalar golden + the hardcoded rust meta goldens regenerated for the revision byte.
  • Guest SDK: Credits.Buyback (Go internal/game api/host/room + dev runner; rust host extern + wrapper + test-host).
  • Host: sdk.CreditsService.Buyback + gameabi credits_buyback dispatch routed through creditsCall (inherits the casino-kind guard, roster bounds, and store timeout); memsvc + kittest doubles + fakeCredits stub.
  • ABI.md §3: credits_buyback row + buyback semantics + revision-8 note.
  • Changeset: kit minor.

Tests

  • go build/vet/test ./... green; cargo test --lib green (57 tests).
  • New memsvc TestCreditsBuyback: solvent → refused (balance unchanged), mid-hand (stake open) → not broke, broke → tops up to the amount and returns the new balance.

Downstream: shellcade pins v2.16.0 and implements CasinoWallet.Buyback (ledger buyback + reservation top-up + daily-limit-100 + rebuy-count tracking); the 4 casino games pin v2.16.0 and wire in-game rebuy.

🤖 Generated with Claude Code

Casino-kind games can now offer a broke player a mid-session rebuy without
leaving the game. `Credits.Buyback(p) (int64, error)` returns the new balance
(symmetric to Balance); the host owns the gate (broke-only floor + a per-day
rebuy limit) and makes the credited amount wagerable in the current seat. A
refusal (solvent, or the daily limit reached) is CreditsErrInsufficient with
the balance unchanged.

Additive minor: existing games are unaffected; the meta payload is unchanged
(only a new host function the guest may import). Wire Revision 7 -> 8.

- wire: FnCreditsBuyback, Revision 8 + ledger entry; rust WIRE_REVISION 8;
  scalar + hardcoded rust meta goldens regenerated for the revision byte.
- guest SDK: Credits.Buyback (Go internal/game api/host/room + dev runner;
  rust host extern/wrapper/test-host).
- host: sdk.CreditsService.Buyback + gameabi credits_buyback dispatch (routes
  through creditsCall, inheriting the casino-kind guard / roster bounds /
  timeout); memsvc + kittest doubles + fakeCredits stub.
- ABI.md §3: credits_buyback row + buyback semantics; revision-8 note.
- memsvc test: solvent-refused / mid-hand-not-broke / broke-tops-up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7oJQSTva5xgbAZomdV5Jj
@BCook98 BCook98 merged commit bf75d9c into main Jul 3, 2026
6 checks passed
@BCook98 BCook98 deleted the credits-buyback-abi branch July 3, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant