# Changelog All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ### Added - `kuatia` is now the only crate an application names in `Cargo.toml`. It re-exports `kuatia-core`, `kuatia-types` and `kuatia-storage`, and the SQL backend as `kuatia::sql` behind a new `sqlite` or `postgres` feature. The other crates stay published for custom development, such as a hand-written `Store`. - `SqlStore::connect(db_url)` and `Ledger::connect(db_url)` open a database and apply the schema, so opening a ledger no longer means naming `sqlx` and building the pool by hand. Both own the two traps that cost callers before: the SQLite driver must be installed before any connection opens, and `sqlite::memory:` gives each connection its own database, so a wider pool splits the ledger. - `kuatia::prelude` exports `SqlStore` under the `sql` feature. - A `quickstart` example, which the top-level README's quick example is held to by a test. - `Ledger::get_postings(ids)` reads postings by id from the immutable record. A committed envelope stores consumed ids alone, so without it a reader could not recover the owner or the value of anything a transfer spent. ### Fixed - The quick example in the README named an asset by a hand-minted `AssetId`, which the asset registry made unusable: an amount needs the handle the registry returns. `crates/kuatia/README.md` and `doc/crates.md` still showed the pre-registry builder verbs taking a separate asset and amount. - The dashboard's transfer feed showed only the postings a transfer created, so a reader could not tell debits from credits and the value that left an account was nowhere on screen. It now renders each transfer as a journal entry with both sides and a pair of per-asset totals, normalizing by sign so that a negative created posting reads as the debit it is. A deposit, which consumes nothing, had no debit side at all before. The feed also told a change output apart from an offset position by nothing, dimming both, though the offset is where a deposit's value comes from. Every account named in the dashboard is now a link to its own page; none of them were. The dashboard's transfer JSON changed shape with the view: `legs` and `consumes` give way to per-asset `debits`, `credits` and totals. ## [0.4.0] - 2026-12-02 ### Upgrading to 0.4.0 In this order, before the first commit against an upgraded database: 1. **Register every asset already in use**, with the precision it was always recorded at. A posting now rebuilds its amount by joining the registry, so a posting in an unregistered asset fails its read loudly rather than coming back at the wrong scale. 2. **Settle any two assets sharing a code** before migration `015` adds its unique index, or the migration fails on them. Two assets under one code split every balance held in it, which is the condition the index exists to prevent, and only a human knows which row is the real one. 3. **Drain inflight authorizations.** An authorization opened before the upgrade cannot be confirmed after it: the leg table is CBOR inside a transfer's metadata and its shape moved twice this cycle. Stored transfer ids from 0.3.0 do not reproduce. The content-address preimage moved twice: `payer` left it and `value_date` joined it, and `CANONICAL_VERSION` is now 6. The recorded ids are untouched and still verify against the bytes that produced them, so the audit trail is intact; recomputing one from its transfer under this version gives a different id. ### Added - `Ledger::authorize_until(transfer, expires_at)`, an authorization with a deadline, plus `expire(inflight, now)` and `expire_due(now)` to return its funds once that deadline has passed. An authorize with nobody to settle it used to park its funders' money indefinitely. The deadline is written onto the holding account at creation, where it cannot drift, and expiring runs the existing void path, so an expired authorization returns exactly what a void returns: each posting to the account that funded it, only the remainder when some legs were confirmed, and confirmations left alone. Nothing expires on its own: `expire_due` takes the clock and is a method a caller schedules. `authorize` is unchanged and records no deadline. See [doc/inflight.md](doc/inflight.md#expiry). - `Ledger::holdings(account)`, every asset one account holds, with what it holds of each. A balance read answered for one account and one asset, so asking what an account held at all meant the caller keeping its own list of the assets to ask about. Assets the account has no live posting of are absent rather than reported as zero. No read aggregates across accounts, so a trial balance, a balance sheet and a P&L are the application's to build, off the event stream where they can be cached (ADR-0031). `holdings` and `balances` are bounded by one account, which is what lets the store be sharded on it later. - Amounts are what the ledger stores and what it hands back. `Movement`, `Posting`, `NewPosting` and `BalanceProjection` each hold one `Amount` instead of an `AssetId` beside a value, and an amount serializes with its asset's definition, so a stored record decodes with no registry to consult. The content address is unchanged: it still hashes the asset's id and the value, and a golden vector in `kuatia-core` asserts it. The amount columns are unchanged too, so ADR-0024's exact sums and indexes still work; a posting read left-joins the registry to rebuild the amount, and fails loudly rather than dropping a row if an asset is missing. `Cent` no longer appears in any public signature: an `Amount` gives up `Display`, checked arithmetic that refuses two assets, and `minor_units() -> i128`, and the other crates reach the integer through `kuatia_types::internals`. `AssetId` stays public as the name of an asset. *(breaking throughout)* (ADR-0029) - An asset registry, and an `Amount` that carries its asset. `Asset { id, code, symbol, decimals }` is a row written once and never updated; `AssetStore` adds `create_asset`/`get_asset`/`list_assets` and migration `014_assets`. `Amount` pairs a `Cent` with the `Arc` it is denominated in, built only by conversion: an integer is minor units, a string is the written form parsed at the asset's own scale, so `(500, usd)` and `("5.00", usd)` are the same amount and `("5.001", usd)` is refused. `balance`, `balance_exact`, `balance_as_of` and `SubAccountBalance` now hand back an `Amount`, so two balances in different assets cannot be added by the caller holding them, and `InsufficientFunds` names the asset that fell short. A commit refuses an unregistered asset, and a balance read of one fails: an unregistered asset has no precision to report at. Each conversion also takes a reference to the asset (`("100.00", &usd)`), and `Denominate` gives the same conversions from the asset's side (`usd.amount("100.00")?`), so one handle serves several movements without cloning. `Arc` stops at the public API, so nothing stored moves and `CANONICAL_VERSION` stays at 6. *(breaking: every balance read, and any caller matching on `InsufficientFunds`)* (ADR-0028) - `Cent: TryFrom`, the range-checked conversion that previously existed only inside the canonical and storage byte decoders. - `Ledger::balance_as_of(account, asset, as_of)`, the balance as it stood at a past commit instant: the newest cache point at or before `as_of` plus the transfers committed up to it. `as_of` is commit time in unix milliseconds and never a value date, because the cache points a read folds against are watermarked by the commit clock. A past balance cannot be taken from the postings, which carry no timestamp, so the read folds transfers; with no cache point below `as_of` it folds the whole history up to it. An as-of read appends no cache point. No new storage method and no decision of its own: the storage lookup already took an `as_of` (ADR-0019). - `TransferBuilder::value_date(..)` and the `ValueDate` calendar-day type, for an entry booked on a different day than it belongs to: a correction, a late settlement, a future-dated order. `TransferQuery` gains `from_value_date` and `to_value_date`, so a period report groups by the day an entry takes effect rather than by the clock it was typed on. The value date is part of the content address, so two entries differing only in that day are two transfers, and `CANONICAL_VERSION` moves to 6: content addresses computed under an earlier version do not reproduce. `created_at` is unchanged and still not caller-supplied. Migration `013_value_date`. (ADR-0027) - `TransferBuilder::reference(..)`, which writes a caller-supplied reference under the reserved `REFERENCE_KEY` metadata key. A transfer's id is the hash of its content, so a transfer that consumes nothing (a deposit, an issuance) cannot distinguish itself from an identical earlier one and the second commit is reported as a replay. Setting a distinct reference makes two real deposits two transfers; repeating one keeps a retry idempotent. See [doc/transfers.md](doc/transfers.md#transfer-identity-give-every-distinct-transfer-a-reference). ### Changed - A transfer commits in one store transaction. `CommitStore::commit_envelope` spends the consumed postings, inserts the created ones, records the transfer and appends its event together, so a crash leaves nothing half applied and there is nothing to recover: the write-ahead record and its machinery (`SagaStore`, `PendingSaga`, `Ledger::recover`, the reserve/finalize phases) are gone and migration `010_drop_sagas` drops the table. The guards that used to be checked before the write are re-checked inside that transaction and are now strict rather than best-effort: double-spend (the delete's affected count is the atomic single-winner claim), freeze and close, and the no-overdraft floor. Multi-transfer composition is a plain LIFO runner over `commit` and `reverse` instead of a saga interpreter. *(breaking for `Store` implementors, and `Ledger::recover` is gone)* (ADR-0023) - Amount columns are native integers the database can add up exactly: `NUMERIC(39,0)` on PostgreSQL and a 16-byte order-preserving `BLOB` on SQLite, through migrations `011`. An amount used to be stored in a form only Rust could interpret, so every aggregate had to be folded in the process that asked, and the commit transaction could not check a balance without shipping the rows out of the database. The floor check and the live-balance read are now one exact aggregate inside the transaction, `SUM()` on Postgres and a registered `kuatia_i128_sum` on SQLite, both of which raise on overflow instead of wrapping. Ordering and range predicates work on the column directly. No floating point goes near an amount, and everything that is not an exact aggregate over one of these columns is still computed in Rust with checked arithmetic. *(on-disk format change)* (ADR-0024) - `payer` is provenance and no longer part of a transfer's identity, so it left the content-address preimage. Two transfers that differ only in who paid are now one transfer and the second commit is reported as a replay, which is the point: the payer is a record of where the funds came from, not a way to make an otherwise identical transfer distinct. *(breaking: a transfer id computed under 0.3.0 does not reproduce)* - `Ledger::asset(code, symbol, decimals)` registers an asset on first sight and returns its handle, so naming money takes one line and no invented id: `ledger.asset("EUR", "\u{20ac}", 2)`. Idempotent, so setup code calls it unconditionally; a code already registered at another precision is `AssetRedefined` rather than either definition quietly winning. The id is minted in Rust as an account's or a book's is, `code` is unique (migration `015_asset_code_unique`), and `AssetStore` gains `get_asset_by_code`. The by-id lookup is now `asset_by_id`, and `create_asset` stays for a caller that wants to choose the id. *(breaking: `Ledger::asset` has a new meaning)* (ADR-0030) - Anything that names an asset takes `impl Into`: `BookBuilder::allow_asset` and the `Ledger` reads (`asset`, `balance`, `balance_exact`, `balance_as_of`, `balances`). An `Asset`, an `Arc`, a reference to either, or the id itself all work, so a caller holding a handle stops writing `.id` to get four bytes back out of it. The `Store` trait keeps `&AssetId`, since it is used behind `Arc` and a generic method would cost object safety. - An amount conversion takes the value first: `(500, usd)`, `("5.00", usd)`, `(500, &usd)`. The asset-first spelling is gone, because one order is enough and this one reads the way the money does. - `Denominate` covers `Asset` as well as `Arc`, so `asset.amount(500)?` works on a row from `list_assets` and not only on a handle from `asset`. It is a trait, so it has to be in scope; the prelude brings it. - `Asset::scale` is no longer public. It returned a `Scale`, which this cycle took off the public surface, so a caller could call it and not name what came back. An amount formats and parses itself. - A decimal amount refuses a second sign. `"--5"` used to strip one sign, parse the rest with another, and come back as a positive five. One sign is allowed, of either kind, and a digit or a point has to follow it. - `Ledger::asset` reports `AssetNotFound` only for an absent row. A store failure used to arrive as the same error, so a dropped connection told a caller to register an asset it had registered already. - `TransferBuilder`'s verbs take one amount in place of an asset beside a value: `.pay(from, to, amount)`, `.deposit(to, amount, external)`, `.withdraw(from, amount, external)`, `.movement(from, to, amount)`, where `amount` is anything convertible into an `Amount`. A failed conversion is held until `build`, which now returns `Result`. That retires `deposit`'s mid-chain `Result`, which was the one verb that broke the fluent chain. *(breaking for every builder call site)* (ADR-0028) - `kuatia_money::Amount` is `Scale` and `ParseAmountError` is `ParseDecimalError`. The old name described a decimal-place count that parsed and formatted and was never stored, and it is the name the asset-carrying value wants. An asset's scale is reachable as `asset.scale()`. *(breaking)* (ADR-0028) - `SubAccountBalance::value` is `amount`, and carries an `Amount`. *(breaking)* - The dashboard's hardcoded asset table is gone: it registers its assets in the ledger and reads precision back from there. Its `/api/overview` issued figures serialize under `value` rather than `issued`. - The ledger no longer has to be held in an `Arc`. `commit`, `commit_envelope`, `reverse`, the inflight entry points and `workflow::run_transfers` take `&self`, so `Ledger::new(store)` is usable directly; an `Arc` still derefs, so sharing stays available to callers who want it. *(breaking only for code naming the receiver type)* (ADR-0026) - `EnvelopeId` is `TransferId` and `EnvelopeRecord` is `TransferRecord`, so the public surface speaks of transfers throughout. `Envelope`, `EnvelopeBuilder` and `commit_envelope` keep their names as the resolved form. Nothing stored changes: no migration, no content address and no dedup key moves. *(breaking)* (ADR-0026) - `Ledger::compute_balance` is `balance_exact`, beside `balance`, so a call site says whether it took the cached read or the authoritative one. *(breaking)* (ADR-0026) - `Ledger::with_snapshot_interval` and `with_projection_grace_ms` become one `with_projection_config(ProjectionConfig { .. })`. *(breaking)* (ADR-0026) - `kuatia::saga` is now `kuatia::workflow`, and `run_movements` is `run_transfers`, taking the transfers themselves. Its own `Movement`, `PayInput` and `DepositInput` described legs it then rebuilt with `TransferBuilder`, and that `Movement` shadowed `kuatia_types::Movement`. *(breaking)* - `ValidationError::OverdraftExceeded` no longer carries a `floor` field. The balance model is binary (an account either permits unbounded overdraft or forbids any negative balance), so the floor was always zero and implied a configurable bound that does not exist. *(breaking for callers matching on the variant)* ### Removed - `TransferBuilder::movement_ref` and `pay_ref`. Both pushed the same `Movement` as `movement` and `pay`: ADR-0012 meant them for subaccount endpoints, but every endpoint is a full `AccountId` already. *(breaking)* (ADR-0026) - `Ledger::append_cache_point` moves to `ledger.projection().append_cache_point(..)`, since it maintains the balance cache rather than reading a balance. *(breaking)* (ADR-0026) - The reservation protocol, which the atomic commit of ADR-0023 had left without a producer. `PostingState::Reserved`, `PostingFilter::{Active, Reserved}`, `ReservationId` and `TransitionId` are gone, and `live_postings.reservation` is dropped by migration `012_drop_reservation`. A posting is live or spent, with nothing in between. *(breaking: `PostingState::Active` is now `Live`, which also changes its serde representation, and the dashboard reports a posting's status as "Live" rather than "Active")* (ADR-0025) - Six `Store` write methods: `reserve_postings`, `release_postings`, `deactivate_postings`, `insert_postings`, `append_account_version` and `store_transfer`. Nothing called them, and because `Ledger::store()` returns the trait they were a public route to spend a posting or append a version while skipping the guards the commit transaction enforces. `CommitStore` is now the only way either is written. *(breaking for out-of-tree backends)* (ADR-0025) ## [0.3.0] - 2026-07-30 ### Added - Subaccounts: `AccountId` gains a subaccount leg (`{ id, sub }`), so several independent balances live under one owner, each individually addressable, drained, and closed. Aggregate reads take a base id plus an optional subaccount filter; exact operations take the full `AccountId`; balances are never summed across subaccounts. (ADR-0012) - Inflight holds: authorize, confirm, and void value through per-destination holding subaccounts, so an authorization reserves funds without committing them and a void returns them. (ADR-0014) - IBAN-style account identifiers: `AccountId` has a fixed 20-character `Display`/`FromStr` form (a base-36 body plus two mod-97 check digits) for presentation and routing, while storage keeps the two integer legs. (ADR-0015) - Cached balance projection: an append-only balance snapshot, refreshed lazily off the read path once enough activity accrues, shortens the everyday balance read; the authoritative live-posting sum stays the source of truth. (ADR-0019) - `SagaStore::get_saga`, a keyed read for a single write-ahead record, so recovery no longer scans every pending record. - Continuous integration now runs the storage conformance suite against PostgreSQL (exercising the Postgres-only `FOR UPDATE` and `ON CONFLICT` paths) and runs the test suite with the i128 Cent backing. ### Changed - Storage write contract: every `Store` write method returns the number of affected rows and makes no domain decision. The saga interprets counts and owns idempotency and compensation, with a phase-tracked write-ahead record and roll-forward crash recovery in place of a monolithic commit transaction. (ADR-0003) *(breaking for `Store` implementors)* - Account balance constraint collapsed to the single `DEBIT_MUST_NOT_EXCEED_CREDIT` flag; overdraft is allowed by default. (ADR-0018) - The SQL schema separates append-only value tables from disposable active/reserved index tables. (ADR-0016, ADR-0017) - Intent resolution is pure and preserves typed errors across the saga. - Internal structure: the `Ledger` was split into concern-named submodules; the commit-safety invariant is documented and its double-spend guard named (ADR-0021); the write-ahead recovery record was concentrated into one `pending` module; balance computation was consolidated into one module. ### Removed - The vestigial `UserData` type and the orphaned withdraw saga step. *(breaking)* ### Documentation - Document that the ledger supports journaling: a committed transfer is a journal entry, a transfer with multiple movements is a compound journal entry, and the transfer log is the accounting journal. Adds `doc/journaling.md` and ADR-0013, and notes it in the README overview. ## [0.2.0] - 2026-07-01 ### Added - `kuatia-dashboard`: a server-rendered dashboard and REST API for observing a Kuatia ledger over HTTP. Browse accounts, postings, transfers, and the event log; inspect per-account balances computed in Rust. ### Changed - The SQL backend stores binary identifiers as hex text and structured columns as JSON text instead of opaque blobs, so a ledger can be audited directly with SQL tooling. The SQLite and PostgreSQL schemas were unified into a single `001_init.sql`. ## [0.1.0] - 2026-06-30 Initial release. ### Added - Append-only, multi-asset, UTXO-style ledger. Value is tracked as signed postings with no mutable balance fields. Transfers atomically consume and create postings, enforcing per-asset conservation (`sum(consumed) == sum(created)`). - Intent API: movements (`pay`, `deposit`, `withdraw`) resolved into concrete postings by the core, committed through a single `reserve → finalize` saga with automatic retry and LIFO compensation. - Content-addressed transfers (double-SHA-256 of canonical bytes) for idempotency and tamper evidence. - Account policies: `NoOverdraft`, `CappedOverdraft`, `UncappedOverdraft`, `SystemAccount`, `ExternalAccount`, with append-only versioned accounts and snapshot pinning to guard against TOCTOU races. - Durable crash recovery via a phase-tracked write-ahead saga record and `Ledger::recover()` (roll-forward, not rollback). - Dumb-storage `Store` trait split into focused sub-traits, with an in-memory backend and a SQLite/PostgreSQL backend (`kuatia-storage-sql`). - A conformance test suite (`store_tests!`) applied to every storage backend. - Snowflake-style `i64` IDs generated in Rust; the database never assigns IDs. - Compile-time swappable monetary backing (`i64` default, `i128` via the `i128` feature). ### Crates - `kuatia-money` — monetary `Cent` type with swappable integer backing. - `kuatia-types` — domain types: accounts, postings, transfers, books. - `kuatia-core` — pure, sans-IO logic: validation, hashing, posting selection. - `kuatia-storage` — storage abstraction and conformance suite. - `kuatia-storage-sql` — SQLite/PostgreSQL backend. - `kuatia` — async `Ledger` resource and the atomic commit path. [0.4.0]: https://github.com/crodas/kuatia/releases/tag/v0.4.0 [0.3.0]: https://github.com/crodas/kuatia/releases/tag/v0.3.0 [0.2.0]: https://github.com/crodas/kuatia/releases/tag/v0.2.0 [0.1.0]: https://github.com/crodas/kuatia/releases/tag/v0.1.0