Function ensure_status

Source
pub fn ensure_status(
    tx: &TransactionRepoModel,
    expected: TransactionStatus,
    operation: Option<&str>,
) -> Result<(), TransactionError>
Expand description

Validates that a transaction is in the expected state.

This enforces state machine invariants and prevents invalid state transitions. Used for domain-level validation to ensure business rules are always enforced.

§Arguments

  • tx - The transaction to validate
  • expected - The expected status
  • operation - Optional operation name for better error messages (e.g., “prepare_transaction”)

§Returns

Ok(()) if the status matches, Err(TransactionError) otherwise