Skip to main content

Generated from package comments and exported declarations. Edit the Go source, not this file.

wallet

import "codeberg.org/hemanta212/playgo/api/wallet"

Package wallet defines player wallet command and snapshot contracts.

A wallet holds everything a player owns: cash, withdrawable cash, freeplay, and reward resources such as XP, diamonds, and spin tokens. Admin reads and every money-moving service use these types so all of it stays aligned with the ledger.

Two rules matter when using this package. Money is always integer cents, never formatted dollars: formatting is a display concern, and doing money math in floating point accumulates rounding errors that someone eventually has to reconcile by hand. And balances are derived from ledger entries rather than set directly, so a wallet snapshot is a view of the accounting, not a source of truth you can edit.

Variables​

var (
ErrInsufficientFunds = errors.New("wallet: insufficient funds")
ErrInvalidRequest = errors.New("wallet: invalid request")
)

type Balance​

type Balance struct {
UserID uuid.UUID
AccountID uuid.UUID
AmountCents ledger.Cents
CurrencyCode ledger.CurrencyCode
}

type CreditRequest​

type CreditRequest struct {
ActorID uuid.UUID
UserID uuid.UUID
AmountCents ledger.Cents
// HouseSubsidyCents is funded separately from provider receipts in the same transaction.
HouseSubsidyCents ledger.Cents
Idempotency IdempotencyInput
}

type DebitRequest​

type DebitRequest struct {
ActorID uuid.UUID
UserID uuid.UUID
AmountCents ledger.Cents
Idempotency IdempotencyInput
}

type FailureCode​

type FailureCode string
const (
FailureCodeInsufficientFunds FailureCode = "insufficient_funds"
FailureCodeInvalidRequest FailureCode = "invalid_request"
)

type IdempotencyInput​

type IdempotencyInput = idempotency.Input

type MoneyCommandResult​

type MoneyCommandResult struct {
TransactionID uuid.UUID
Balance Balance
Replayed bool
}

type ResultStatus​

type ResultStatus string
const (
ResultStatusSucceeded ResultStatus = "succeeded"
ResultStatusFailed ResultStatus = "failed"
)

type Service​

type Service interface {
EnsureUserWallet(ctx context.Context, userID uuid.UUID) (Wallet, error)
Balance(ctx context.Context, userID uuid.UUID) (Balance, error)
Credit(ctx context.Context, req CreditRequest) (MoneyCommandResult, error)
Debit(ctx context.Context, req DebitRequest) (MoneyCommandResult, error)
}

type Wallet​

type Wallet struct {
UserID uuid.UUID
AccountID uuid.UUID
Currency ledger.CurrencyCode
}

Generated by gomarkdoc