clm-kernel 0.0.19

Cubical Logic Model (CLM) sovereign execution engine, CPN-VM, and Cordis spatiotemporal substrate
Documentation
//! Structured Event Log & Execution Receipts — Sprint 364
//!
//! Provides the structured event log formatting and deterministic BLAKE3 receipt hashing,
//! binding transitions into an immutable audit trail adhering to the Bounded Function Thesis.

use serde::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ExecutionEvent {
    pub transition_id: String,
    pub transition_name: String,
    pub source_places: Vec<String>,
    pub target_places: Vec<String>,
    pub token_deltas: Value,
    pub timestamp: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct EventLog {
    pub run_id: String,
    pub sponsor_did: String,
    pub events: Vec<ExecutionEvent>,
}

impl EventLog {
    pub fn new(run_id: &str, sponsor_did: &str) -> Self {
        Self {
            run_id: run_id.to_string(),
            sponsor_did: sponsor_did.to_string(),
            events: Vec::new(),
        }
    }

    pub fn append_event(&mut self, event: ExecutionEvent) {
        self.events.push(event);
    }

    pub fn to_canonical_json(&self) -> String {
        serde_json::to_string(self).unwrap_or_default()
    }

    pub fn compute_receipt_hash(&self) -> String {
        let canonical = self.to_canonical_json();
        crate::layer0::hash::compute_blake3(canonical.as_bytes())
    }
}