clm_rust_core/layer4/
events.rs1use serde::{Deserialize, Serialize};
7use serde_json::Value;
8
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
10pub struct ExecutionEvent {
11 pub transition_id: String,
12 pub transition_name: String,
13 pub source_places: Vec<String>,
14 pub target_places: Vec<String>,
15 pub token_deltas: Value,
16 pub timestamp: String,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
20pub struct EventLog {
21 pub run_id: String,
22 pub sponsor_did: String,
23 pub events: Vec<ExecutionEvent>,
24}
25
26impl EventLog {
27 pub fn new(run_id: &str, sponsor_did: &str) -> Self {
28 Self {
29 run_id: run_id.to_string(),
30 sponsor_did: sponsor_did.to_string(),
31 events: Vec::new(),
32 }
33 }
34
35 pub fn append_event(&mut self, event: ExecutionEvent) {
36 self.events.push(event);
37 }
38
39 pub fn to_canonical_json(&self) -> String {
40 serde_json::to_string(self).unwrap_or_default()
41 }
42
43 pub fn compute_receipt_hash(&self) -> String {
44 let canonical = self.to_canonical_json();
45 crate::layer0::hash::compute_blake3(canonical.as_bytes())
46 }
47}