use cortex_core::ClaimCeiling;
use serde::{Deserialize, Serialize};
use crate::witness::WitnessSummary;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BrokenEdge {
pub invariant: String,
pub detail: String,
}
impl BrokenEdge {
#[must_use]
pub fn new(invariant: &'static str, detail: impl Into<String>) -> Self {
Self {
invariant: invariant.to_string(),
detail: detail.into(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "state", rename_all = "snake_case")]
pub enum VerifiedTrustState {
FullChainVerified {
ceiling: ClaimCeiling,
witnesses: Vec<WitnessSummary>,
},
Partial {
reasons: Vec<String>,
witnesses: Vec<WitnessSummary>,
},
Broken {
edge: BrokenEdge,
witnesses: Vec<WitnessSummary>,
},
}
impl VerifiedTrustState {
#[must_use]
pub const fn is_full_chain_verified(&self) -> bool {
matches!(self, Self::FullChainVerified { .. })
}
#[must_use]
pub const fn is_broken(&self) -> bool {
matches!(self, Self::Broken { .. })
}
#[must_use]
pub const fn is_partial(&self) -> bool {
matches!(self, Self::Partial { .. })
}
#[must_use]
pub const fn wire_str(&self) -> &'static str {
match self {
Self::FullChainVerified { .. } => "full_chain_verified",
Self::Partial { .. } => "partial",
Self::Broken { .. } => "broken",
}
}
}