Skip to main content

interpolate

Function interpolate 

Source
pub fn interpolate(
    transaction: &Transaction,
) -> Result<InterpolationResult, InterpolationError>
Expand description

Interpolate missing amounts in a transaction.

This function:

  1. Identifies postings with missing amounts
  2. For each currency, calculates the residual
  3. 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:

  • AtMostOneNull: At most one posting per currency can have a missing amount (returns MultipleMissing error if violated)
  • CompleteImpliesBalanced: After interpolation, sum(postings) = 0 for each currency
  • HasNullAccurate: filled_indices contains exactly the indices of postings that were originally missing amounts

See: spec/tla/Interpolation.tla

§Example

let txn = Transaction::new(date, "Test")
    .with_posting(Posting::new("Expenses:Food", Amount::new(dec!(50.00), "USD")))
    .with_posting(Posting::auto("Assets:Cash"));

let result = interpolate(&txn)?;
// Assets:Cash now has -50.00 USD