jonnify·bcs /bcs/codemojex/the-economy/the-transactional-wallet

B7.5.2 · dive 2 of 3 · module B7.5

The transactional wallet.

Balances live in a wallet keyed by the USR account; the balance is the running total of an append-only TXN ledger, and every move is a debit and a credit applied together in one all-or-nothing transaction.

A wallet keyed by USR, an append-only ledger, and moves as one all-or-nothing transaction. Select a part.
the walletkeyed by USRone per account the TXN ledgerappend-only entriesthe balance is derivedalways there to audit one transactiondebit and creditall or nothing
readout · Select a part. The wallet is keyed by USR; the balance is the running total of an append-only TXN ledger; every move is a debit and a credit applied together in one all-or-nothing transaction.
§1

The idea

codemojex · the transactional wallet

A player’s balances live in a wallet keyed by their USR account, one wallet per account across every room they play. The wallet is not a number that is edited in place; it is the running total of a ledger. Every credit and debit is a TXN entry, and the balance is what the entries sum to, so the history is always there to audit.

Money moves only through the economy, and only inside a transaction. Charging a guess, crediting a purchase, paying a prize — each is a debit and a credit applied together, all-or-nothing, so a balance is never left half-changed by a crash between two steps. The reference implementation composes these as a single database transaction, which either commits whole or leaves the wallet exactly as it was.

Because the ledger is the truth and the balance is derived, the economy reconciles. A disputed charge is a row to read, not a mystery; a wallet can be rebuilt from its entries; and the same discipline that keeps a guess from charging twice keeps a payout from paying twice. The wallet sits on the Postgres floor, the record of truth, with the rest of the game’s record.

§4

The doors

the sibling courses
§2

References

sources · related

Sources

Related