RevFramework – Sample Scene: 07_Currency_BatchAndTxn¶
Namespace: RevGaming.RevFramework.Runtime.Currency.Samples.Scenes
🎯 Purpose¶
Show how to stage and commit multiple currency operations atomically using the CurrencyTxn system, and how to use batch events to receive a single consolidated update after a transaction completes.
This scene highlights atomic commits, rollbacks, and the event model for multi-operation changes.
🧩 What This Scene Teaches¶
- How to compose multi-step wallet operations with
CurrencyTxn. - How to commit staged operations as one atomic transaction.
- How to capture deltas via
CurrencyBatchduring multi-op commits. - How to subscribe to
ICurrencyBatchEvents.OnWalletBatchChangedfor consolidated updates. - How rollback works automatically if any operation in the batch fails.
🕹️ How to Use¶
- Enter Play Mode.
- Open the CurrencyBatchAndTxnPanel (
F8). - Observe bindings for Owner A, Owner B, and the active service.
- Batch Events Section
- Click Subscribe to listen for consolidated batch events.
- Commit a transaction to see all deltas logged together in a single event.
- Transaction Section
- Select a currency.
- Add multiple staged operations (
Credit,Debit,Set,Transfer). - Click Commit Txn to apply all operations atomically.
- If any operation fails, all previously staged changes rollback automatically.
🔐 Authority (Important)¶
This sample scene includes a CurrencyAuthorityBinder configured for single-player use:
CurrencyAuthorityBinderalwaysTrue = true
This allows all currency mutations so the demo works out of the box.
Why this exists¶
RevFramework currency mutations are authority-gated by default.
- If no authority is present, all mutations are blocked.
- This is intentional and required for multiplayer safety.
Multiplayer note¶
For multiplayer or server-authoritative games:
- Do not use
CurrencyAuthorityBinder - Implement your own
ICurrencyAuthority - Validate all currency mutations on the server/host
This scene uses the permissive binder only to demonstrate behaviour in a local, single-player context.
💡 Key Takeaways¶
CurrencyTxnprovides a fluent builder for multi-operation sequences:
var result = CurrencyTxn.Begin(svc, "QuestReward", "rid:789") .Debit(player, gold, 250) .Credit(player, gems, 5) .Credit(player, tokens, 1) .Commit();- All operations inside a transaction are atomic — either all succeed or all rollback.
- Batch events are fired once per commit via:
ICurrencyBatchEvents.OnWalletBatchChanged CurrencyBatchcollects deltas for UI updates and persistence layers.- Ideal for store purchases, quest rewards, loot bundles, or compound transactions.
- Compatible with all decorators (Audit, Caps, Authority, Escrow, Idempotency).
⚙️ Stack Composition¶
Bootstrap: CurrencyServiceBootstrap
Service Stack:
SceneCurrencyService → CappedCurrencyService → AuditedCurrencyService → AuthorityCurrencyService → IdempotencyCurrencyService → BatchEventCurrencyService
Teaching Panel: CurrencyBatchAndTxnPanel
Scene Path:
Assets/RevFramework/Runtime/Systems/Currency/Samples/Scenes/07_Currency_BatchAndTxn/
⚠️ Gotchas¶
- If any operation fails, the entire transaction rolls back — partial state is never left behind.
- Batch events trigger after successful commits only; failed transactions emit no events.
- Use
reasonandsourceIdto trace grouped transactions in audit logs. - Decorators (like Caps or Escrow) may alter commit results — always inspect the returned
CurOpResult. - Nested transactions aren’t supported; create discrete commits for complex flows.
- If this scene is running the bootstrapped service stack, removing
CurrencyAuthorityBinderwill cause all currency mutations to fail withUnauthorized.
📚 Related¶
- 06_Currency_Idempotency — Prevent duplicate transactions.
- Decorators — BatchEvent and Audit service internals.
- Core —
CurrencyTxnandCurrencyBatchimplementation. - Samples Index — Overview of all Currency sample scenes.
✅ Summary
This scene shows the real muscle of RevFramework’s Currency layer:
Atomic transactions, single event updates, and guaranteed rollback safety.