use crate::{Pczt, common::AnchorRequirement};
impl super::Verifier {
pub fn with_orchard<E, F>(self, f: F) -> Result<Self, OrchardError<E>>
where
F: FnOnce(&orchard::pczt::Bundle) -> Result<(), OrchardError<E>>,
{
let Pczt {
global,
transparent,
sapling,
orchard,
ironwood,
} = self.pczt;
let anchor_requirement = AnchorRequirement::for_pre_authorization(global.tx_version);
let parsed = orchard
.into_parsed_with_version(
crate::orchard::orchard_bundle_version(&global)
.ok_or(OrchardError::UnsupportedConsensusBranchId)?,
anchor_requirement,
)
.map_err(OrchardError::Parse)?;
f(&parsed.bundle)?;
Ok(Self {
pczt: Pczt {
global,
transparent,
sapling,
orchard: parsed.reserialize(),
ironwood,
},
})
}
pub fn with_ironwood<E, F>(self, f: F) -> Result<Self, OrchardError<E>>
where
F: FnOnce(&orchard::pczt::Bundle) -> Result<(), OrchardError<E>>,
{
let Pczt {
global,
transparent,
sapling,
orchard,
ironwood,
} = self.pczt;
let anchor_requirement = AnchorRequirement::for_pre_authorization(global.tx_version);
let parsed = ironwood
.into_ironwood_parsed(anchor_requirement)
.map_err(OrchardError::Parse)?;
f(&parsed.bundle)?;
Ok(Self {
pczt: Pczt {
global,
transparent,
sapling,
orchard,
ironwood: parsed.reserialize(),
},
})
}
}
#[derive(Debug)]
pub enum OrchardError<E> {
Parse(crate::orchard::ParseError),
UnsupportedConsensusBranchId,
Verify(orchard::pczt::VerifyError),
Custom(E),
}
impl<E> From<orchard::pczt::VerifyError> for OrchardError<E> {
fn from(e: orchard::pczt::VerifyError) -> Self {
OrchardError::Verify(e)
}
}