use serde::{Deserialize, Serialize};
use super::*;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FiringReceiptMCard {
pub card: MCardRecord,
pub net_id: String,
pub transition_id: String,
pub step_seq: usize,
pub fiber_state_trace: Vec<String>,
pub consumed_refs: BTreeMap<String, Vec<String>>,
pub produced_refs: BTreeMap<String, Vec<String>>,
pub pre_marking_hash: String,
pub post_marking_hash: String,
pub verdict: String,
}
impl FiringReceiptMCard {
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(),
})
}
pub fn qualified_hash(&self) -> String {
qualified_record_hash(&self.card)
}
}