Skip to main content

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:

  1. The source account, to debit.
  2. The destination account, to credit. (With neitherflags.credits_must_not_exceed_debits nor flags.debits_must_not_exceed_credits set, since in this recipe we are only enforcing the invariant on a per-transfer basis.
  3. The control account, to test the balance invariant. The control account should have flags.credits_must_not_exceed_debits set.
IdDebit AccountCredit AccountAmountPending IdFlags
1SourceDestination123-linked
2DestinationControl1-linked, pending, balancing_debit
3--02void_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.