kuatia-types (asset, book), kuatia-storage
(AssetStore), kuatia-storage-sql (migration 015), kuatia
(ledger::asset), kuatia-dashboardADR-0028 gave assets caller-supplied ids, reasoning that an asset is named like an account rather than minted. In practice a caller names an asset by its code and has no opinion about its id, so registering one took two steps and an invented number:
ledger.create_asset(Asset::new(AssetId::new(2), "EUR", "€", 2)).await?;
let eur = ledger.asset(&AssetId::new(2)).await?;
The 2 is the caller keeping a registry of its own alongside the ledger's, which is the thing the registry exists to stop. Every test, example and seed in the tree carried such a table, and nothing but convention kept two of them from disagreeing.
Pros:
Cons:
An AssetId is a hash of the code, so one code is one id in every database.
Pros:
EUR agree without coordination, which helps if they are ever compared.Cons:
Pros:
AutoId, never from the database.Cons:
Chosen option: name by code, mint the id.
Ledger::asset(code, symbol, decimals) is get-or-create and returns Arc<Asset>. The by-id lookup keeps its behaviour as asset_by_id. create_asset stays for a caller that wants to choose the id.
A code registered with other metadata is LedgerError::AssetRedefined. Returning the stored row would hand back a precision the caller did not ask for and mis-state every amount formatted through it; rewriting the row is not possible, since a registry row is immutable (ADR-0028). So neither side wins and the disagreement is reported, carrying both decimal counts.
The id comes from AutoId, folded into the u32 an AssetId carries, retried past the small chance that a truncated snowflake lands on an id already taken. A code's uniqueness is the index's job, so a concurrent registration of the same code is caught by re-reading it rather than by locking.
code is unique (migration 015_asset_code_unique). Without it a get-or-create could register a second EUR under a different id and split every balance held in it.
AssetStore gains get_asset_by_code, returning an Option rather than NotFound, because the caller asking by code is deciding whether to register.
ledger.asset("EUR", "€", 2).AssetId is no longer portable between databases, which it was when a caller chose it. Nothing in the ledger compares ids across databases, but a tool that did would have to map by code.