pub fn interpolate(
transaction: &Transaction,
) -> Result<InterpolationResult, InterpolationError>Expand description
Interpolate missing amounts in a transaction.
This function:
- Identifies postings with missing amounts
- For each currency, calculates the residual
- Fills in the missing amount to balance
§Rules
- At most one posting per currency can have a missing amount
- If a posting has a cost spec with a currency, that currency is used
- Otherwise, the posting gets the residual that makes the transaction balance
§TLA+ Specification
Implements invariants from Interpolation.tla (post-#1030 redesign for
N postings + multi-currency + cost-unknowns):
AtMostOneUnknownPerCurrency: For each currency group, at most one posting may be “unknown” — either a missing amount (counts toward the units currency) or an empty cost spec like{}(counts toward the cost currency, since the cost-basis weight is unresolved until booking-pass lot matching). ReturnsMultipleMissingif violated.CompleteImpliesValidated: Interpolation only completes the transaction when the validation rule holds.
The spec models the structural validation rule, not the residual
arithmetic that produces filled amounts — see Interpolation.tla’s
header for the scope rationale.
See: spec/tla/Interpolation.tla
§Example
ⓘ
let txn = Transaction::new(date, "Test")
.with_synthesized_posting(Posting::new("Expenses:Food", Amount::new(dec!(50.00), "USD")))
.with_synthesized_posting(Posting::auto("Assets:Cash"));
let result = interpolate(&txn)?;
// Assets:Cash now has -50.00 USD