Skip to main content

pczt/roles/updater/
transparent.rs

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