Skip to main content

waitprims_core/
receipts.rs

1//! Caller-owned delivery and activation evidence.
2//!
3//! These types are not `agent-wait/v0` messages. They do not carry
4//! `message_type` and must not be serialized as wait-contract JSON.
5//! Setting a ref on a [`WaitEvent`](crate::WaitEvent) never changes
6//! `outcome_kind` and never means the agent acted or the waiter handled
7//! the event.
8
9use crate::refs::OpaqueRef;
10use crate::types::WaitEvent;
11
12/// Caller-owned delivery evidence. Opaque ref only; not a wait-contract message.
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct DeliveryEvidence {
15    delivery_ref: OpaqueRef,
16}
17
18impl DeliveryEvidence {
19    /// Record a caller-owned delivery ref.
20    pub fn new(delivery_ref: impl Into<String>) -> Self {
21        Self {
22            delivery_ref: OpaqueRef::new(delivery_ref),
23        }
24    }
25
26    /// Borrow the opaque delivery ref.
27    pub fn delivery_ref(&self) -> &OpaqueRef {
28        &self.delivery_ref
29    }
30}
31
32/// Caller-owned activation evidence. Opaque ref only; not a wait-contract message.
33#[derive(Debug, Clone, PartialEq, Eq)]
34pub struct ActivationEvidence {
35    activation_ref: OpaqueRef,
36}
37
38impl ActivationEvidence {
39    /// Record a caller-owned activation ref.
40    pub fn new(activation_ref: impl Into<String>) -> Self {
41        Self {
42            activation_ref: OpaqueRef::new(activation_ref),
43        }
44    }
45
46    /// Borrow the opaque activation ref.
47    pub fn activation_ref(&self) -> &OpaqueRef {
48        &self.activation_ref
49    }
50}
51
52/// Attach optional opaque refs to observed events.
53///
54/// Does not change wait `outcome_kind` and does not create a message kind.
55/// Presence never means the agent acted or the waiter handled the event.
56pub fn attach_event_refs(
57    events: &mut [WaitEvent],
58    delivery_ref: Option<OpaqueRef>,
59    activation_ref: Option<OpaqueRef>,
60) {
61    for event in events {
62        event.attach_refs(delivery_ref.clone(), activation_ref.clone());
63    }
64}
65
66#[cfg(test)]
67mod tests {
68    use crate::types::MessageType;
69
70    #[test]
71    fn evidence_is_not_a_wait_message_kind() {
72        let names = [
73            MessageType::RegistrationSet.as_str(),
74            MessageType::LiveWaitRequest.as_str(),
75            MessageType::LiveWaitOutcome.as_str(),
76            MessageType::PollCycleRequest.as_str(),
77            MessageType::PollCycleOutcome.as_str(),
78            MessageType::PollCycleAck.as_str(),
79        ];
80        assert!(!names.contains(&"delivery"));
81        assert!(!names.contains(&"activation"));
82        assert!(!names.contains(&"delivery_receipt"));
83        assert!(!names.contains(&"activation_receipt"));
84    }
85}