The ledger has one state: committed. Anything that looks pending, reserved, authorised or unsettled is value parked in an account you control, and its status is the balance of that account. To add a workflow state, add an account, not a flag.
Postings are immutable and a balance is a projection over them, so no row exists that a status could be written on. That is the whole of the constraint, and it is also the mechanism: because position is the only thing that can carry a state, every state change is a transfer, and every transfer is already conserved, content-addressed and in the log. A status modelled this way cannot drift from the money, because it is the money. A status column can.
This is why there is no Transfer::status and no pending flag on an account. Asking for one is usually asking for an account.
crates/kuatia/examples/escrow.rs is this page in runnable form. Run it with cargo run -p kuatia --example escrow.
An agreement's money sits in its own escrow account, a subaccount of one top-level escrow account, so one agreement's funds can never be spent by another and each closes independently.
const ESCROW: i64 = 50;
fn escrow_for(agreement: i64) -> AccountId {
AccountId::with_sub(ESCROW, agreement)
}
The account forbids overdraft, which is what makes releasing more than was deposited impossible rather than merely incorrect:
ledger
.create_account(Account::debit_must_not_exceed_credit(escrow_for(agreement)))
.await?;
Entering escrow is an ordinary payment, final the moment it commits:
ledger.commit(
TransferBuilder::new()
.pay(buyer, escrow_for(agreement), usd, amount)
.reference("escrow-in-7001")
.build(),
).await?;
Leaving it is the same transfer with a different destination. Release pays the seller, refund pays the buyer, and nothing distinguishes them to the ledger:
let held = ledger.balance(&escrow_for(agreement), &usd).await?;
ledger.commit(
TransferBuilder::new()
.pay(escrow_for(agreement), seller, usd, held) // or back to buyer
.reference("escrow-release-7001")
.build(),
).await?;
stateDiagram-v2
[*] --> InEscrow: pay buyer to escrow(7001)
InEscrow --> Released: pay escrow(7001) to seller
InEscrow --> Refunded: pay escrow(7001) to buyer
Released --> [*]: close the drained account
Refunded --> [*]: close the drained account
Three properties come free, and are the reason to model it this way rather than with a status field:
balance(escrow_for(agreement), usd) answers both "is this pending" and "how much", and cannot disagree with itself.close succeeds, and a closed account rejects further transfers. The agreement is finished rather than marked finished.| Business state | The account that holds it | What ends it |
|---|---|---|
| Card authorisation | Per-destination hold (implemented, see inflight.md) | Capture, or void on expiry |
| Escrow | Escrow account per agreement | Release to seller, or refund to buyer |
| Unsettled card batch | Clearing account per settlement cycle | Settlement file, netted to the bank account |
| Chargeback reserve | Reserve account per merchant | Dispute resolved either way |
| Unapplied receipt | Suspense account | Matched to an invoice |
| Accrued but unbilled revenue | Accrual account per period | Invoice issued |
Classical accounting calls the general shape a control account with a subsidiary ledger; payments systems call it a sub-ledger or virtual accounts under a master account. Subaccounts exist to make it cheap: an account is a base id plus a subaccount, so a per-agreement or per-cycle account is addressable without minting unrelated top-level accounts (ADR-0012).
Inflight holds apply this to authorisation and capture, with the per-destination holding account created for you. authorize rewrites every destination of a trade to a holding subaccount, confirm sweeps a hold to its destination, and void returns it to the funders recorded in the authorize transfer's leg table. All three are ordinary commits. Reach for them when the shape is authorise then capture, and build your own account when it is not.
Not every workflow state is money sitting somewhere. An authorisation you have accepted but not funded, a payment awaiting compliance review before any value moves, a quote: none of these park value, so none of them is an account. Those live outside the ledger, or as metadata on the transfer that eventually commits.
The test is whether value has moved. If it has, the state is an account. If it has not, the ledger has nothing to record yet, and recording it anyway means inventing the status field this model does without.