Skip to main content

pczt/roles/updater/
sapling.rs

1use sapling::pczt::{Updater, UpdaterError};
2
3use crate::{Pczt, common::AnchorRequirement, sapling::ParseError};
4
5impl super::Updater {
6    /// Updates the Sapling bundle with information in the given closure.
7    pub fn update_sapling_with<F>(self, f: F) -> Result<Self, SaplingError>
8    where
9        F: FnOnce(Updater<'_>) -> Result<(), UpdaterError>,
10    {
11        let Pczt {
12            global,
13            transparent,
14            sapling,
15            orchard,
16            ironwood,
17        } = self.pczt;
18        let anchor_requirement = AnchorRequirement::for_pre_authorization(global.tx_version);
19
20        let mut parsed = sapling
21            .into_parsed(anchor_requirement)
22            .map_err(SaplingError::Parser)?;
23
24        parsed
25            .bundle
26            .update_with(f)
27            .map_err(SaplingError::Updater)?;
28
29        Ok(Self {
30            pczt: Pczt {
31                global,
32                transparent,
33                sapling: parsed.reserialize(),
34                orchard,
35                ironwood,
36            },
37        })
38    }
39}
40
41/// Errors that can occur while updating the Sapling bundle of a PCZT.
42#[derive(Debug)]
43pub enum SaplingError {
44    Parser(ParseError),
45    Updater(UpdaterError),
46}