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())
}
}