actrpc_core/interception/
request.rs1use crate::{
2 action::ResolvedActionRecord, error::ProtocolError, interception::InterceptionPhase,
3 json_rpc::JsonRpcMessage, participant::Participant,
4};
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
8pub struct InterceptionRequest {
9 pub origin: Participant,
10 pub message: JsonRpcMessage,
11
12 #[serde(default, skip_serializing_if = "Vec::is_empty")]
13 pub resolved_action_history: Vec<Vec<ResolvedActionRecord>>,
14}
15
16impl InterceptionRequest {
17 pub fn has_resolved_actions(&self) -> bool {
18 self.resolved_action_history
19 .iter()
20 .any(|actions| !actions.is_empty())
21 }
22
23 pub fn has_prior_actions(&self) -> bool {
24 self.has_resolved_actions()
25 }
26
27 pub fn get_last_resolved_actions(&self) -> Option<&[ResolvedActionRecord]> {
28 self.resolved_action_history.last().map(Vec::as_slice)
29 }
30
31 pub fn iter_resolved_action_rounds(&self) -> impl Iterator<Item = &[ResolvedActionRecord]> {
32 self.resolved_action_history.iter().map(Vec::as_slice)
33 }
34
35 pub fn phase(&self) -> Result<InterceptionPhase, ProtocolError> {
36 self.message.phase()
37 }
38}