Lines
100 %
Functions
Branches
//! What a transaction the browser submitted stored.
use anyhow::Result;
use uuid::Uuid;
use super::harness::Harness;
use crate::common::tenant::tenant_connection;
pub async fn snapshot(h: &Harness, transaction: Uuid) -> Result<Vec<String>> {
let mut conn = tenant_connection(h.tenant.id).await;
Ok(server::lossless::snapshot(&mut *conn, transaction).await?)
}
/// `account commodity value` of every split, sorted.
pub fn legs(snapshot: &[String]) -> Vec<String> {
let mut legs: Vec<String> = snapshot
.iter()
.filter_map(|fact| fact.strip_prefix("split "))
.map(|fact| fact.split(' ').take(3).collect::<Vec<_>>().join(" "))
.collect();
legs.sort();
legs
/// `account value name value` of every split tag, sorted.
pub fn leg_tags(snapshot: &[String]) -> Vec<String> {
let mut tags: Vec<String> = snapshot
.filter_map(|fact| fact.strip_prefix("split-tag "))
.map(|fact| {
let words: Vec<&str> = fact.split(' ').collect();
let tail = words.len().saturating_sub(3);
format!(
"{} {} {} {}",
words.first().unwrap_or(&""),
words.get(2).unwrap_or(&""),
words.get(tail).unwrap_or(&""),
words.get(tail + 1).unwrap_or(&"")
)
})
tags.sort();
tags
/// One expected leg: account, commodity and the value as stored.
pub fn leg(account: Uuid, commodity: Uuid, value: &str) -> String {
format!("{account} {commodity} {value}")