Skip to main content

pczt/roles/updater/
transparent.rs

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