delivery_summary.rs (3434B)
1 use super::{ 2 DeliveryAttempt, DeliveryIntent, DeliveryObservation, OperationError, PublicationArtifact, 3 }; 4 use core::fmt; 5 use radroots_domain::{TransactionId, UnixSeconds}; 6 7 /// Bounded original delivery references without another copy of its signed 8 /// bytes. This data projection grants no dispatch permission or storage proof. 9 #[derive(Clone, Eq, PartialEq)] 10 pub struct DeliveryAttemptSummary { 11 work: PublicationArtifact, 12 intent: DeliveryIntent, 13 digest: [u8; 32], 14 transaction: TransactionId, 15 retained_at: UnixSeconds, 16 ordinals: Box<[u8]>, 17 } 18 impl DeliveryAttemptSummary { 19 /// Copies original report facts, never a scheduling capability. 20 pub fn from_attempt(attempt: &DeliveryAttempt) -> Self { 21 Self { 22 work: attempt.work(), 23 intent: attempt.intent().clone(), 24 digest: *attempt.envelope_digest(), 25 transaction: attempt.transaction_id(), 26 retained_at: attempt.retained_at(), 27 ordinals: attempt.target_ordinals().into(), 28 } 29 } 30 /// Original protected publication linkage. 31 pub const fn work(&self) -> PublicationArtifact { 32 self.work 33 } 34 /// Complete immutable original transport intent. 35 pub const fn intent(&self) -> &DeliveryIntent { 36 &self.intent 37 } 38 /// SHA-256 of the original exact signed outer representation. 39 pub const fn envelope_digest(&self) -> &[u8; 32] { 40 &self.digest 41 } 42 /// Actual original retention transaction report. 43 pub const fn transaction_id(&self) -> TransactionId { 44 self.transaction 45 } 46 /// Original retention time, never a renewed lease or deadline. 47 pub const fn retained_at(&self) -> UnixSeconds { 48 self.retained_at 49 } 50 /// Original endpoint attempt numbers in target order. 51 pub fn target_ordinals(&self) -> &[u8] { 52 &self.ordinals 53 } 54 /// Evaluates only this attempt's retained exact target evidence with the 55 /// shared acceptance law. A success does not prove recipient delivery. 56 pub fn acceptance_satisfied( 57 &self, 58 observations: &[DeliveryObservation], 59 ) -> Result<bool, OperationError> { 60 let relevant = observations.iter().filter(|value| { 61 value.work() == self.work && value.request_id() == self.intent.request_id() 62 }); 63 for value in relevant.clone() { 64 if value.event_id() != self.intent.event_id() 65 || value.envelope_digest() != &self.digest 66 || !self 67 .intent 68 .targets() 69 .targets() 70 .contains(value.target_receipt().target()) 71 { 72 return Err(OperationError::InvalidEvidence); 73 } 74 } 75 radroots_transport::policy::evaluate_satisfaction( 76 self.intent.policy(), 77 self.intent.targets(), 78 relevant.map(|value| { 79 ( 80 value.target_receipt().target().fingerprint(), 81 value.target_receipt().outcome(), 82 ) 83 }), 84 ) 85 .map(|value| value == radroots_transport::policy::SatisfactionState::Satisfied) 86 .map_err(|_| OperationError::InvalidEvidence) 87 } 88 } 89 impl fmt::Debug for DeliveryAttemptSummary { 90 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 91 f.write_str("DeliveryAttemptSummary(<redacted>)") 92 } 93 }