Skip to main content

pczt/roles/verifier/
sapling.rs

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