use crate::receipt::RuntimeReceiptV1;
use std::collections::BTreeSet;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RuntimeIndex {
pub pipeline_id: String,
pub stage_ids: Vec<String>,
pub authorities: Vec<String>,
pub receipt_hash: String,
}
impl RuntimeIndex {
pub fn of(receipt: &RuntimeReceiptV1) -> Self {
let stage_ids = receipt.stages.iter().map(|s| s.stage_id.clone()).collect();
let mut auth: BTreeSet<String> = BTreeSet::new();
for s in &receipt.stages {
for a in &s.authority_hashes {
auth.insert(a.name.clone());
}
}
RuntimeIndex {
pipeline_id: receipt.pipeline_id.clone(),
stage_ids,
authorities: auth.into_iter().collect(),
receipt_hash: receipt.receipt_hash.clone(),
}
}
pub fn summary_line(&self) -> String {
format!(
"{}: {} stage(s) [{}] over authorities [{}] -> {}",
self.pipeline_id,
self.stage_ids.len(),
self.stage_ids.join(", "),
self.authorities.join(", "),
&self.receipt_hash[..self.receipt_hash.len().min(12)],
)
}
}