Tallér: the coin system
High-level architecture for 501 · 25 November 2026 · not yet built
501 will sell a virtual coin, Tallér, as consumable in-app purchases. A player gets it by buying a pack, as a gift or by winning, and spends it where the game asks for it. This first project is the system underneath: hold a balance, add to it, take from it, list what happened, with a store screen whose purchase is a stand-in until a payment provider is chosen.
The idea
One number per account, whatever the source. Never below zero.
Every change is a line that is never edited. Ledger and balance always agree, and one query proves it.
A retry, a double tap or a repeated webhook changes nothing the second time.
The server says which packs exist and what they give. No app release to change one.
A stand-in now, a real provider later, with nothing around it changing.
The balance shown is always one the server answered.
Scope
| Now | Later |
|---|---|
|
|
How it fits together
Dashed boxes are the two places a real provider plugs in.
Tables
users one new column
- coin_balance
- the number the player sees; the database refuses a value below zero. Only the coin service writes it
coin_entries the ledger; never edited or deleted
- id
- rising number; history pages by it
- user_id
- → users
- type
- purchase, reversal, adjustment now; gift, ad reward, stake, payout later
- amount
- + in, − out
- balance_after
- the balance once this line is written
- idempotency_key
- unique per player and type: the same write counts once
- ref_type, ref_id
- what it was for: a purchase now, a room or a game later
- group_id
- lines written together share one (a pot)
- reverses_entry_id
- → coin_entries; an entry is undone once
- context
- internal details; never sent to the app as stored
- created_at
coin_packs switched off, never deleted
- id
- store_product_id
- unique; the same id in both stores. A key only: nothing is read out of it
- coins
- the whole sum credited
- bonus_coins
- how much of it is shown as “on top”
- tag
- none, popular, best value
- art_tier
- which picture
- sort_order
- place in the row
- is_active
- listed in the store or not
coin_purchases one per store transaction
- id
- user_id
- → users
- pack_id
- → coin_packs
- store
- Apple, Google, or the stand-in
- environment
- production or sandbox, so a test purchase cannot mint real coins
- store_transaction_id
- unique per store: one transaction credits one account, once
- coins_credited
- as it was then, whatever the pack says now
- status
- credited, refunded; pending and revoked when a provider needs them
- entry_id
- → coin_entries, the line that credited it
- price, currency, country
- as the provider reports them; cannot be filled in later
- created_at, refunded_at
user_groups who may use admin routes
- user_id
- → users
- group_name
- admin today; more groups later
- created_at
A purchase row and its ledger line are written in one transaction: both are there, or neither.
A route names the groups it allows, and membership is read from the database on every request, so removing someone works at once. Nothing in the API makes an admin: that is done by hand, where the database is.
Changing a balance
One service. Each operation is a single database transaction that locks the player's balance, updates it and writes its ledger line together, and it can join a larger transaction, so a credit lands with its purchase and a stake will land with its seat.
Add coins to a player.
Take coins. Too few: refused, nothing changes.
Undo one line. A store refund. Stops at zero and records what could not be taken back.
Several players at once, all or none. Built with the rooms that need it; the tables already have room for it.
Every ledger line says what it was, carries a unique key so it counts once, and stores the balance after it. A write sent again is answered “already done” before anything else is checked.
A purchase
The app confirms, the provider's webhook is the backup. Both use the same key, so whichever arrives first credits and the other changes nothing.
- The server never trusts the app: it asks the provider whether this account bought, and takes the product from the provider's answer.
- The provider keeps every purchase, so one the app failed to confirm is still credited: by the app's next try, or by the webhook.
- The app tells the provider who the player is at sign-in, so a purchase always arrives with its account.
- The webhook also covers what the app cannot see: refunds and purchases approved later.
Changing packs
| Change | Stores | Our server | App release |
|---|---|---|---|
| Coins, bonus, tag, picture, order | nothing | update the pack | no |
| Price | edit in the console | nothing | no |
| Add a pack | create the product in both; Apple reviews it | add the pack | no (the very first product ships with an app version) |
| Retire a pack | nothing | switch it off, never delete | no |
In the app
Coin and balance, top right in the lobby. A tap opens the store.
Packs in a row that scrolls sideways, dearest first, and the history of what came in and went out.
A dialog saying what is needed and what the player has; it leads to the store. Built with the first feature that charges.
The balance is only ever set from a server answer, and never from an older one. The store stays out of release builds until a real provider is in place.
- Account recovery and deletion. An account is a name and a password with no reset: a forgotten password would lose paid coins. Apple also requires that an account can be deleted in the app.
- Age rating. Staking coins against other players counts as simulated gambling: used often, Apple rates the app 18+, and some countries are stricter. It is not real-money gaming, because Tallér never turns back into money.
- No expiry. Apple does not allow bought currency to expire. With one balance, that means no Tallér ever expires.
- Refund after the coins moved. A player can buy, lose on purpose to a second account, and ask the store for a refund. Needs a rule (a debt, a frozen account) before rooms with a fee.
Open questions
- Does a new player start with some Tallér, and how much? Not needed to build this; can be added later.
- Which payment provider (Adapty is likely).
- Real pack amounts and prices. Placeholders until then; changing them is data, not code.
Roadmap
- Coins underneathLedger, packs, stand-in purchase, store screen.
- Real moneyAccount recovery, then the provider.
- Free coinsGifts and rewarded ads.
- Rooms with a feeMoving coins between players: entry, pot, games without a winner.