clm-kernel 0.0.14

Cubical Logic Model (CLM) sovereign execution engine, CPN-VM, and Cordis spatiotemporal substrate
Documentation
//! FiringReceiptMCard extracted from `token_namespace.rs` (Sprint 534 ratchet).

use serde::{Deserialize, Serialize};
use super::*;

/// Self-verifying `MCardRecord` receipt sealing a 5-state Cordis `Fiber` transition firing.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FiringReceiptMCard {
    /// Underlying immutable content-addressed MCard record.
    pub card: MCardRecord,
    /// Petri Net identifier.
    pub net_id: String,
    /// Fired transition identifier.
    pub transition_id: String,
    /// Monotonic step sequence number.
    pub step_seq: usize,
    /// Recorded Cordis `Fiber` lifecycle state trace.
    pub fiber_state_trace: Vec<String>,
    /// Consumed token references indexed by input place ID.
    pub consumed_refs: BTreeMap<String, Vec<String>>,
    /// Produced token references indexed by output place ID.
    pub produced_refs: BTreeMap<String, Vec<String>>,
    /// Pre-firing marking state hash (`a:hex`).
    pub pre_marking_hash: String,
    /// Post-firing marking state hash (`a:hex`).
    pub post_marking_hash: String,
    /// Execution verdict (`COMMITTED`, `ROLLED_BACK`, or `ROUTED_TO_EXCEPTION`).
    pub verdict: String,
}

impl FiringReceiptMCard {
    /// Creates a deterministic `FiringReceiptMCard` sealing a transition firing step.
    pub fn create(
        net_id: &str,
        transition_id: &str,
        step_seq: usize,
        fiber_state_trace: Vec<String>,
        consumed_refs: BTreeMap<String, Vec<String>>,
        produced_refs: BTreeMap<String, Vec<String>>,
        pre_marking_hash: &str,
        post_marking_hash: &str,
        verdict: &str,
        algorithm: Option<&str>,
        timestamp: Option<&str>,
    ) -> Result<Self, String> {
        let envelope = json!({
            "consumed_refs": consumed_refs,
            "fiber_state_trace": fiber_state_trace,
            "kind": "firing_receipt_mcard",
            "net_id": net_id,
            "post_marking_hash": post_marking_hash,
            "pre_marking_hash": pre_marking_hash,
            "produced_refs": produced_refs,
            "step_seq": step_seq,
            "transition_id": transition_id,
            "verdict": verdict,
        });
        let card = record_from_canonical_json(&envelope, algorithm, timestamp)?;
        Ok(Self {
            card,
            net_id: net_id.to_string(),
            transition_id: transition_id.to_string(),
            step_seq,
            fiber_state_trace,
            consumed_refs,
            produced_refs,
            pre_marking_hash: pre_marking_hash.to_string(),
            post_marking_hash: post_marking_hash.to_string(),
            verdict: verdict.to_string(),
        })
    }

    /// Returns the algorithm-qualified `a:hex` reference for this receipt.
    pub fn qualified_hash(&self) -> String {
        qualified_record_hash(&self.card)
    }
}