made_core/entities/ceremony_instance/fold/
mod.rs1use crate::entities::{CeremonyEvent, CeremonyInstance};
11use crate::error::DomainError;
12
13mod context;
14mod guard_decisions;
15mod import;
16mod interventions;
17mod participant_bindings;
18mod reasons;
19mod recollection;
20mod start;
21mod step_execution;
22mod transitions;
23
24impl CeremonyInstance {
25 pub fn apply(&mut self, event: &CeremonyEvent) {
33 match event {
34 CeremonyEvent::CeremonyInstanceStarted(_) => {}
41 CeremonyEvent::ParticipantsBound(bound) => self.apply_participants_bound(bound),
42 CeremonyEvent::StepStarted(started) => self.apply_step_started(started),
43 CeremonyEvent::StepCompleted(completed) => self.apply_step_completed(completed),
44 CeremonyEvent::StepFailed(failed) => self.apply_step_failed(failed),
45 CeremonyEvent::ContextWritten(written) => self.apply_context_written(written),
46 CeremonyEvent::StateIterationStarted(started) => {
47 self.apply_state_iteration_started(started);
48 }
49 CeremonyEvent::TransitionApplied(applied) => self.apply_transition_applied(applied),
50 CeremonyEvent::InterventionRequested(requested) => {
51 self.apply_intervention_requested(requested);
52 }
53 CeremonyEvent::InterventionResponded(responded) => {
54 self.apply_intervention_responded(responded);
55 }
56 CeremonyEvent::InterventionClosed(closed) => self.apply_intervention_closed(closed),
57 CeremonyEvent::EvidenceCollected(collected) => self.apply_evidence_collected(collected),
58 CeremonyEvent::ReasonAsserted(asserted) => self.apply_reason_asserted(asserted),
59 CeremonyEvent::HumanApprovalRecorded(recorded) => {
60 self.apply_human_approval_recorded(recorded);
61 }
62 CeremonyEvent::HumanDeferralRecorded(recorded) => {
63 self.apply_human_deferral_recorded(recorded);
64 }
65 CeremonyEvent::CeremonyCompleted(completed) => self.apply_ceremony_completed(completed),
66 CeremonyEvent::InstanceImported(imported) => self.apply_instance_imported(imported),
67 CeremonyEvent::MemoryRecalled(recalled) => self.apply_memory_recalled(recalled),
68 }
69 }
70
71 pub fn rehydrate<'a>(
81 events: impl IntoIterator<Item = &'a CeremonyEvent>,
82 ) -> Result<Self, DomainError> {
83 let mut events = events.into_iter();
84 let mut instance = match events.next() {
85 Some(CeremonyEvent::CeremonyInstanceStarted(started)) => Self::from_started(started),
86 Some(CeremonyEvent::InstanceImported(imported)) => Self::from_imported(imported),
87 _ => {
88 return Err(DomainError::InvariantViolated {
89 reason: "a ceremony stream opens with its start or with its import",
90 })
91 }
92 };
93 for event in events {
94 if matches!(event, CeremonyEvent::InstanceImported(_)) {
95 return Err(DomainError::InvariantViolated {
96 reason: "a ceremony stream carries an import only as its first event",
97 });
98 }
99 instance.apply(event);
100 }
101 Ok(instance)
102 }
103
104 pub(in crate::entities::ceremony_instance) fn apply_all(&mut self, events: &[CeremonyEvent]) {
106 for event in events {
107 self.apply(event);
108 }
109 }
110}