Balance-invariant Transfers
For some accounts, it may be useful to enforce flags.debits_must_not_exceed_credits
or flags.credits_must_not_exceed_debits
balance invariants for only a subset of all transfers, rather than all
transfers.
Per-transfer
credits_must_not_exceed_debits
This recipe requires three accounts:
- The source account, to debit.
- The destination account, to credit. (With
neither
flags.credits_must_not_exceed_debitsnorflags.debits_must_not_exceed_creditsset, since in this recipe we are only enforcing the invariant on a per-transfer basis. - The control account, to test the balance invariant.
The control account should have
flags.credits_must_not_exceed_debitsset.
| Id | Debit Account | Credit Account | Amount | Pending Id | Flags |
|---|---|---|---|---|---|
| 1 | Source | Destination | 123 | - | linked |
| 2 | Destination | Control | 1 | - | linked,
pending,
balancing_debit |
| 3 | - | - | 0 | 2 | void_pending_transfer |
When the destination account’s final credits do not exceed its
debits, the chain will succeed. When the destination account’s final
credits exceeds its debits, transfer 2 will fail with
exceeds_debits.