RevFramework – Sample Scene: 01_Currency_PolicyCaps¶
Goal¶
Teach how CurrencyPolicy cap rules shape currency operations before they are applied through the real ICurrencyService.
This scene focuses on min/max rules, Clamp vs Fail behaviour, policy preview, and caps-aware transfer preview.
What This Scene Demonstrates¶
This scene shows the policy decision flow for currency mutations.
The flow is:
Owner A → CurrencyPolicy → Preview → Apply through ICurrencyService → CurOpResult
- Owner A is the wallet being inspected and mutated
- Owner B is used for transfer preview and transfer apply
- The selected
CurrencyPolicyprovides per-currency min/max rules - The panel previews Set / Credit / Debit against the selected rule
- The panel previews transfer using
TryComputeEffectiveTransferAmount - The live service result is still the final truth
Policy preview explains the cap rule only.
A preview can say OK and the real operation can still fail if another composed service rule blocks it. That is correct behaviour.
What To Look For¶
Use the CurrencyPolicyCapsPanel to compare policy preview against real service results.
-
Bindings
-
Owner A is the wallet being inspected and mutated
- Owner B is used for A → B transfer behaviour
- Policy is the
CurrencyPolicyasset used for preview -
Service shows the resolved
ICurrencyServicestack -
Currency & Rule
-
Select a currency
- Inspect the active min/max rule
-
Confirm whether the rule uses Clamp, Fail, or pass-through behaviour
-
Probe
-
Choose Set, Credit, or Debit
- Enter an amount
- Compare Tentative, Adjusted, and Outcome
-
Apply the operation through the real service
-
Transfer
-
Enter a requested transfer amount
- Compare requested amount against effective amount
- Apply a real transfer using the effective amount
Sample Scope¶
This scene covers:
- Per-currency min/max cap rules
- Clamp vs Fail behaviour
- Policy-aware preview for Set / Credit / Debit
- Insufficient-funds handling during Debit preview
- Caps-aware transfer preview
- Applying previewed operations through the real
ICurrencyService
This scene does NOT cover:
- Exchange tables or conversion rates
- Escrow holds and expiry
- Persistence or replay
- Idempotency flows
- Batch transactions or awaiters
- Full multiplayer authority implementation
Those are taught in dedicated scenes.
Authority Note¶
This scene may include a permissive sample authority setup so it runs without additional configuration.
Networking Reminder¶
RevFramework does not include networking.
For multiplayer projects, currency mutations must be validated and executed through your own authority and networking layer.
How To Use¶
- Enter Play Mode.
- Toggle the
CurrencyPolicyCapsPanelwithF8. -
Confirm the top bindings:
-
Owner A is assigned
- Policy is assigned
ICurrencyServiceis resolved- Owner B is assigned if you want to test transfer behaviour
- Select a currency in the Currency & Rule section.
-
Inspect the rule:
-
min= lowest allowed balance max= highest allowed balancemax = 0means no upper limitClampadjusts into rangeFailrejects the operation-
In Probe:
-
Choose Set, Credit, or Debit
- Enter an amount
- Read Tentative, Adjusted, and Outcome
- Press Apply to run the real service call
-
In Transfer:
-
Enter a requested amount
- Read Requested, Effective, and Preview Code
- Press Transfer A → B to apply the effective transfer
Failure Behaviour¶
Failures are shown through preview outcome or the returned CurOpResult.
Common causes:
-
Play Mode required
-
The panel previews and applies against live wallet state
-
Fix: enter Play Mode
-
Service missing
-
No
ICurrencyServicewas resolved -
Fix: add
SceneCurrencyService, addCurrencyServiceBootstrap, or publish a composed service -
Owner A missing
-
Policy preview needs a wallet to inspect and mutate
-
Fix: assign Owner A or tag the player GameObject as
Player -
Policy missing
-
No
CurrencyPolicyasset is available for preview -
Fix: assign a policy asset in the Inspector
-
Owner B missing
-
Transfer preview cannot run without a target wallet
-
Fix: assign Owner B if testing transfer behaviour
-
Invalid CurrencyId
-
The selected
CurrencyDefinitionhas an invalid Id -
Fix: correct the CurrencyDefinition asset
-
Preview outcome is FAIL
-
The selected cap rule rejects the tentative value
-
Fix: change the amount, operation, currency, or policy rule
-
Preview allowed it, but service rejected it
-
Another service layer blocked the operation
- Fix: check authority, escrow, debit rules, service composition, and policy/cap configuration
Behind The Scenes¶
The panel uses real Currency APIs and data:
-
CurrencyResolve.ServiceFrom -
resolves the active
ICurrencyService -
CurrencyPolicy.TryGetCapRule -
reads the selected currency cap rule
-
ICurrencyService -
GetBalance SetBalanceCreditDebitTransfer-
TryComputeEffectiveTransferAmount -
CurOpResult -
Success CodeMessage
The preview calculations explain the selected policy rule.
The real service call still decides the final result.
Key Takeaway¶
Definitions describe the currency.
Policy defines allowed balance behaviour.
Preview explains the rule, but the ICurrencyService result is truth.