use anyhow::{Context, Result};
use rustledger_core::{Directive, Transaction};
use std::path::Path;
pub(super) fn load_existing_transactions(path: &Path) -> Result<Vec<Transaction>> {
let options = rustledger_loader::LoadOptions {
run_plugins: false,
validate: false,
..Default::default()
};
let ledger = rustledger_loader::load(path, &options)
.with_context(|| format!("Failed to load existing ledger: {}", path.display()))?;
Ok(ledger
.directives
.into_iter()
.filter_map(|spanned| match spanned.value {
Directive::Transaction(txn) => Some(txn),
_ => None,
})
.collect())
}