Skip to main content

pczt/roles/verifier/
transparent.rs

1use crate::Pczt;
2
3impl super::Verifier {
4    /// Parses the Transparent bundle and then verifies it in the given closure.
5    pub fn with_transparent<E, F>(self, f: F) -> Result<Self, TransparentError<E>>
6    where
7        F: FnOnce(&transparent::pczt::Bundle) -> Result<(), TransparentError<E>>,
8    {
9        let Pczt {
10            global,
11            transparent,
12            sapling,
13            orchard,
14            ironwood,
15        } = self.pczt;
16
17        let bundle = transparent
18            .into_parsed()
19            .map_err(TransparentError::Parser)?;
20
21        f(&bundle)?;
22
23        Ok(Self {
24            pczt: Pczt {
25                global,
26                transparent: crate::transparent::Bundle::serialize_from(bundle),
27                sapling,
28                orchard,
29                ironwood,
30            },
31        })
32    }
33}
34
35/// Errors that can occur while verifying the Transparent bundle of a PCZT.
36#[derive(Debug)]
37pub enum TransparentError<E> {
38    Parser(transparent::pczt::ParseError),
39    Verifier(transparent::pczt::VerifyError),
40    Custom(E),
41}
42
43impl<E> From<transparent::pczt::VerifyError> for TransparentError<E> {
44    fn from(e: transparent::pczt::VerifyError) -> Self {
45        TransparentError::Verifier(e)
46    }
47}