penumbra_sdk_transaction/
detection_data.rs

1use anyhow::Error;
2use decaf377_fmd::Clue;
3use penumbra_sdk_proto::core::transaction::v1 as pbt;
4use penumbra_sdk_proto::DomainType;
5use penumbra_sdk_txhash::{EffectHash, EffectingData};
6
7/// Detection data used by a detection server using Fuzzy Message Detection.
8///
9/// Only present if outputs are present.
10#[derive(Clone, Debug, Default)]
11pub struct DetectionData {
12    pub fmd_clues: Vec<Clue>,
13}
14
15impl EffectingData for DetectionData {
16    fn effect_hash(&self) -> EffectHash {
17        EffectHash::from_proto_effecting_data(&self.to_proto())
18    }
19}
20
21impl DomainType for DetectionData {
22    type Proto = pbt::DetectionData;
23}
24
25impl TryFrom<pbt::DetectionData> for DetectionData {
26    type Error = Error;
27
28    fn try_from(proto: pbt::DetectionData) -> anyhow::Result<Self, Self::Error> {
29        let fmd_clues = proto
30            .fmd_clues
31            .into_iter()
32            .map(|x| x.try_into())
33            .collect::<Result<Vec<Clue>, Error>>()?;
34        Ok(DetectionData { fmd_clues })
35    }
36}
37
38impl From<DetectionData> for pbt::DetectionData {
39    fn from(msg: DetectionData) -> Self {
40        let fmd_clues = msg.fmd_clues.into_iter().map(|x| x.into()).collect();
41
42        pbt::DetectionData { fmd_clues }
43    }
44}